[PATCH] gitweb: Display branch and tag labels

Brendan Cully brendan at kublai.com
Mon Jun 11 13:09:14 CDT 2007


On Saturday, 02 June 2007 at 12:49, Thomas Arendsen Hein wrote:
> * Josef 'Jeff' Sipek <jeffpc at josefsipek.net> [20070602 02:03]:
> > # User Josef "Jeff" Sipek <jeffpc at josefsipek.net>
> > # Date 1180742199 14400
> > # Node ID d46d3197a5d199679067557b23558b8bdce1acd8
> > # Parent  e8a5840678255657d3b97cc1215a005aac061ede
> > gitweb: Display branch and tag labels
> 
> I like it and I hope a corresponding change for hgweb would come
> soon, too.
> 
> > +    def taglistdict(self,node):
> > +        return [{"name":i} for i in self.repo.nodetags(node)]
> 
> spacing issues, e.g. (self, node) and {"name": i}
> 
> And maybe call it nodetagsdict, because it yields a dict with the
> result of nodetags.
> 
> > +    def branchlistdict(self,node):
> > +        l=[]
> > +        for t, tn in self.repo.branchtags().items():
> > +            if tn == node:
> > +                l.append({"name":t})
> > +        return l
> 
> The branch of a changeset (there can only be one!) can easily be
> read by using ctx.branch() ... no need to go the long way.

Well, you can't just use ctx.branch() on its own because you only want
the tag next to the tip of the branch. How about the following
cleanups?

It seems a little silly to put the branch in an array, but I don't see
another way of not generating the span when there's nothing to
display.
-------------- next part --------------
# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1181585202 25200
# Node ID e6c69a2491ed97d94b1d666e23f64ecf2f917fe4
# Parent  4272ae760bb183ab0a44371b6650cf3af1d75af4
Small cleanups for the new tag code

diff -r 4272ae760bb1 -r e6c69a2491ed mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Fri Jun 01 19:56:39 2007 -0400
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Jun 11 11:06:42 2007 -0700
@@ -133,15 +133,15 @@ class hgweb(object):
             return [dict(file=r[0], node=hex(r[1]))]
         return []
 
-    def taglistdict(self,node):
-        return [{"name":i} for i in self.repo.nodetags(node)]
-
-    def branchlistdict(self,node):
-        l=[]
-        for t, tn in self.repo.branchtags().items():
-            if tn == node:
-                l.append({"name":t})
-        return l
+    def nodetagsdict(self, node):
+        return [{"name": i} for i in self.repo.nodetags(node)]
+
+    def nodebranchdict(self, ctx):
+        branches = []
+        branch = ctx.branch()
+        if self.repo.branchtags()[branch] == ctx.node():
+            branches.append({"name": branch})
+        return branches
 
     def showtag(self, t1, node=nullid, **args):
         for t in self.repo.nodetags(node):
@@ -222,8 +222,8 @@ class hgweb(object):
                              "files": self.listfilediffs(ctx.files(), n),
                              "rev": i,
                              "node": hex(n),
-                             "tags": self.taglistdict(n),
-                             "branches": self.branchlistdict(n)})
+                             "tags": self.nodetagsdict(n),
+                             "branches": self.nodebranchdict(ctx)})
 
             for e in l:
                 yield e
@@ -287,8 +287,8 @@ class hgweb(object):
                              files=self.listfilediffs(ctx.files(), n),
                              rev=ctx.rev(),
                              node=hex(n),
-                             tags=self.taglistdict(n),
-                             branches=self.branchlistdict(n))
+                             tags=self.nodetagsdict(n),
+                             branches=self.nodebranchdict(ctx))
 
                 if count >= self.maxchanges:
                     break
@@ -329,8 +329,8 @@ class hgweb(object):
                      date=ctx.date(),
                      files=files,
                      archives=self.archivelist(hex(n)),
-                     tags=self.taglistdict(n),
-                     branches=self.branchlistdict(n))
+                     tags=self.nodetagsdict(n),
+                     branches=self.nodebranchdict(ctx))
 
     def filelog(self, fctx):
         f = fctx.path()
@@ -499,8 +499,8 @@ class hgweb(object):
                      fentries=filelist,
                      dentries=dirlist,
                      archives=self.archivelist(hex(node)),
-                     tags=self.taglistdict(node),
-                     branches=self.branchlistdict(node))
+                     tags=self.nodetagsdict(node),
+                     branches=self.nodebranchdict(ctx))
 
     def tags(self):
         i = self.repo.tagslist()
@@ -574,8 +574,8 @@ class hgweb(object):
                     date=ctx.date(),
                     rev=i,
                     node=hn,
-                    tags=self.taglistdict(n),
-                    branches=self.branchlistdict(n)))
+                    tags=self.nodetagsdict(n),
+                    branches=self.nodebranchdict(ctx)))
 
             yield l
 


More information about the Mercurial-devel mailing list