Patchwork [2,of,2,V2] hgweb: link to successors of obsoleted changesets

login
register
mail settings
Submitter Anton Shestakov
Date Dec. 22, 2017, 2:40 p.m.
Message ID <c2befc8a84ac898e1b45.1513953616@neuro>
Download mbox | patch
Permalink /patch/26400/
State Accepted
Headers show

Comments

Anton Shestakov - Dec. 22, 2017, 2:40 p.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1513949146 -28800
#      Fri Dec 22 21:25:46 2017 +0800
# Node ID c2befc8a84ac898e1b451b38ec6a6fe702966517
# Parent  d3211cd1ef5ed1f5a50d49af800155271ad3861e
# EXP-Topic hgweb-more-info
hgweb: link to successors of obsoleted changesets

_siblings() prepare various useful properties to use in templates. This
function usually prepares parents and children of changesets for use in hgweb
templates, but it can be used for successors too. It's needed because
item['successors'] is a _hybrid object that works well when used in regular
templates, but in hgweb templates work slightly differently and can't get hex
nodes of the successors, which are required for these links to work.
Yuya Nishihara - Dec. 23, 2017, 1:43 a.m.
On Fri, 22 Dec 2017 22:40:16 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1513949146 -28800
> #      Fri Dec 22 21:25:46 2017 +0800
> # Node ID c2befc8a84ac898e1b451b38ec6a6fe702966517
> # Parent  d3211cd1ef5ed1f5a50d49af800155271ad3861e
> # EXP-Topic hgweb-more-info
> hgweb: link to successors of obsoleted changesets
> 
> _siblings() prepare various useful properties to use in templates. This
> function usually prepares parents and children of changesets for use in hgweb
> templates, but it can be used for successors too. It's needed because
> item['successors'] is a _hybrid object that works well when used in regular
> templates, but in hgweb templates work slightly differently and can't get hex
> nodes of the successors, which are required for these links to work.

Queued, thanks. Let's revisit it later to build a real webtemplatekw.py
module. The current web template is too ad-hoc and has problems like some
generator keywords can be consumed only once.

Patch

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -353,7 +353,10 @@  def formatlinerange(fromline, toline):
     return '%d:%d' % (fromline + 1, toline)
 
 def succsandmarkers(repo, ctx):
-    return templatekw.showsuccsandmarkers(repo, ctx)
+    for item in templatekw.showsuccsandmarkers(repo, ctx):
+        item['successors'] = _siblings(repo[successor]
+                                       for successor in item['successors'])
+        yield item
 
 def commonentry(repo, ctx):
     node = ctx.node()
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