hgweb: hoist changenav up, and use it in the filelog
authorBrendan Cully <brendan@kublai.com>
Sun, 15 Oct 2006 23:51:28 -0700
changeset 3407 03e7e8958a27
parent 3406 970b2d6de3b3
child 3408 4e0c08f019b8
hgweb: hoist changenav up, and use it in the filelog
mercurial/hgweb/hgweb_mod.py
templates/filelog.tmpl
templates/gitweb/filelog.tmpl
templates/gitweb/map
templates/map
--- a/mercurial/hgweb/hgweb_mod.py	Sun Oct 15 21:20:15 2006 -0700
+++ b/mercurial/hgweb/hgweb_mod.py	Sun Oct 15 23:51:28 2006 -0700
@@ -28,6 +28,41 @@
         return "/"
     return up + "/"
 
+def revnavgen(pos, pagelen, limit):
+    def seq(factor, limit=None):
+        if limit:
+            yield limit
+            if limit >= 20 and limit <= 40:
+                yield 50
+        else:
+            yield 1 * factor
+            yield 3 * factor
+        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, pos + f))
+            if pos - f >= 0:
+                l.insert(0, ("-%d" % f, pos - f))
+
+        yield {"label": "(0)", "rev": 0}
+
+        for label, rev in l:
+            yield {"label": label, "rev": rev}
+
+        yield {"label": "tip", "rev": "tip"}
+
+    return nav
+
 class hgweb(object):
     def __init__(self, repo, name=None):
         if type(repo) == type(""):
@@ -149,41 +184,6 @@
                                           opts=diffopts), f, tn)
 
     def changelog(self, ctx, shortlog=False):
-        pos = ctx.rev()
-        def changenav(**map):
-            def seq(factor, maxchanges=None):
-                if maxchanges:
-                    yield maxchanges
-                    if maxchanges >= 20 and maxchanges <= 40:
-                        yield 50
-                else:
-                    yield 1 * factor
-                    yield 3 * factor
-                for f in seq(factor * 10):
-                    yield f
-
-            l = []
-            last = 0
-            maxchanges = shortlog and self.maxshortchanges or self.maxchanges
-            for f in seq(1, maxchanges):
-                if f < maxchanges or f <= last:
-                    continue
-                if f > count:
-                    break
-                last = f
-                r = "%d" % f
-                if pos + f < count:
-                    l.append(("+" + r, pos + f))
-                if pos - f >= 0:
-                    l.insert(0, ("-" + r, pos - f))
-
-            yield {"rev": 0, "label": "(0)"}
-
-            for label, rev in l:
-                yield {"label": label, "rev": rev}
-
-            yield {"label": "tip", "rev": "tip"}
-
         def changelist(**map):
             parity = (start - end) & 1
             cl = self.repo.changelog
@@ -210,10 +210,13 @@
         maxchanges = shortlog and self.maxshortchanges or self.maxchanges
         cl = self.repo.changelog
         count = cl.count()
+        pos = ctx.rev()
         start = max(0, pos - maxchanges + 1)
         end = min(count, start + maxchanges)
         pos = end - 1
 
+        changenav = revnavgen(pos, maxchanges, count)
+
         yield self.t(shortlog and 'shortlog' or 'changelog',
                      changenav=changenav,
                      node=hex(cl.tip()),
@@ -306,12 +309,17 @@
         f = fctx.path()
         fl = fctx.filelog()
         count = fl.count()
+        pagelen = self.maxshortchanges
 
         def entries(**map):
+            pos = fctx.filerev()
+            start = max(0, pos - pagelen + 1) 
+            end = min(count, start + pagelen)
+            pos = end - 1
             l = []
             parity = (count - 1) & 1
 
-            for i in range(count):
+            for i in range(start, end):
                 ctx = fctx.filectx(i)
                 n = fl.node(i)
 
@@ -330,7 +338,9 @@
             for e in l:
                 yield e
 
-        yield self.t("filelog", file=f, node=hex(fctx.node()), entries=entries)
+        nav = revnavgen(fctx.filerev(), self.maxshortchanges, count)
+        yield self.t("filelog", file=f, node=hex(fctx.node()), nav=nav,
+                     entries=entries)
 
     def filerevision(self, fctx):
         f = fctx.path()
--- a/templates/filelog.tmpl	Sun Oct 15 21:20:15 2006 -0700
+++ b/templates/filelog.tmpl	Sun Oct 15 23:51:28 2006 -0700
@@ -17,6 +17,8 @@
 
 <h2>#file|escape# revision history</h2>
 
+<p>navigate: <small class="navigate">{nav%filenaventry}</small></p>
+
 #entries%filelogentry#
 
 #footer#
--- a/templates/gitweb/filelog.tmpl	Sun Oct 15 21:20:15 2006 -0700
+++ b/templates/gitweb/filelog.tmpl	Sun Oct 15 23:51:28 2006 -0700
@@ -19,6 +19,9 @@
 <a href="{url}annotate/{node|short}/#file|urlescape#{sessionvars%urlparameter}">annotate</a> |
 <a href="{url}diff/{node|short}/{file|urlescape}{sessionvars%urlparameter}">diff</a> |
 <a href="{url}rss-log/#node|short#/#file|urlescape#">rss</a><br/>
+
+<br/>
+{nav%filenaventry}<br/>
 </div>
 
 <div class="title" >#file|urlescape#</div>
--- a/templates/gitweb/map	Sun Oct 15 21:20:15 2006 -0700
+++ b/templates/gitweb/map	Sun Oct 15 23:51:28 2006 -0700
@@ -7,6 +7,7 @@
 error = error.tmpl
 naventry = '<a href="#url#log/#rev#{sessionvars%urlparameter}">#label|escape#</a> '
 navshortentry = '<a href="#url#shortlog/#rev#{sessionvars%urlparameter}">#label|escape#</a> '
+filenaventry = '<a href="{url}log/{rev}/{file|urlescape}{sessionvars%urlparameter}">{label|escape}</a> '
 filedifflink = '<a href="#url#diff/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#file|escape#</a> '
 filenodelink = '<tr class="parity#parity#"><td><a class="list" href="{url}diff/{node|short}/{file|urlescape}{sessionvars%urlparameter}">#file|escape#</a></td><td></td><td class="link"><a href="#url#file/#node|short#/#file|urlescape#{sessionvars%urlparameter}">file</a> | <a href="#url#annotate/#node|short#/#file|urlescape#{sessionvars%urlparameter}">annotate</a> | <a href="#url#diff/#node|short#/#file|urlescape#{sessionvars%urlparameter}">diff</a> | <a href="#url#log/#node|short#/#file|urlescape#{sessionvars%urlparameter}">revisions</a></td></tr>'
 fileellipses = '...'
--- a/templates/map	Sun Oct 15 21:20:15 2006 -0700
+++ b/templates/map	Sun Oct 15 23:51:28 2006 -0700
@@ -7,6 +7,7 @@
 shortlogentry = shortlogentry.tmpl
 naventry = '<a href="#url#log/#rev#{sessionvars%urlparameter}">#label|escape#</a> '
 navshortentry = '<a href="#url#shortlog/#rev#{sessionvars%urlparameter}">#label|escape#</a> '
+filenaventry = '<a href="{url}log/{rev}/{file|urlescape}{sessionvars%urlparameter}">{label|escape}</a> '
 filedifflink = '<a href="#url#diff/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#file|escape#</a> '
 filenodelink = '<a href="#url#file/#node|short#/#file|urlescape#{sessionvars%urlparameter}">#file|escape#</a> '
 fileellipses = '...'