merge with mpm
authorDirkjan Ochtman <dirkjan@ochtman.nl>
Sat, 08 Nov 2008 00:29:04 +0100
changeset 7348 1a5c9ca2bfd5
parent 7347 bc158cd800fa (current diff)
parent 7345 55651328dfcc (diff)
child 7349 f711b8e0d2b3
merge with mpm
mercurial/hgweb/hgweb_mod.py
tests/test-hgweb-commands.out
--- a/mercurial/hgweb/hgweb_mod.py	Sat Nov 08 00:27:51 2008 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Sat Nov 08 00:29:04 2008 +0100
@@ -228,23 +228,16 @@
         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", "paper")
         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:
--- a/mercurial/hgweb/webcommands.py	Sat Nov 08 00:27:51 2008 +0100
+++ b/mercurial/hgweb/webcommands.py	Sat Nov 08 00:29:04 2008 +0100
@@ -5,7 +5,7 @@
 # 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
@@ -619,20 +619,27 @@
     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())
@@ -645,7 +652,6 @@
         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)
--- a/mercurial/hgweb/webutil.py	Sat Nov 08 00:27:51 2008 +0100
+++ b/mercurial/hgweb/webutil.py	Sat Nov 08 00:29:04 2008 +0100
@@ -6,7 +6,7 @@
 # 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
@@ -196,3 +196,19 @@
         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 = '&'
--- a/templates/coal/graph.tmpl	Sat Nov 08 00:27:51 2008 +0100
+++ b/templates/coal/graph.tmpl	Sat Nov 08 00:29:04 2008 +0100
@@ -37,8 +37,8 @@
 </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>
 
@@ -102,8 +102,8 @@
 </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>
 
--- a/templates/gitweb/graph.tmpl	Sat Nov 08 00:27:51 2008 +0100
+++ b/templates/gitweb/graph.tmpl	Sat Nov 08 00:29:04 2008 +0100
@@ -25,8 +25,8 @@
 <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>
 
@@ -111,8 +111,8 @@
 </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>
 
Binary file tests/test-hgweb-commands.out has changed