hgweb: display fate of obsolete changesets
authorAnton Shestakov <av6@dwimlabs.net>
Tue, 21 Nov 2017 17:03:41 +0800
changeset 35485 1721ce06100a
parent 35484 1853c8677160
child 35486 4c7ae95e1c71
hgweb: display fate of obsolete changesets Operations that obsolete changesets store enough metadata to explain what happened after the fact. One way to get that metadata is showsuccsandmarkers function, which returns a list of successors of a particular changeset and appropriate obsolescence markers. Templates have a set of experimental functions that have names starting with obsfate. This patch uses some of these functions to interpret output of succsandmarkers() and produce human-friendly messages that describe what happened to an obsolete changeset, e.g. "pruned" or "rewritten as 6:3de5eca88c00". In commonentry(), succsandmarkers property is made callable so it's only executed on demand; this saves time when changeset is not obsolete, and also in e.g. /shortlog view, where there are a lot of changesets, but we don't need to show each and every one in detail. In spartan theme, succsandmarkers is used instead of the simple "obsolete: yes", in other themes a new line is added to /rev page.
mercurial/hgweb/webutil.py
mercurial/templates/gitweb/changeset.tmpl
mercurial/templates/gitweb/map
mercurial/templates/monoblue/changeset.tmpl
mercurial/templates/monoblue/map
mercurial/templates/paper/changeset.tmpl
mercurial/templates/paper/map
mercurial/templates/spartan/changelogentry.tmpl
mercurial/templates/spartan/changeset.tmpl
mercurial/templates/spartan/map
tests/test-hgweb-commands.t
tests/test-hgweb-diffs.t
tests/test-hgweb-removed.t
tests/test-obsolete.t
--- a/mercurial/hgweb/webutil.py	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/hgweb/webutil.py	Tue Nov 21 17:03:41 2017 +0800
@@ -32,6 +32,7 @@
     pathutil,
     pycompat,
     templatefilters,
+    templatekw,
     ui as uimod,
     util,
 )
@@ -351,6 +352,9 @@
 def formatlinerange(fromline, toline):
     return '%d:%d' % (fromline + 1, toline)
 
+def succsandmarkers(repo, ctx):
+    return templatekw.showsuccsandmarkers(repo, ctx)
+
 def commonentry(repo, ctx):
     node = ctx.node()
     return {
@@ -362,6 +366,7 @@
         'extra': ctx.extra(),
         'phase': ctx.phasestr(),
         'obsolete': ctx.obsolete(),
+        'succsandmarkers': lambda **x: succsandmarkers(repo, ctx),
         'instabilities': [{"instability": i} for i in ctx.instabilities()],
         'branch': nodebranchnodefault(ctx),
         'inbranch': nodeinbranch(repo, ctx),
--- a/mercurial/templates/gitweb/changeset.tmpl	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/gitweb/changeset.tmpl	Tue Nov 21 17:03:41 2017 +0800
@@ -44,6 +44,7 @@
  <td>changeset {rev}</td>
  <td style="font-family:monospace"><a class="list" href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></td>
 </tr>
+{if(obsolete, '<tr><td>obsolete</td><td>{succsandmarkers%obsfateentry}</td></tr>')}
 {ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
 {child%changesetchild}
 </table></div>
--- a/mercurial/templates/gitweb/map	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/gitweb/map	Tue Nov 21 17:03:41 2017 +0800
@@ -271,6 +271,10 @@
 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, ', ')}'
+obsfateverb = '{obsfateverb(successors, markers)}'
+obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
+obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
 shortlogentry = '
   <tr class="parity{parity}">
     <td class="age"><i class="age">{date|rfc822date}</i></td>
--- a/mercurial/templates/monoblue/changeset.tmpl	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/monoblue/changeset.tmpl	Tue Nov 21 17:03:41 2017 +0800
@@ -48,6 +48,7 @@
         {branch%changesetbranch}
         <dt>changeset {rev}</dt>
         <dd><a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></dd>
+        {if(obsolete, '<dt>obsolete</dt><dd>{succsandmarkers%obsfateentry}</dd>')}
         {ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
         {child%changesetchild}
     </dl>
--- a/mercurial/templates/monoblue/map	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/monoblue/map	Tue Nov 21 17:03:41 2017 +0800
@@ -229,6 +229,10 @@
 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, ', ')}'
+obsfateverb = '{obsfateverb(successors, markers)}'
+obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
+obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
 shortlogentry = '
   <tr class="parity{parity}">
     <td class="nowrap age">{date|rfc822date}</td>
--- a/mercurial/templates/paper/changeset.tmpl	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/paper/changeset.tmpl	Tue Nov 21 17:03:41 2017 +0800
@@ -49,6 +49,10 @@
  <th class="date">date</th>
  <td class="date age">{date|rfc822date}</td>
 </tr>
