[PATCH 1 of 1] hgweb: changenav: separate pages before and after the current position

Nicolas Dumazet nicdumz at gmail.com
Fri Dec 25 03:29:43 CST 2009


# HG changeset patch
# User Nicolas Dumazet <nicdumz.commits at gmail.com>
# Date 1261727785 -32400
# Node ID d36918b72b83c7cd4687d8011e4932cf9a0d1b8b
# Parent  69a974125938c11184598b99a51aaeba6f6323f9
hgweb: changenav: separate pages before and after the current position

This should allow styles to customize more precisely navigation bar,
for example inserting a cursor to show where we are in the navigation bar.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -32,31 +32,34 @@
         for f in seq(factor * 10):
             yield f
 
-    def nav(**map):
-        l = []
-        last = 0
-        for f in seq(1, pagelen):
-            if f < pagelen or f <= last:
-                continue
-            if f > limit:
-                break
-            last = f
-            if pos + f < limit:
-                l.append(("+%d" % f, hex(nodefunc(pos + f).node())))
-            if pos - f >= 0:
-                l.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
+    navbefore = []
+    navafter = []
 
-        try:
-            yield {"label": "(0)", "node": hex(nodefunc('0').node())}
+    last = 0
+    for f in seq(1, pagelen):
+        if f < pagelen or f <= last:
+            continue
+        if f > limit:
+            break
+        last = f
+        if pos + f < limit:
+            navafter.append(("+%d" % f, hex(nodefunc(pos + f).node())))
+        if pos - f >= 0:
+            navbefore.insert(0, ("-%d" % f, hex(nodefunc(pos - f).node())))
 
+    navafter.append(("tip", "tip"))
+    try:
+        navbefore.insert(0, ("(0)", hex(nodefunc('0').node())))
+    except error.RepoError:
+        pass
+
+    def gen(l):
+        def f(**map):
             for label, node in l:
                 yield {"label": label, "node": node}
+        return f
 
-            yield {"label": "tip", "node": "tip"}
-        except error.RepoError:
-            pass
-
-    return nav
+    return (dict(before=gen(navbefore), after=gen(navafter)), )
 
 def _siblings(siblings=[], hiderev=None):
     siblings = [s for s in siblings if s.node() != nullid]
diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
--- a/mercurial/templates/coal/map
+++ b/mercurial/templates/coal/map
@@ -23,6 +23,11 @@
 changeset = ../paper/changeset.tmpl
 manifest = ../paper/manifest.tmpl
 
+nav = '{before%naventry} {after%naventry}'
+navshort = '{before%navshortentry} {after%navshortentry}'
+navgraph = '{before%navgraphentry} {after%navgraphentry}'
+filenav = '{before%filenaventry} {after%filenaventry}'
+
 direntry = '
   <tr class="fileline parity{parity}">
     <td class="name">
diff --git a/mercurial/templates/gitweb/changelog.tmpl b/mercurial/templates/gitweb/changelog.tmpl
--- a/mercurial/templates/gitweb/changelog.tmpl
+++ b/mercurial/templates/gitweb/changelog.tmpl
@@ -27,13 +27,13 @@
 <a href="{url}branches{sessionvars%urlparameter}">branches</a> |
 <a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a>{archives%archiveentry}
 <br/>
-{changenav%naventry}<br/>
+{changenav%nav}<br/>
 </div>
 
 {entries%changelogentry}
 
 <div class="page_nav">
-{changenav%naventry}<br/>
+{changenav%nav}<br/>
 </div>
 
 {footer}
diff --git a/mercurial/templates/gitweb/filelog.tmpl b/mercurial/templates/gitweb/filelog.tmpl
--- a/mercurial/templates/gitweb/filelog.tmpl
+++ b/mercurial/templates/gitweb/filelog.tmpl
@@ -24,7 +24,7 @@
 <a href="{url}diff/{node|short}/{file|urlescape}{sessionvars%urlparameter}">diff</a> |
 <a href="{url}rss-log/{node|short}/{file|urlescape}">rss</a>
 <br/>
-{nav%filenaventry}
+{nav%filenav}
 </div>
 
 <div class="title" >{file|urlescape}</div>
@@ -34,7 +34,7 @@
 </table>
 
 <div class="page_nav">
-{nav%filenaventry}
+{nav%filenav}
 </div>
 
 {footer}
diff --git a/mercurial/templates/gitweb/graph.tmpl b/mercurial/templates/gitweb/graph.tmpl
--- a/mercurial/templates/gitweb/graph.tmpl
+++ b/mercurial/templates/gitweb/graph.tmpl
@@ -29,7 +29,7 @@
 <br/>
 <a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
 <a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
-| {changenav%navgraphentry}<br/>
+| {changenav%navgraph}</br/>
 </div>
 
 <div class="title">&nbsp;</div>
@@ -115,7 +115,7 @@
 <div class="page_nav">
 <a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
 <a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
