Patchwork [2,of,2,STABLE] hgweb: handle filtered "0" rev in navigation

login
register
mail settings
Submitter Pierre-Yves David
Date April 30, 2013, 1:15 p.m.
Message ID <6c1d79239cc43204641f.1367327722@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/1511/
State Accepted
Commit fc1b77db123f86fb07a8d35101439dded809d1c5
Headers show

Comments

Pierre-Yves David - April 30, 2013, 1:15 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1367322829 -7200
#      Tue Apr 30 13:53:49 2013 +0200
# Branch stable
# Node ID 6c1d79239cc43204641ffb60f414f28f66943a64
# Parent  b44d4877db10ed093e06edc20ee81eb2cb95351f
hgweb: handle filtered "0" rev in navigation

Before this changeset, navigation generation crashed if revision "0" was
filtered. We introduce a `_first` methods on revision navigation that return the
lowest unfiltered element and use it in two place were the "0" changeset was
explicitly referenced.

Test case are introduced.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -49,11 +49,18 @@  class revnav(object):
         # used for hex generation
         self._revlog = repo.changelog
 
     def __nonzero__(self):
         """return True if any revision to navigate over"""
-        return bool(len(self._revlog))
+        return self._first() is not None
+
+    def _first(self):
+        """return the minimum non-filtered changeset or None"""
+        try:
+            return iter(self._revlog).next()
+        except StopIteration:
+            return None
 
     def hex(self, rev):
         return hex(self._revlog.node(rev))
 
     def gen(self, pos, pagelen, limit):
@@ -79,11 +86,12 @@  class revnav(object):
                 break
             targets.append(pos + f)
             targets.append(pos - f)
         targets.sort()
 
-        navbefore = [("(0)", self.hex(0))]
+        first = self._first()
+        navbefore = [("(%i)" % first, self.hex(first))]
         navafter = []
         for rev in targets:
             if rev not in self._revlog:
                 continue
             if pos < rev < limit:
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1434,6 +1434,101 @@  proper status for filtered revision
   Content-Type: text/plain; charset=ascii\r (esc)
   \r (esc)
   
   error: unknown revision '4'
 
+filtered '0' changeset
+
+(create new root)
+  $ hg up null
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo 'babar' > jungle
+  $ hg add jungle
+  $ hg ci -m 'Babar is in the jungle!'
+  created new head
+  $ hg graft 0::
+  grafting revision 0
+  grafting revision 1
+  grafting revision 2
+  grafting revision 3
+  grafting revision 4
+  grafting revision 5
+(turning the initial root secret (filtered))
+  $ hg phase --force --secret 0
+  $ PATH_INFO=/graph/; export PATH_INFO
+  $ QUERY_STRING=''
+  $ python hgweb.cgi | grep Status
+  Status: 200 Script output follows\r (esc)
+(check rendered revision)
+  $ QUERY_STRING='style=raw'
+  $ python hgweb.cgi | grep -v ETag
+  Status: 200 Script output follows\r (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  # HG graph
+  # Node ID 1d9b947fef1fbb382a95c11a8f5a67e9a10b5026
+  # Rows shown 7
+  
+  changeset:   1d9b947fef1f
+  user:        test
+  date:        1970-01-01
+  summary:     5
+  branch:      default
+  tag:         tip
+  
+  node:        (0, 0) (color 1)
+  edge:        (0, 0) -> (0, 1) (color 1)
+  
+  changeset:   0cfd435fd222
+  user:        test
+  date:        1970-01-01
+  summary:     4
+  
+  node:        (0, 1) (color 1)
+  edge:        (0, 1) -> (0, 2) (color 1)
+  
+  changeset:   6768b9939e82
+  user:        test
+  date:        1970-01-01
+  summary:     3
+  
+  node:        (0, 2) (color 1)
+  edge:        (0, 2) -> (0, 3) (color 1)
+  
+  changeset:   05b0497fd125
+  user:        test
+  date:        1970-01-01
+  summary:     2
+  
+  node:        (0, 3) (color 1)
+  edge:        (0, 3) -> (0, 4) (color 1)
+  
+  changeset:   9c102df67cfb
+  user:        test
+  date:        1970-01-01
+  summary:     1
+  
+  node:        (0, 4) (color 1)
+  edge:        (0, 4) -> (0, 5) (color 1)
+  
+  changeset:   3ebcd7db11bf
+  user:        test
+  date:        1970-01-01
+  summary:     0
+  
+  node:        (0, 5) (color 1)
+  edge:        (0, 5) -> (0, 6) (color 1)
+  
+  changeset:   c5e9bd96ae01
+  user:        test
+  date:        1970-01-01
+  summary:     Babar is in the jungle!
+  
+  node:        (0, 6) (color 1)
+  
+  
+
+
+
   $ cd ..
+