+{if(obsolete, '<tr>
+ <th>obsolete</th>
+ <td>{succsandmarkers%obsfateentry}</td>
+</tr>')}
 <tr>
  <th class="author">parents</th>
  <td class="author">{ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}</td>
--- a/mercurial/templates/paper/map	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/paper/map	Tue Nov 21 17:03:41 2017 +0800
@@ -209,6 +209,11 @@
 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, ', ')}'
+obsfateverb = '{obsfateverb(successors, markers)}'
+obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
+obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
+
 filediffparent = '
   <tr>
     <th class="parent">parent {rev}:</th>
--- a/mercurial/templates/spartan/changelogentry.tmpl	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/spartan/changelogentry.tmpl	Tue Nov 21 17:03:41 2017 +0800
@@ -24,7 +24,7 @@
  </tr>')}
  {if(obsolete, '<tr>
   <th class="obsolete">obsolete:</th>
-  <td class="obsolete">yes</td>
+  <td class="obsolete">{succsandmarkers%obsfateentry}</td>
  </tr>')}
  {ifeq(count(instabilities), '0', '', '<tr>
   <th class="instabilities">instabilities:</th>
--- a/mercurial/templates/spartan/changeset.tmpl	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/spartan/changeset.tmpl	Tue Nov 21 17:03:41 2017 +0800
@@ -39,7 +39,7 @@
 </tr>')}
 {if(obsolete, '<tr>
  <th class="obsolete">obsolete:</th>
- <td class="obsolete">yes</td>
+ <td class="obsolete">{succsandmarkers%obsfateentry}</td>
 </tr>')}
 {ifeq(count(instabilities), '0', '', '<tr>
  <th class="instabilities">instabilities:</th>
--- a/mercurial/templates/spartan/map	Sat Dec 16 18:58:02 2017 -0500
+++ b/mercurial/templates/spartan/map	Tue Nov 21 17:03:41 2017 +0800
@@ -166,6 +166,10 @@
 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, ', ')}'
+obsfateverb = '{obsfateverb(successors, markers)}'
+obsfateoperations = '{if(obsfateoperations(markers), ' using {join(obsfateoperations(markers), ', ')}')}'
+obsfateentry = '{obsfateverb}{obsfateoperations}{obsfatesuccessors}'
 filediffparent = '
   <tr>
     <th class="parent">parent {rev}:</th>
--- a/tests/test-hgweb-commands.t	Sat Dec 16 18:58:02 2017 -0500
+++ b/tests/test-hgweb-commands.t	Tue Nov 21 17:03:41 2017 +0800
@@ -902,6 +902,7 @@
    <th class="date">date</th>
    <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td>
   </tr>
+  
   <tr>
    <th class="author">parents</th>
    <td class="author"></td>
--- a/tests/test-hgweb-diffs.t	Sat Dec 16 18:58:02 2017 -0500
+++ b/tests/test-hgweb-diffs.t	Tue Nov 21 17:03:41 2017 +0800
@@ -103,6 +103,7 @@
    <th class="date">date</th>
    <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td>
   </tr>
+  
   <tr>
    <th class="author">parents</th>
    <td class="author"></td>
@@ -398,6 +399,7 @@
    <th class="date">date</th>
    <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td>
   </tr>
+  
   <tr>
    <th class="author">parents</th>
    <td class="author"></td>
--- a/tests/test-hgweb-removed.t	Sat Dec 16 18:58:02 2017 -0500
+++ b/tests/test-hgweb-removed.t	Tue Nov 21 17:03:41 2017 +0800
@@ -84,6 +84,7 @@
    <th class="date">date</th>
    <td class="date age">Thu, 01 Jan 1970 00:00:00 +0000</td>
   </tr>
+  
   <tr>
    <th class="author">parents</th>
    <td class="author"><a href="/rev/cb9a9f314b8b">cb9a9f314b8b</a> </td>
--- a/tests/test-obsolete.t	Sat Dec 16 18:58:02 2017 -0500
+++ b/tests/test-obsolete.t	Tue Nov 21 17:03:41 2017 +0800
@@ -1032,7 +1032,19 @@
           <span class="logtags"><span class="phasetag" title="draft">draft</span> <span class="obsoletetag" title="obsolete">obsolete</span> </span>
   $ get-with-headers.py localhost:$HGPORT 'log?rev=first(obsolete())&style=spartan' | grep 'class="obsolete"'
     <th class="obsolete">obsolete:</th>
-    <td class="obsolete">yes</td>
+    <td class="obsolete">pruned</td>
+
+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>
+  $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=coal' | grep rewritten
+   <td>rewritten as 6:3de5eca88c00</td>
+  $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=gitweb' | grep rewritten
+  <tr><td>obsolete</td><td>rewritten as 6:3de5eca88c00</td></tr>
+  $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=monoblue' | grep rewritten
+          <dt>obsolete</dt><dd>rewritten as 6:3de5eca88c00</dd>
+  $ get-with-headers.py localhost:$HGPORT 'rev/cda648ca50f5?style=spartan' | grep rewritten
+   <td class="obsolete">rewritten as 6:3de5eca88c00</td>
 
 check changeset with instabilities