-| {changenav%navgraphentry}
+| {changenav%navgraph}
 </div>
 
 {footer}
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -34,6 +34,12 @@
       <a href="{url}log/{node|short}/{file|urlescape}{sessionvars%urlparameter}">revisions</a>
     </td>
   </tr>'
+
+nav = '{before%naventry} {after%naventry}'
+navshort = '{before%navshortentry} {after%navshortentry}'
+navgraph = '{before%navgraphentry} {after%navgraphentry}'
+filenav = '{before%filenaventry} {after%filenaventry}'
+
 fileellipses = '...'
 changelogentry = changelogentry.tmpl
 searchentry = changelogentry.tmpl
diff --git a/mercurial/templates/gitweb/shortlog.tmpl b/mercurial/templates/gitweb/shortlog.tmpl
--- a/mercurial/templates/gitweb/shortlog.tmpl
+++ b/mercurial/templates/gitweb/shortlog.tmpl
@@ -25,8 +25,7 @@
 <a href="{url}tags{sessionvars%urlparameter}">tags</a> |
 <a href="{url}branches{sessionvars%urlparameter}">branches</a> |
 <a href="{url}file/{node|short}{sessionvars%urlparameter}">files</a>{archives%archiveentry}
-<br/>
-{changenav%navshortentry}<br/>
+<br/>{changenav%navshort}<br/>
 </div>
 
 <div class="title">&nbsp;</div>
@@ -35,7 +34,7 @@
 </table>
 
 <div class="page_nav">
-{changenav%navshortentry}
+{changenav%navshort}
 </div>
 
 {footer}
diff --git a/mercurial/templates/monoblue/changelog.tmpl b/mercurial/templates/monoblue/changelog.tmpl
--- a/mercurial/templates/monoblue/changelog.tmpl
+++ b/mercurial/templates/monoblue/changelog.tmpl
@@ -34,7 +34,7 @@
     </div>
 
     <div class="page-path">
-{changenav%naventry}
+{changenav%nav}
     </div>
 
 {footer}
diff --git a/mercurial/templates/monoblue/filelog.tmpl b/mercurial/templates/monoblue/filelog.tmpl
--- a/mercurial/templates/monoblue/filelog.tmpl
+++ b/mercurial/templates/monoblue/filelog.tmpl
@@ -43,7 +43,7 @@
     </table>
 
     <div class="page-path">
-    {nav%filenaventry}
+    {nav%filenav}
     </div>
 
 {footer}
diff --git a/mercurial/templates/monoblue/graph.tmpl b/mercurial/templates/monoblue/graph.tmpl
--- a/mercurial/templates/monoblue/graph.tmpl
+++ b/mercurial/templates/monoblue/graph.tmpl
@@ -112,7 +112,7 @@
     <div class="page-path">
         <a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
         <a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
-        | {changenav%navgraphentry}
+        | {changenav%navgraph}
     </div>
 
 {footer}
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -32,6 +32,12 @@
       <a href="{url}log/{node|short}/{file|urlescape}{sessionvars%urlparameter}">revisions</a>
     </td>
   </tr>'
+
+nav = '{before%naventry} {after%naventry}'
+navshort = '{before%navshortentry} {after%navshortentry}'
+navgraph = '{before%navgraphentry} {after%navgraphentry}'
+filenav = '{before%filenaventry} {after%filenaventry}'
+
 fileellipses = '...'
 changelogentry = changelogentry.tmpl
 searchentry = changelogentry.tmpl
diff --git a/mercurial/templates/monoblue/shortlog.tmpl b/mercurial/templates/monoblue/shortlog.tmpl
--- a/mercurial/templates/monoblue/shortlog.tmpl
+++ b/mercurial/templates/monoblue/shortlog.tmpl
@@ -35,7 +35,7 @@
     </table>
 
     <div class="page-path">
-{changenav%navshortentry}
+    {changenav%navshort}
     </div>
 
 {footer}
diff --git a/mercurial/templates/paper/filelog.tmpl b/mercurial/templates/paper/filelog.tmpl
--- a/mercurial/templates/paper/filelog.tmpl
+++ b/mercurial/templates/paper/filelog.tmpl
@@ -43,7 +43,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="navigate">{nav%filenaventry}</div>
+<div class="navigate">{nav%filenav}</div>
 
 <table class="bigtable">
  <tr>
diff --git a/mercurial/templates/paper/graph.tmpl b/mercurial/templates/paper/graph.tmpl
--- a/mercurial/templates/paper/graph.tmpl
+++ b/mercurial/templates/paper/graph.tmpl
@@ -40,7 +40,7 @@
 <div class="navigate">
 <a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
 <a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
-| rev {rev}: {changenav%navgraphentry}
+| rev {rev}: {changenav%navgraph}
 </div>
 
 <noscript><p>The revision graph only works with JavaScript-enabled browsers.</p></noscript>
@@ -123,7 +123,7 @@
 <div class="navigate">
 <a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
 <a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
