Patchwork [STABLE] revbranchcache: special case nullrev

login
register
mail settings
Submitter Durham Goode
Date May 23, 2015, 4:59 a.m.
Message ID <912ff2370836f4646121.1432357170@dev2000.prn2.facebook.com>
Download mbox | patch
Permalink /patch/9249/
State Superseded
Delegated to: Pierre-Yves David
Headers show

Comments

Durham Goode - May 23, 2015, 4:59 a.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1432357020 25200
#      Fri May 22 21:57:00 2015 -0700
# Node ID 912ff2370836f46461218a68212c3c253d2bc5c7
# Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
revbranchcache: special case nullrev

hg log -r 'branch(.)' was causing a stack trace if the user was on the nullrev
because it tried to access position -1 in the rev branch cache. This patch
special cases the nullrev to avoid the cache.
Yuya Nishihara - May 23, 2015, 5:59 a.m.
On Fri, 22 May 2015 21:59:30 -0700, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1432357020 25200
> #      Fri May 22 21:57:00 2015 -0700
> # Node ID 912ff2370836f46461218a68212c3c253d2bc5c7
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> revbranchcache: special case nullrev
> 
> hg log -r 'branch(.)' was causing a stack trace if the user was on the nullrev
> because it tried to access position -1 in the rev branch cache. This patch
> special cases the nullrev to avoid the cache.
> 
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -338,6 +338,9 @@ class revbranchcache(object):
>      def branchinfo(self, rev):
>          """Return branch name and close flag for rev, using and updating
>          persistent cache."""
> +        if rev == nullrev:
> +            return self._branchinfo(rev)

_branchinfo() calls _setcachedata() with negative rev, which is probably wrong.

I have a patch that will do "return changelog.branchinfo(rev)" instead, and
another patch for "children(branch(null))" issue.

Regards,
Pierre-Yves David - May 23, 2015, 5:40 p.m.
On 05/22/2015 11:59 PM, Durham Goode wrote:
> # HG changeset patch
> # User Durham Goode <durham@fb.com>
> # Date 1432357020 25200
> #      Fri May 22 21:57:00 2015 -0700
> # Node ID 912ff2370836f46461218a68212c3c253d2bc5c7
> # Parent  f2b98dacb37ddd6713b11a1a871fcdbbc5fd8bb2
> revbranchcache: special case nullrev

This is a fix for to http://bz.selenic.com/show_bug.cgi?id=4683

We probably want to handle wdir in the same goes to prefer futur other 
traceback for our user.

> hg log -r 'branch(.)' was causing a stack trace if the user was on the nullrev
> because it tried to access position -1 in the rev branch cache. This patch
> special cases the nullrev to avoid the cache.
>
> diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
> --- a/mercurial/branchmap.py
> +++ b/mercurial/branchmap.py
> @@ -338,6 +338,9 @@ class revbranchcache(object):
>       def branchinfo(self, rev):
>           """Return branch name and close flag for rev, using and updating
>           persistent cache."""
> +        if rev == nullrev:
> +            return self._branchinfo(rev)
> +

as nullid is immutable, we can probably just return ('default', False) here.

Patch

diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py
--- a/mercurial/branchmap.py
+++ b/mercurial/branchmap.py
@@ -338,6 +338,9 @@  class revbranchcache(object):
     def branchinfo(self, rev):
         """Return branch name and close flag for rev, using and updating
         persistent cache."""
+        if rev == nullrev:
+            return self._branchinfo(rev)
+
         changelog = self._repo.changelog
         rbcrevidx = rev * _rbcrecsize
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1630,6 +1630,12 @@  test or-ed indirect predicates (issue377
   5
   6
 
+  $ hg branch -q default
+  $ echo a >> a
+  $ hg ci -qm 'default branch commit'
+  $ log 'branch(null)'
+  10
+
 tests for 'remote()' predicate:
 #.  (csets in remote) (id)            (remote)
 1.  less than local   current branch  "default"