# HG changeset patch # User Durham Goode # Date 1489618137 25200 # Node ID a5bad127128d8f60060be53d161acfa7a32a17d5 # Parent 3b7a6941a6efcca57c6d13bc356adee99adb7ff1 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. diff -r 3b7a6941a6ef -r a5bad127128d mercurial/branchmap.py --- a/mercurial/branchmap.py Wed Mar 15 23:28:39 2017 +0900 +++ b/mercurial/branchmap.py Wed Mar 15 15:48:57 2017 -0700 @@ -452,6 +452,8 @@ def _setcachedata(self, rev, node, branchidx): """Writes the node's branch data to the in-memory cache data.""" + if rev == nullrev: + return rbcrevidx = rev * _rbcrecsize if len(self._rbcrevs) < rbcrevidx + _rbcrecsize: self._rbcrevs.extend('\0' * diff -r 3b7a6941a6ef -r a5bad127128d tests/test-branches.t --- a/tests/test-branches.t Wed Mar 15 23:28:39 2017 +0900 +++ b/tests/test-branches.t Wed Mar 15 15:48:57 2017 -0700 @@ -1,5 +1,10 @@ $ hg init a $ cd a + +Verify checking branch of nullrev before the cache is created doesnt crash + $ hg log -r 'branch(.)' -T '{branch}\n' + +Basic test $ echo 'root' >root $ hg add root $ hg commit -d '0 0' -m "Adding root node"