-| rev {rev}: {changenav%navgraphentry}
+| rev {rev}: {changenav%navgraph}
 </div>
 
 </div>
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -23,6 +23,11 @@
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 
+nav = '{before%naventry} {after%naventry}'
+navshort = '{before%navshortentry} {after%navshortentry}'
+navgraph = '{before%navgraphentry} {after%navgraphentry}'
+filenav = '{before%filenaventry} {after%filenaventry}'
+
 direntry = '
   <tr class="fileline parity{parity}">
     <td class="name">
diff --git a/mercurial/templates/paper/shortlog.tmpl b/mercurial/templates/paper/shortlog.tmpl
--- a/mercurial/templates/paper/shortlog.tmpl
+++ b/mercurial/templates/paper/shortlog.tmpl
@@ -39,7 +39,7 @@
 files, or words in the commit message</div>
 </form>
 
-<div class="navigate">rev {rev}: {changenav%navshortentry}</div>
+<div class="navigate">rev {rev}: {changenav%navshort}</div>
 
 <table class="bigtable">
  <tr>
@@ -50,7 +50,7 @@
 {entries%shortlogentry}
 </table>
 
-<div class="navigate">rev {rev}: {changenav%navshortentry}</div>
+<div class="navigate">rev {rev}: {changenav%navshort}</div>
 </div>
 </div>
 
diff --git a/mercurial/templates/spartan/changelog.tmpl b/mercurial/templates/spartan/changelog.tmpl
--- a/mercurial/templates/spartan/changelog.tmpl
+++ b/mercurial/templates/spartan/changelog.tmpl
@@ -25,7 +25,7 @@
 <p>
 <label for="search1">search:</label>
 <input name="rev" id="search1" type="text" size="30">
-navigate: <small class="navigate">{changenav%naventry}</small>
+navigate: <small class="navigate">{changenav%nav}</small>
 </p>
 </form>
 
@@ -36,7 +36,7 @@
 <p>
 <label for="search2">search:</label>
 <input name="rev" id="search2" type="text" size="30">
-navigate: <small class="navigate">{changenav%naventry}</small>
+navigate: <small class="navigate">{changenav%nav}</small>
 </p>
 </form>
 
diff --git a/mercurial/templates/spartan/filelog.tmpl b/mercurial/templates/spartan/filelog.tmpl
--- a/mercurial/templates/spartan/filelog.tmpl
+++ b/mercurial/templates/spartan/filelog.tmpl
@@ -21,7 +21,7 @@
 
 <h2>{file|escape} revision history</h2>
 
-<p>navigate: <small class="navigate">{nav%filenaventry}</small></p>
+<p>navigate: <small class="navigate">{nav%filenav}</small></p>
 
 {entries%filelogentry}
 
diff --git a/mercurial/templates/spartan/graph.tmpl b/mercurial/templates/spartan/graph.tmpl
--- a/mercurial/templates/spartan/graph.tmpl
+++ b/mercurial/templates/spartan/graph.tmpl
@@ -23,7 +23,7 @@
 <p>
 <label for="search1">search:</label>
 <input name="rev" id="search1" type="text" size="30">
-navigate: <small class="navigate">{changenav%navgraphentry}</small>
+navigate: <small class="navigate">{changenav%navgraph}</small>
 </p>
 </form>
 
@@ -89,7 +89,7 @@
 <p>
 <label for="search1">search:</label>
 <input name="rev" id="search1" type="text" size="30">
-navigate: <small class="navigate">{changenav%navgraphentry}</small>
+navigate: <small class="navigate">{changenav%navgraph}</small>
 </p>
 </form>
 
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -20,6 +20,11 @@
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 
+nav = '{before%naventry} {after%naventry}'
+navshort = '{before%navshortentry} {after%navshortentry}'
+navgraph = '{before%navgraphentry} {after%navgraphentry}'
+filenav = '{before%filenaventry} {after%filenaventry}'
+
 direntry = '
   <tr class="parity{parity}">
     <td><tt>drwxr-xr-x</tt>&nbsp;
diff --git a/mercurial/templates/spartan/shortlog.tmpl b/mercurial/templates/spartan/shortlog.tmpl
--- a/mercurial/templates/spartan/shortlog.tmpl
+++ b/mercurial/templates/spartan/shortlog.tmpl
@@ -25,7 +25,7 @@
 <p>
 <label for="search1">search:</label>
 <input name="rev" id="search1" type="text" size="30">
-navigate: <small class="navigate">{changenav%navshortentry}</small>
+navigate: <small class="navigate">{changenav%navshort}</small>
 </p>
 </form>
 
@@ -36,7 +36,7 @@
 <p>
 <label for="search2">search:</label>
 <input name="rev" id="search2" type="text" size="30">
-navigate: <small class="navigate">{changenav%navshortentry}</small>
+navigate: <small class="navigate">{changenav%navshort}</small>
 </p>
 </form>
 


More information about the Mercurial-devel mailing list