[PATCH] hgweb: add heads to gitweb summary

Brendan Cully brendan at kublai.com
Mon Oct 23 21:22:34 UTC 2006


On Monday, 23 October 2006 at 14:50, Matt Mackall wrote:
> On Mon, Oct 23, 2006 at 11:35:02AM -0700, Brendan Cully wrote:
> > Here's an updated version that uses the new branchtags code (showing
> > the short hash if there's no tag for a head).
> 
> > # HG changeset patch
> > # User Brendan Cully <brendan at kublai.com>
> > # Date 1161628292 25200
> > # Node ID 5590dbf961707f9f315c9acfb74da84ebeec4187
> > # Parent  c3345b0f2fcdb3bb8cf3a6bf572159ec7e190a90
> > hgweb: add heads to gitweb summary
> > 
> > diff -r c3345b0f2fcd -r 5590dbf96170 mercurial/hgweb/hgweb_mod.py
> > +++ b/mercurial/hgweb/hgweb_mod.py	Mon Oct 23 11:31:32 2006 -0700
> > @@ -527,6 +527,29 @@ class hgweb(object):
> >                               date = t)
> >                  parity += 1
> >  
> > +        def heads(**map):
> > +            parity = 0
> > +            count = 0
> > +
> > +            branches = {}
> > +            for label, node in self.repo.branchtags().iteritems():
> > +                branches[node] = label
> 
> Eep, no! Loading the branch tags can be expensive and should only be
> done as a last resort. Especially with hgweb, which may not be able to
> write out the branch cache. 
> 
> Instead, read the branch labels directly out of the changeset using
> changectx.branch().
> 
> Also, be careful not to confuse branches and heads, they're slightly
> different concepts.

How about this?

-------------- next part --------------
# HG changeset patch
# User Brendan Cully <brendan at kublai.com>
# Date 1161637333 25200
# Node ID 654d8cf43b6f44f2bf70ee069563bb5b4f73f656
# Parent  c3345b0f2fcdb3bb8cf3a6bf572159ec7e190a90
hgweb: add heads to gitweb summary

diff -r c3345b0f2fcd -r 654d8cf43b6f mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py	Mon Oct 23 14:56:51 2006 +0200
+++ b/mercurial/hgweb/hgweb_mod.py	Mon Oct 23 14:02:13 2006 -0700
@@ -527,6 +527,23 @@ class hgweb(object):
                              date = t)
                 parity += 1
 
+        def heads(**map):
+            parity = 0
+            count = 0
+
+            for node in self.repo.heads():
+                count += 1
+                if count > 10:
+                    break;
+
+                ctx = self.repo.changectx(node)
+
+                yield {'parity': self.stripes(parity),
+                       'branch': ctx.branch(),
+                       'node': hex(node),
+                       'date': ctx.date()}
+                parity += 1
+
         def changelist(**map):
             parity = 0
             cl = self.repo.changelog
@@ -560,6 +577,7 @@ class hgweb(object):
                           self.repo.ui.config("web", "author", "unknown")), # also
                  lastchange = cl.read(cl.tip())[2],
                  tags = tagentries,
+                 heads = heads,
                  shortlog = changelist,
                  node = hex(cl.tip()),
                  archives=self.archivelist("tip"))
diff -r c3345b0f2fcd -r 654d8cf43b6f templates/gitweb/map
--- a/templates/gitweb/map	Mon Oct 23 14:56:51 2006 +0200
+++ b/templates/gitweb/map	Mon Oct 23 14:02:13 2006 -0700
@@ -39,6 +39,7 @@ fileannotatechild = '<tr><td class="meta
 fileannotatechild = '<tr><td class="metatag">child {rev}:</td><td><a href="{url}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{node|short}</a></td></tr>'
 tags = tags.tmpl
 tagentry = '<tr class="parity#parity#"><td class="age"><i>#date|age# ago</i></td><td><a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}"><b>#tag|escape#</b></a></td><td class="link"><a href="{url}rev/#node|short#{sessionvars%urlparameter}">changeset</a> | <a href="{url}log/#node|short#{sessionvars%urlparameter}">changelog</a> | <a href="{url}file/#node|short#{sessionvars%urlparameter}">manifest</a></td></tr>'
+headentry = '<tr class="parity{parity}"><td class="age"><i>{date|age} ago</i></td><td><a class="list" href="{url}rev/{node|short}{sessionvars%urlparameter}"><b>{node|short}</td><td>{branch|escape}</td><td class="link"><a href="{url}rev/{node|short}{sessionvars%urlparameter}">changeset</a> | <a href="{url}log/{node|short}{sessionvars%urlparameter}">changelog</a> | <a href="{url}file/{node|short}{sessionvars%urlparameter}">manifest</a></td></tr>'
 diffblock = '<pre>#lines#</pre>'
 changelogtag = '<tr><th class="tag">tag:</th><td class="tag">#tag|escape#</td></tr>'
 changesettag = '<tr><td>tag</td><td>#tag|escape#</td></tr>'
diff -r c3345b0f2fcd -r 654d8cf43b6f templates/gitweb/summary.tmpl
--- a/templates/gitweb/summary.tmpl	Mon Oct 23 14:56:51 2006 +0200
+++ b/templates/gitweb/summary.tmpl	Mon Oct 23 14:02:13 2006 -0700
@@ -36,4 +36,12 @@ summary |
 <tr class="light"><td colspan="3"><a class="list" href="{url}tags{sessionvars%urlparameter}">...</a></td></tr>
 </table>
 
+<div><a class="title"
+href="#">heads</a></div>
+<table cellspacing="0">
+{heads%headentry}
+<tr class="light">
+  <td colspan="3"><a class="list"  href="#">...</a></td>
+</tr>
+</table>
 #footer#


More information about the Mercurial-devel mailing list