[PATCH] hgweb: display fate of obsolete changesets

Anton Shestakov av6 at dwimlabs.net
Tue Nov 21 05:14:42 EST 2017


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1511255021 -28800
#      Tue Nov 21 17:03:41 2017 +0800
# Node ID f8e398c42760482f02e6cfb6b8a1e6a752564c95
# Parent  ff80efc8f3e469c90376603af4fa39012f328918
# EXP-Topic hgweb-more-info
hgweb: display fate of obsolete changesets

Non-hgweb templates have a set of experimental functions that have names
starting with obsfate. Combined, they can be used to show why a particular
changeset is obsolete, e.g.  "pruned" or "rewritten as 5:6e06e39c31df". This
patch reuses some of that code to produce a list of strings that describe what
happened to an obsolete changeset.

In commonentry(), "obsfate" 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, obsfate is used instead of the simple "obsolete: yes", in
other themes a new line is added to /rev page.

diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -28,10 +28,12 @@ from .. import (
     error,
     match,
     mdiff,
+    obsutil,
     patch,
     pathutil,
     pycompat,
     templatefilters,
+    templatekw,
     ui as uimod,
     util,
 )
@@ -351,6 +353,10 @@ def linerange(req):
 def formatlinerange(fromline, toline):
     return '%d:%d' % (fromline + 1, toline)
 
+def obsfate(repo, ctx, ui):
+    return [obsutil.obsfateprinter(x['successors'], x['markers'], ui)
+            for x in templatekw.showsuccsandmarkers(repo, ctx)]
+
 def commonentry(repo, ctx):
     node = ctx.node()
     return {
@@ -362,6 +368,7 @@ def commonentry(repo, ctx):
         'extra': ctx.extra(),
         'phase': ctx.phasestr(),
         'obsolete': ctx.obsolete(),
+        'obsfate': lambda **x: obsfate(repo, ctx, repo.ui),
         'instabilities': [{"name": i} for i in ctx.instabilities()],
         'branch': nodebranchnodefault(ctx),
         'inbranch': nodeinbranch(repo, ctx),
diff --git a/mercurial/templates/gitweb/changeset.tmpl b/mercurial/templates/gitweb/changeset.tmpl
--- a/mercurial/templates/gitweb/changeset.tmpl
+++ b/mercurial/templates/gitweb/changeset.tmpl
@@ -44,6 +44,7 @@ changeset |
  <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>{join(obsfate, '; ')|escape}</td></tr>')}
 {ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
 {child%changesetchild}
 </table></div>
diff --git a/mercurial/templates/monoblue/changeset.tmpl b/mercurial/templates/monoblue/changeset.tmpl
--- a/mercurial/templates/monoblue/changeset.tmpl
+++ b/mercurial/templates/monoblue/changeset.tmpl
@@ -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>{join(obsfate, '; ')|escape}</dd>')}
         {ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
         {child%changesetchild}
     </dl>
diff --git a/mercurial/templates/paper/changeset.tmpl b/mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl
+++ b/mercurial/templates/paper/changeset.tmpl
@@ -49,6 +49,10 @@
  <th class="date">date</th>
  <td class="date age">{date|rfc822date}</td>
 </tr>
+{if(obsolete, '<tr>
+ <th>obsolete</th>
+ <td>{join(obsfate, '; ')|escape}</td>
+</tr>')}
 <tr>
  <th class="author">parents</th>
  <td class="author">{ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}</td>
diff --git a/mercurial/templates/spartan/changelogentry.tmpl b/mercurial/templates/spartan/changelogentry.tmpl
--- a/mercurial/templates/spartan/changelogentry.tmpl
+++ b/mercurial/templates/spartan/changelogentry.tmpl
@@ -24,7 +24,7 @@
  </tr>')}
  {if(obsolete, '<tr>
   <th class="obsolete">obsolete:</th>
-  <td class="obsolete">yes</td>
+  <td class="obsolete">{join(obsfate, '; ')|escape}</td>
  </tr>')}
  {ifeq(count(instabilities), '0', '', '<tr>
   <th class="instabilities">instabilities:</th>
diff --git a/mercurial/templates/spartan/changeset.tmpl b/mercurial/templates/spartan/changeset.tmpl
--- a/mercurial/templates/spartan/changeset.tmpl
+++ b/mercurial/templates/spartan/changeset.tmpl
@@ -39,7 +39,7 @@
 </tr>')}
 {if(obsolete, '<tr>
  <th class="obsolete">obsolete:</th>
- <td class="obsolete">yes</td>
+ <td class="obsolete">{join(obsfate, '; ')|escape}</td>
 </tr>')}
 {ifeq(count(instabilities), '0', '', '<tr>
  <th class="instabilities">instabilities:</th>
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -902,6 +902,7 @@ Logs and changes
    <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>
diff --git a/tests/test-hgweb-diffs.t b/tests/test-hgweb-diffs.t
--- a/tests/test-hgweb-diffs.t
+++ b/tests/test-hgweb-diffs.t
@@ -103,6 +103,7 @@ revision
    <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>
@@ -381,6 +382,7 @@ revision
    <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>
diff --git a/tests/test-hgweb-removed.t b/tests/test-hgweb-removed.t
--- a/tests/test-hgweb-removed.t
+++ b/tests/test-hgweb-removed.t
@@ -84,6 +84,7 @@ revision
    <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>
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1032,7 +1032,7 @@ check obsolete changeset
           <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 changeset with instabilities
 


More information about the Mercurial-devel mailing list