changeset 19094:fc1b77db123f stable

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.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Tue, 30 Apr 2013 13:53:49 +0200
parents 6f27efc7db23
children 5cc71484ee9c
files mercurial/hgweb/webutil.py tests/test-hgweb-commands.t
diffstat 2 files changed, 105 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Tue Apr 30 15:11:12 2013 +0200
+++ b/mercurial/hgweb/webutil.py	Tue Apr 30 13:53:49 2013 +0200
@@ -51,7 +51,14 @@
 
     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))
@@ -81,7 +88,8 @@
             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:
--- a/tests/test-hgweb-commands.t	Tue Apr 30 15:11:12 2013 +0200
+++ b/tests/test-hgweb-commands.t	Tue Apr 30 13:53:49 2013 +0200
@@ -1436,4 +1436,99 @@
   
   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 ..
+