Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/branchmap.py @ 29604:db0095c83344
rbc: fix invalid rbc-revs entries caused by missing cache growth
It was in some cases possible to end up writing to the cache file without
growing it first. The range assignment in _setcachedata would append instead of
writing at the requested position and thus write the new record in the wrong
place.
To fix this, we avoid looking up in too small caches, and when growing the
cache, do it right before writing the new record to it so we know it has been
done correctly.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 18 Jul 2016 22:22:38 +0200 |
parents | d2c6f3a948fa |
children | a2a380e2750f |
comparison
equal
deleted
inserted
replaced
29603:b181a650a886 | 29604:db0095c83344 |
---|---|
400 | 400 |
401 # avoid negative index, changelog.read(nullrev) is fast without cache | 401 # avoid negative index, changelog.read(nullrev) is fast without cache |
402 if rev == nullrev: | 402 if rev == nullrev: |
403 return changelog.branchinfo(rev) | 403 return changelog.branchinfo(rev) |
404 | 404 |
405 # if requested rev is missing, add and populate all missing revs | 405 # if requested rev isn't allocated, grow and cache the rev info |
406 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: | 406 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: |
407 self._rbcrevs.extend('\0' * (len(changelog) * _rbcrecsize - | 407 return self._branchinfo(rev) |
408 len(self._rbcrevs))) | |
409 | 408 |
410 # fast path: extract data from cache, use it if node is matching | 409 # fast path: extract data from cache, use it if node is matching |
411 reponode = changelog.node(rev)[:_rbcnodelen] | 410 reponode = changelog.node(rev)[:_rbcnodelen] |
412 cachenode, branchidx = unpack( | 411 cachenode, branchidx = unpack( |
413 _rbcrecfmt, buffer(self._rbcrevs, rbcrevidx, _rbcrecsize)) | 412 _rbcrecfmt, buffer(self._rbcrevs, rbcrevidx, _rbcrecsize)) |
450 def _setcachedata(self, rev, node, branchidx): | 449 def _setcachedata(self, rev, node, branchidx): |
451 """Writes the node's branch data to the in-memory cache data.""" | 450 """Writes the node's branch data to the in-memory cache data.""" |
452 rbcrevidx = rev * _rbcrecsize | 451 rbcrevidx = rev * _rbcrecsize |
453 rec = array('c') | 452 rec = array('c') |
454 rec.fromstring(pack(_rbcrecfmt, node, branchidx)) | 453 rec.fromstring(pack(_rbcrecfmt, node, branchidx)) |
454 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: | |
455 self._rbcrevs.extend('\0' * | |
456 (len(self._repo.changelog) * _rbcrecsize - | |
457 len(self._rbcrevs))) | |
455 self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec | 458 self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec |
456 self._rbcrevslen = min(self._rbcrevslen, rev) | 459 self._rbcrevslen = min(self._rbcrevslen, rev) |
457 | 460 |
458 tr = self._repo.currenttransaction() | 461 tr = self._repo.currenttransaction() |
459 if tr: | 462 if tr: |