Patchwork [16,of,23,Series-D] hgweb: simplify the handling of empty repo

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 11, 2013, 12:24 a.m.
Message ID <b5c4fbe18ffe6569402e.1357863841@yamac.lan>
Download mbox | patch
Permalink /patch/534/
State Superseded
Headers show

Comments

Pierre-Yves David - Jan. 11, 2013, 12:24 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357841345 -3600
# Node ID b5c4fbe18ffe6569402ece22b1273bc4a46b6f44
# Parent  6efba5b8d479f0381905f69cab459e440a57ec72
hgweb: simplify the handling of empty repo

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -46,10 +46,18 @@  class revnav(object):
 
         :nodefun: factory for a changectx from a revision
         """
         self.nodefunc = nodefunc
 
+    def __nonzero__(self):
+        """return True if any revision to navigate over"""
+        try:
+            self.nodefunc(0)
+            return True
+        except error.RepoError:
+            return False
+
     def hex(self, rev):
         return self.nodefunc(rev).hex()
 
     def gen(self, pos, pagelen, limit):
         """computes label and revision id for navigation link
@@ -62,10 +70,13 @@  class revnav(object):
             - a single element tuple
             - containing a dictionary with a `before` and `after` key
             - values are generator function taking arbitrary number of kwargs
             - yield items are dictionnary with `label` and `node` key
         """
+        if not self:
+            # empty repo
+            return ({'before': (), 'after': ()},)
 
         navbefore = []
         navafter = []
 
         for f in _navseq(1, pagelen):
@@ -75,14 +86,11 @@  class revnav(object):
                 navafter.append(("+%d" % f, self.hex(pos + f)))
             if pos - f >= 0:
                 navbefore.insert(0, ("-%d" % f, self.hex(pos - f)))
 
         navafter.append(("tip", "tip"))
-        try:
-            navbefore.insert(0, ("(0)", self.hex(0)))
-        except error.RepoError:
-            pass
+        navbefore.insert(0, ("(0)", self.hex(0)))
 
         def gen(l):
             def f(**map):
                 return ({"label": i[0], "node": i[1]} for i in l)
             return f