Patchwork [15,of,22,V2-Series-D] hgweb: generate revnav in two phase

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 14, 2013, 8:35 p.m.
Message ID <814260dac17076a8c44b.1358195747@yamac.lan>
Download mbox | patch
Permalink /patch/610/
State Superseded
Headers show

Comments

Pierre-Yves David - Jan. 14, 2013, 8:35 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1357842588 -3600
# Node ID 814260dac17076a8c44b588a1968fdb2252e7520
# Parent  70aa9a56ce5815fad55ad3f5a72c12287e1bd577
hgweb: generate revnav in two phase

We first generate revision to link. Then we dispatch them in before, after list.

This will help filtering of unknown revision.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -75,20 +75,26 @@  class revnav(object):
         """
         if not self:
             # empty repo
             return ({'before': (), 'after': ()},)
 
-        navbefore = [("(0)", self.hex(0))]
-        navafter = []
-
+        targets = []
         for f in _navseq(1, pagelen):
             if f > limit:
                 break
-            if pos + f < limit:
-                navafter.append(("+%d" % f, self.hex(pos + f)))
-            if pos - f >= 0:
-                navbefore.insert(0, ("-%d" % f, self.hex(pos - f)))
+            targets.append(pos + f)
+            targets.append(pos - f)
+        targets.sort()
+
+        navbefore = [("(0)", self.hex(0))]
+        navafter = []
+        for rev in targets:
+            if pos < rev < limit:
+                navafter.append(("+%d" % f, self.hex(rev)))
+            if 0 < rev < pos:
+                navbefore.append(("-%d" % f, self.hex(rev)))
+
 
         navafter.append(("tip", "tip"))
 
         data = lambda i: {"label": i[0], "node": i[1]}
         return ({'before': lambda **map: (data(i) for i in navbefore),