comparison mercurial/branchmap.py @ 31454:a5bad127128d

branchmap: handle nullrev in setcachedata 906be86990 recently changed to switch from: self._rbcrevs[rbcrevidx:rbcrevidx + _rbcrecsize] = rec to pack_into(_rbcrecfmt, self._rbcrevs, rbcrevidx, node, branchidx) This causes an exception if rbcrevidx is -1 (i.e. the nullrev). The old code handled this because python handles out of bound sets to arrays gracefully. The new code throws because the self._rbcrevs buffer isn't long enough to write 8 bytes to. Normally it would've been resized by the immediately preceding line, but because the 0 length buffer is greater than the idx (-1) times the size, no resize happens. Setting the branch for the nullrev doesn't make sense anyway, so let's skip it. This was caught by external tests in the Facebook extensions repo, but I've added a test here that catches the issue.
author Durham Goode <durham@fb.com>
date Wed, 15 Mar 2017 15:48:57 -0700
parents 7359157b9e46
children a369482e9649
comparison
equal deleted inserted replaced
31453:3b7a6941a6ef 31454:a5bad127128d
450 self._setcachedata(rev, reponode, branchidx) 450 self._setcachedata(rev, reponode, branchidx)
451 return b, close 451 return b, close
452 452
453 def _setcachedata(self, rev, node, branchidx): 453 def _setcachedata(self, rev, node, branchidx):
454 """Writes the node's branch data to the in-memory cache data.""" 454 """Writes the node's branch data to the in-memory cache data."""
455 if rev == nullrev:
456 return
455 rbcrevidx = rev * _rbcrecsize 457 rbcrevidx = rev * _rbcrecsize
456 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: 458 if len(self._rbcrevs) < rbcrevidx + _rbcrecsize:
457 self._rbcrevs.extend('\0' * 459 self._rbcrevs.extend('\0' *
458 (len(self._repo.changelog) * _rbcrecsize - 460 (len(self._repo.changelog) * _rbcrecsize -
459 len(self._rbcrevs))) 461 len(self._rbcrevs)))