[PATCH 2 of 2 PoC] hgweb: link to successors of obsoleted changesets (PoC)

Anton Shestakov av6 at dwimlabs.net
Fri Dec 15 14:41:48 UTC 2017


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1513346027 -28800
#      Fri Dec 15 21:53:47 2017 +0800
# Node ID 4273260ac0d6e9bcb293607c7bdc16d0d246e6e9
# Parent  3764b68ff62bb5144f814f17ffe6465bd915e51b
# EXP-Topic hgweb-more-info
hgweb: link to successors of obsoleted changesets (PoC)

This sort of works, but I have doubts about that "node" attribute that is
added. Something tells me that there may be a better way to do this, that's why
this is a proof of concept for now.

I'm not sure if there's a way to somehow access node and other changeset
attributes without actually adding them to this lambda function. But other
functions in templatekw module, like showparents, also use _hybrid() with a
similar makemap argument (a lambda that returns a dict with only ctx and
revcache), and if I do, for example

    hg log -T '{parents%"{node|short} {author} {date|isodate}"}'

it will show node, but also author and date, even though these attributes
aren't explicitly provided by anything in showparents().

But in hgweb, this is not enough, and there needs to be "node" in that dict,
otherwise the links wouldn't work. Any suggestions?

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -772,7 +772,7 @@ def showsuccsandmarkers(repo, ctx, **arg
 
         successors = [hex(n) for n in successors]
         successors = _hybrid(None, successors,
-                             lambda x: {'ctx': repo[x], 'revcache': {}},
+                             lambda x: {'ctx': repo[x], 'node': x, 'revcache': {}},
                              lambda x: scmutil.formatchangeid(repo[x]))
 
         # Format markers
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -271,7 +271,8 @@ branchtag = '<span class="branchtag" tit
 inbranchtag = '<span class="inbranchtag" title="{name|escape}">{name|escape}</span> '
 bookmarktag = '<span class="bookmarktag" title="{name|escape}">{name|escape}</span> '
 alltags = '<span class="logtags">{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a class="list" href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -229,7 +229,8 @@ branchtag = '<span class="branchtag" tit
 inbranchtag = '<span class="inbranchtag" title="{name|escape}">{name|escape}</span> '
 bookmarktag = '<span class="bookmarktag" title="{name|escape}">{name|escape}</span> '
 alltags = '<span class="logtags">{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%inbranchtag}{branches%branchtag}{tags%tagtag}{bookmarks%bookmarktag}</span>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -209,7 +209,8 @@ changelogbranchhead = '<span class="bran
 changelogbranchname = '<span class="branchname">{name|escape}</span> '
 alltags = '{phasetag}{obsoletetag}{instabilities%instabilitytag}{inbranch%changelogbranchname}{branches%changelogbranchhead}{tags%changelogtag}{bookmarks%changelogtag}'
 
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -166,7 +166,8 @@ branchentry = '
 diffblock = '<pre class="parity{parity}">{lines}</pre>'
 changelogtag = '<tr><th class="tag">tag:</th><td class="tag">{tag|escape}</td></tr>'
 changesettag = '<tr><th class="tag">tag:</th><td class="tag">{tag|escape}</td></tr>'
-obsfatesuccessors = '{if(successors, ' as ')}{join(successors, ', ')}'
+successorlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
+obsfatesuccessors = '{if(successors, ' as ')}{successors%successorlink}'
 obsfateverb = '{obsfateverb(successors, markers)}'
 obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
 obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1036,15 +1036,15 @@ check obsolete changeset
 
 check an obsolete changeset that has been rewritten
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=paper' | grep rewritten
-   <td>rewritten as 6:3de5eca88c00</td>
+   <td>rewritten as <a href="/rev/3de5eca88c00?style=paper">3de5eca88c00</a> </td>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=coal' | grep rewritten
-   <td>rewritten as 6:3de5eca88c00</td>
+   <td>rewritten as <a href="/rev/3de5eca88c00?style=coal">3de5eca88c00</a> </td>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=gitweb' | grep rewritten
-  <tr><td>obsolete</td><td>rewritten as 6:3de5eca88c00</td></tr>
+  <tr><td>obsolete</td><td>rewritten as <a class="list" href="/rev/3de5eca88c00?style=gitweb">3de5eca88c00</a> </td></tr>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=monoblue' | grep rewritten
-          <dt>obsolete</dt><dd>rewritten as 6:3de5eca88c00</dd>
+          <dt>obsolete</dt><dd>rewritten as <a href="/rev/3de5eca88c00?style=monoblue">3de5eca88c00</a> </dd>
   $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=spartan' | grep rewritten
-   <td class="obsolete">rewritten as 6:3de5eca88c00</td>
+   <td class="obsolete">rewritten as <a href="/rev/3de5eca88c00?style=spartan">3de5eca88c00</a> </td>
 
 check changeset with instabilities
 



More information about the Mercurial-devel mailing list