Submitter | Durham Goode |
---|---|
Date | March 15, 2017, 10:51 p.m. |
Message ID | <6257ea07d629e83e85f6.1489618287@dev111.prn1.facebook.com> |
Download | mbox | patch |
Permalink | /patch/19369/ |
State | Accepted |
Headers | show |
Comments
On Wed, Mar 15, 2017 at 03:51:27PM -0700, Durham Goode wrote: > # HG changeset patch > # User Durham Goode <durham@fb.com> > # Date 1489618137 25200 > # Wed Mar 15 15:48:57 2017 -0700 > # Node ID 6257ea07d629e83e85f68d0c83202b4111f6d4fd > # Parent e83302d437485620c9bc25921f724af34cd5dd55 > branchmap: handle nullrev in setcachedata Queued, thanks. > > 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 --git a/mercurial/branchmap.py b/mercurial/branchmap.py > --- a/mercurial/branchmap.py > +++ b/mercurial/branchmap.py > @@ -452,6 +452,8 @@ class revbranchcache(object): > > 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 --git a/tests/test-branches.t b/tests/test-branches.t > --- a/tests/test-branches.t > +++ b/tests/test-branches.t > @@ -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" > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@mercurial-scm.org > https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Patch
diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -452,6 +452,8 @@ class revbranchcache(object): 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 --git a/tests/test-branches.t b/tests/test-branches.t --- a/tests/test-branches.t +++ b/tests/test-branches.t @@ -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"