Patchwork [20,of,23,Series-D] hgweb: generate revnav in two phase

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 11, 2013, 12:24 a.m.
Message ID <d497c3c174cf762c0852.1357863845@yamac.lan>
Download mbox | patch
Permalink /patch/523/
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 1357842588 -3600
# Node ID d497c3c174cf762c0852fd445a3509c908695fdf
# Parent  d589ad7c9bf9b76b553a8c6246d8ca6e728a4a29
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"))
 
         def gen(l):
             def f(**map):