Commits

Dirkjan Ochtman committed 5565132

hgweb: fix up the less/more links on the graph page

Previously, they pointed to a non-intuitive revision, and got borked when
using a URL-specified style combined with alternate revcounts.

  • Participants
  • Parent commits 2dc8687

Comments (0)

Files changed (6)

File mercurial/hgweb/hgweb_mod.py

         def motd(**map):
             yield self.config("web", "motd", "")
 
-        def sessionvars(**map):
-            fields = []
-            if 'style' in req.form:
-                style = req.form['style'][0]
-                if style != self.config('web', 'style', ''):
-                    fields.append(('style', style))
-
-            separator = req.url[-1] == '?' and ';' or '?'
-            for name, value in fields:
-                yield dict(name=name, value=value, separator=separator)
-                separator = ';'
-
         # figure out which style to use
 
+        vars = {}
         style = self.config("web", "style", "")
         if 'style' in req.form:
             style = req.form['style'][0]
+            vars['style'] = style
+
+        start = req.url[-1] == '?' and '&' or '?'
+        sessionvars = webutil.sessionvars(vars, start)
         mapfile = style_map(self.templatepath, style)
 
         if not self.reponame:

File mercurial/hgweb/webcommands.py

 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-import os, mimetypes, re, cgi
+import os, mimetypes, re, cgi, copy
 import webutil
 from mercurial import revlog, archival, templatefilters
 from mercurial.node import short, hex, nullid
     rev = webutil.changectx(web.repo, req).rev()
     bg_height = 39
 
+    revcount = 25
+    if 'revcount' in req.form:
+        revcount = int(req.form.get('revcount', [revcount])[0])
+        tmpl.defaults['sessionvars']['revcount'] = revcount
+
+    lessvars = copy.copy(tmpl.defaults['sessionvars'])
+    lessvars['revcount'] = revcount / 2
+    morevars = copy.copy(tmpl.defaults['sessionvars'])
+    morevars['revcount'] = revcount * 2
+
     max_rev = len(web.repo) - 1
-    revcount = min(max_rev, int(req.form.get('revcount', [25])[0]))
+    revcount = min(max_rev, revcount)
     revnode = web.repo.changelog.node(rev)
     revnode_hex = hex(revnode)
     uprev = min(max_rev, rev + revcount)
     downrev = max(0, rev - revcount)
-    lessrev = max(0, rev - revcount / 2)
-
     count = len(web.repo)
     changenav = webutil.revnavgen(rev, revcount, count, web.repo.changectx)
 
     tree = list(graphmod.graph(web.repo, rev, downrev))
     canvasheight = (len(tree) + 1) * bg_height - 27;
-
     data = []
     for i, (ctx, vtx, edges) in enumerate(tree):
         node = short(ctx.node())
         data.append((node, vtx, edges, desc, user, age, branch, ctx.tags()))
 
     return tmpl('graph', rev=rev, revcount=revcount, uprev=uprev,
-                lessrev=lessrev, revcountmore=revcount and 2 * revcount or 1,
-                revcountless=revcount / 2, downrev=downrev,
-                canvasheight=canvasheight, bg_height=bg_height,
-                jsdata=data, node=revnode_hex, changenav=changenav)
+                lessvars=lessvars, morevars=morevars, downrev=downrev,
+                canvasheight=canvasheight, jsdata=data, bg_height=bg_height,
+                node=revnode_hex, changenav=changenav)

File mercurial/hgweb/webutil.py

 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
-import os
+import os, copy
 from mercurial import match, patch
 from mercurial.node import hex, nullid
 from mercurial.repo import RepoError
         block.append(chunk)
     yield tmpl('diffblock', parity=parity.next(),
                lines=prettyprintlines(''.join(block)))
+
+class sessionvars(object):
+    def __init__(self, vars, start='?'):
+        self.start = start
+        self.vars = vars
+    def __getitem__(self, key):
+        return self.vars[key]
+    def __setitem__(self, key, value):
+        self.vars[key] = value
+    def __copy__(self):
+        return sessionvars(copy.copy(self.vars), self.start)
+    def __iter__(self):
+        separator = self.start
+        for key, value in self.vars.iteritems():
+            yield {'name': key, 'value': str(value), 'separator': separator}
+            separator = '&'

File templates/coal/graph.tmpl

 </form>
 
 <div class="navigate">
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a>
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a>
+<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
+<a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
 | rev {rev}: {changenav%navgraphentry}
 </div>
 
 </script>
 
 <div class="navigate">
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a>
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a>
+<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
+<a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
 | rev {rev}: {changenav%navgraphentry}
 </div>
 

File templates/gitweb/graph.tmpl

 <a href="{url}tags{sessionvars%urlparameter}">tags</a> |
 <a href="{url}file/#node|short#{sessionvars%urlparameter}">files</a>
 <br/>
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a>
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a>
+<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
+<a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
 | #changenav%navgraphentry#<br/>
 </div>
 
 </script>
 
 <div class="page_nav">
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountless}">less</a>
-<a href="{url}graph/{uprev}{sessionvars%urlparameter}?revcount={revcountmore}">more</a>
+<a href="{url}graph/{rev}{lessvars%urlparameter}">less</a>
+<a href="{url}graph/{rev}{morevars%urlparameter}">more</a>
 | {changenav%navgraphentry}
 </div>
 

File tests/test-hgweb-commands.out

Binary file modified.