changeset 7671:06cf09c822c4

hgweb: simplify parents/children generation code
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 19 Jan 2009 13:20:47 +0100
parents e5f445c94226
children 523c7816c33a
files mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py
diffstat 2 files changed, 21 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Mon Jan 19 12:59:56 2009 +0100
+++ b/mercurial/hgweb/webcommands.py	Mon Jan 19 13:20:47 2009 +0100
@@ -81,8 +81,8 @@
                 date=fctx.date(),
                 desc=fctx.description(),
                 branch=webutil.nodebranchnodefault(fctx),
-                parent=webutil.siblings(fctx.parents()),
-                child=webutil.siblings(fctx.children()),
+                parent=webutil.parents(fctx),
+                child=webutil.children(fctx),
                 rename=webutil.renamelink(fctx),
                 permissions=fctx.manifest().flags(f))
 
@@ -134,8 +134,8 @@
             yield tmpl('searchentry',
                        parity=parity.next(),
                        author=ctx.user(),
-                       parent=webutil.siblings(ctx.parents()),
-                       child=webutil.siblings(ctx.children()),
+                       parent=webutil.parents(ctx),
+                       child=webutil.children(ctx),
                        changelogtag=showtags,
                        desc=ctx.description(),
                        date=ctx.date(),
@@ -182,8 +182,8 @@
 
             l.insert(0, {"parity": parity.next(),
                          "author": ctx.user(),
-                         "parent": webutil.siblings(ctx.parents(), i - 1),
-                         "child": webutil.siblings(ctx.children(), i + 1),
+                         "parent": webutil.parents(ctx, i - 1),
+                         "child": webutil.children(ctx, i + 1),
                          "changelogtag": showtags,
                          "desc": ctx.description(),
                          "date": ctx.date(),
@@ -227,7 +227,6 @@
     ctx = webutil.changectx(web.repo, req)
     showtags = webutil.showtag(web.repo, tmpl, 'changesettag', ctx.node())
     showbranch = webutil.nodebranchnodefault(ctx)
-    parents = ctx.parents()
 
     files = []
     parity = paritygen(web.stripecount)
@@ -243,8 +242,8 @@
                 diff=diffs,
                 rev=ctx.rev(),
                 node=ctx.hex(),
-                parent=webutil.siblings(parents),
-                child=webutil.siblings(ctx.children()),
+                parent=webutil.parents(ctx),
+                child=webutil.children(ctx),
                 changesettag=showtags,
                 changesetbranch=showbranch,
                 author=ctx.user(),
@@ -442,12 +441,9 @@
     if fctx is not None:
         n = fctx.node()
         path = fctx.path()
-        parents = fctx.parents()
-        p1 = parents and parents[0].node() or nullid
     else:
         n = ctx.node()
         # path already defined in except clause
-        parents = ctx.parents()
 
     parity = paritygen(web.stripecount)
     diffs = webutil.diffs(web.repo, tmpl, fctx or ctx, [path], parity)
@@ -462,8 +458,8 @@
                 author=ctx.user(),
                 rename=rename,
                 branch=webutil.nodebranchnodefault(ctx),
-                parent=webutil.siblings(parents),
-                child=webutil.siblings(ctx.children()),
+                parent=webutil.parents(ctx),
+                child=webutil.children(ctx),
                 diff=diffs)
 
 diff = filediff
@@ -510,8 +506,8 @@
                 desc=fctx.description(),
                 rename=webutil.renamelink(fctx),
                 branch=webutil.nodebranchnodefault(fctx),
-                parent=webutil.siblings(fctx.parents()),
-                child=webutil.siblings(fctx.children()),
+                parent=webutil.parents(fctx),
+                child=webutil.children(fctx),
                 permissions=fctx.manifest().flags(f))
 
 def filelog(web, req, tmpl):
@@ -555,8 +551,8 @@
                          "author": iterfctx.user(),
                          "date": iterfctx.date(),
                          "rename": webutil.renamelink(iterfctx),
-                         "parent": webutil.siblings(iterfctx.parents()),
-                         "child": webutil.siblings(iterfctx.children()),
+                         "parent": webutil.parents(iterfctx),
+                         "child": webutil.children(iterfctx),
                          "desc": iterfctx.description(),
                          "tags": webutil.nodetagsdict(repo, iterfctx.node()),
                          "branch": webutil.nodebranchnodefault(iterfctx),
--- a/mercurial/hgweb/webutil.py	Mon Jan 19 12:59:56 2009 +0100
+++ b/mercurial/hgweb/webutil.py	Mon Jan 19 13:20:47 2009 +0100
@@ -58,7 +58,7 @@
 
     return nav
 
-def siblings(siblings=[], hiderev=None, **args):
+def _siblings(siblings=[], hiderev=None):
     siblings = [s for s in siblings if s.node() != nullid]
     if len(siblings) == 1 and siblings[0].rev() == hiderev:
         return
@@ -69,9 +69,14 @@
         d['description'] = s.description()
         if hasattr(s, 'path'):
             d['file'] = s.path()
-        d.update(args)
         yield d
 
+def parents(ctx, hide=None):
+    return _siblings(ctx.parents(), hide)
+
+def children(ctx, hide=None):
+    return _siblings(ctx.children(), hide)
+
 def renamelink(fctx):
     r = fctx.renamed()
     if r: