[PATCH 3 of 3] hgweb: provide links to branches, tags and bookmarks by name (paper and coal)

Anton Shestakov av6 at dwimlabs.net
Mon Jul 13 07:19:00 CDT 2015


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1436695488 -28800
#      Sun Jul 12 18:04:48 2015 +0800
# Node ID c62766ca6cae325bb0232b3bb401c87ab2feb083
# Parent  87beef5bc365a41688531b1e1df161485710cf38
hgweb: provide links to branches, tags and bookmarks by name (paper and coal)

It's sometimes handy to, say, have a url always point to branch head, not just
at the current branch head by node hash. Previously, this was only possible by
manually editing url and replacing node hash with branch/tag/bookmark name. It
wasn't very convenient, or easy - in case the name contained special
characters that needed to be urlencoded.

Let's have /branches, /tags and /bookmarks pages in paper and coal style
provide links both to symbolic revisions and to node hashes.

This feature was wished for in issue3594.

diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
--- a/mercurial/templates/coal/map
+++ b/mercurial/templates/coal/map
@@ -158,36 +158,42 @@ tags = ../paper/tags.tmpl
 tagentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+      <a href="{url|urlescape}rev/{tag|revescape}{sessionvars%urlparameter}">
         {tag|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 bookmarks = ../paper/bookmarks.tmpl
 bookmarkentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+      <a href="{url|urlescape}rev/{bookmark|revescape}{sessionvars%urlparameter}">
         {bookmark|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 branches = ../paper/branches.tmpl
 branchentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}shortlog/{node|short}{sessionvars%urlparameter}" class="{status}">
+      <a href="{url|urlescape}shortlog/{branch|revescape}{sessionvars%urlparameter}" class="{status}">
         {branch|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}shortlog/{node|short}{sessionvars%urlparameter}" class="{status}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 changelogtag = '<span class="tag">{name|escape}</span> '
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -161,36 +161,42 @@ tags = tags.tmpl
 tagentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+      <a href="{url|urlescape}rev/{tag|revescape}{sessionvars%urlparameter}">
         {tag|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 bookmarks = bookmarks.tmpl
 bookmarkentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+      <a href="{url|urlescape}rev/{bookmark|revescape}{sessionvars%urlparameter}">
         {bookmark|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 branches = branches.tmpl
 branchentry = '
   <tr class="tagEntry">
     <td>
-      <a href="{url|urlescape}shortlog/{node|short}{sessionvars%urlparameter}" class="{status}">
+      <a href="{url|urlescape}shortlog/{branch|revescape}{sessionvars%urlparameter}" class="{status}">
         {branch|escape}
       </a>
     </td>
     <td class="node">
-      {node|short}
+      <a href="{url|urlescape}shortlog/{node|short}{sessionvars%urlparameter}" class="{status}">
+        {node|short}
+      </a>
     </td>
   </tr>'
 changelogtag = '<span class="tag">{name|escape}</span> '
diff --git a/tests/test-hgweb-symrev.t b/tests/test-hgweb-symrev.t
--- a/tests/test-hgweb-symrev.t
+++ b/tests/test-hgweb-symrev.t
@@ -33,7 +33,7 @@ Set up the repo
   $ hg serve --config web.allow_archive=zip -n test -p $HGPORT -d --pid-file=hg.pid -E errors.log
   $ cat hg.pid >> $DAEMON_PIDS
 
-  $ REVLINKS='href=[^>]+(rev=|/)(43c799df6e75|0|a7c1559b7bba|1|xyzzy|9d8c40cba617|2|tip)'
+  $ REVLINKS='href=[^>]+(rev=|/)(43c799df6e75|0|a7c1559b7bba|1|xyzzy|9d8c40cba617|2|tip|default)'
 
 (De)referencing symbolic revisions (paper)
 
@@ -74,6 +74,18 @@ Set up the repo
   <a href="/file/tip/dir/?style=paper">
   <a href="/file/tip/foo?style=paper">
 
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'branches?style=paper' | egrep $REVLINKS
+  <a href="/shortlog/default?style=paper" class="open">
+  <a href="/shortlog/9d8c40cba617?style=paper" class="open">
+
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'tags?style=paper' | egrep $REVLINKS
+  <a href="/rev/tip?style=paper">
+  <a href="/rev/9d8c40cba617?style=paper">
+
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'bookmarks?style=paper' | egrep $REVLINKS
+  <a href="/rev/xyzzy?style=paper">
+  <a href="/rev/a7c1559b7bba?style=paper">
+
   $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'shortlog?style=paper&rev=all()' | egrep $REVLINKS
      <a href="/rev/9d8c40cba617?style=paper">third</a>
      <a href="/rev/a7c1559b7bba?style=paper">second</a>
@@ -249,6 +261,18 @@ Set up the repo
   <a href="/file/tip/dir/?style=coal">
   <a href="/file/tip/foo?style=coal">
 
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'branches?style=coal' | egrep $REVLINKS
+  <a href="/shortlog/default?style=coal" class="open">
+  <a href="/shortlog/9d8c40cba617?style=coal" class="open">
+
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'tags?style=coal' | egrep $REVLINKS
+  <a href="/rev/tip?style=coal">
+  <a href="/rev/9d8c40cba617?style=coal">
+
+  $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'bookmarks?style=coal' | egrep $REVLINKS
+  <a href="/rev/xyzzy?style=coal">
+  <a href="/rev/a7c1559b7bba?style=coal">
+
   $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'shortlog?style=coal&rev=all()' | egrep $REVLINKS
      <a href="/rev/9d8c40cba617?style=coal">third</a>
      <a href="/rev/a7c1559b7bba?style=coal">second</a>


More information about the Mercurial-devel mailing list