[PATCH] hgweb: allow viewing diffs against p1 or p2 for merge commits (issue3904)

Anton Shestakov engored at ya.ru
Sat Jan 3 10:31:00 UTC 2015


# HG changeset patch
# User Anton Shestakov <engored at ya.ru>
# Date 1420278621 -28800
#      Sat Jan 03 17:50:21 2015 +0800
# Node ID ca41678f298a9ce7a842cd1c08b5f8b9905c6165
# Parent  42908c3275c63b7d2d6c871094c1e2c8f7ba31c8
hgweb: allow viewing diffs against p1 or p2 for merge commits (issue3904)

This adds UI portion of the feature that has resided in mercurial since 2012.
Back then the interface was added together with the code, but was shortly
backed out because it was deemed "not ready". Code, however, stayed.

For the original feature and its implementation, see issue2810 and
d605a82cf189.

In short, the backed-out interface had two outstanding issues:
1. it was introducing an entirely new term (baseline) and
2. it was present on every changeset's page, even for changesets with 1 parent
   (or no parents), which didn't make sense

This patch implements a hopefully better interface because:
1. it uses the usual terms (diff) and
2. it only shows up when there actually are 2 parents.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -379,7 +379,7 @@ def changeset(web, req, tmpl):
                 diff=diffs,
                 rev=ctx.rev(),
                 node=ctx.hex(),
-                parent=webutil.parents(ctx),
+                parent=tuple(webutil.parents(ctx)),
                 child=webutil.children(ctx),
                 basenode=basectx.hex(),
                 changesettag=showtags,
diff --git a/mercurial/templates/coal/map b/mercurial/templates/coal/map
--- a/mercurial/templates/coal/map
+++ b/mercurial/templates/coal/map
@@ -109,6 +109,12 @@ changelogparent = '
 
 changesetparent = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
 
+changesetparentdiff = '
+  {changesetparent}
+  {ifeq(node, basenode, '(current diff)', '({difffrom})')}'
+
+difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">diff</a>'
+
 filerevparent = '<a href="{url|urlescape}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{rename%filerename}{node|short}</a> '
 filerevchild = '<a href="{url|urlescape}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{node|short}</a> '
 
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
@@ -36,7 +36,7 @@ changeset |
 <tr><td></td><td class="date age">{date|rfc822date}</td></tr>
 {branch%changesetbranch}
 <tr><td>changeset {rev}</td><td style="font-family:monospace">{node|short}</td></tr>
-{parent%changesetparent}
+{ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
 {child%changesetchild}
 </table></div>
 
diff --git a/mercurial/templates/gitweb/map b/mercurial/templates/gitweb/map
--- a/mercurial/templates/gitweb/map
+++ b/mercurial/templates/gitweb/map
@@ -127,14 +127,23 @@ changelogparent = '
       <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
     </td>
   </tr>'
+changesetlink = '<a class="list" href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>'
 changesetbranch = '<tr><td>branch</td><td>{name|escape}</td></tr>'
 changesetparent = '
   <tr>
     <td>parent {rev}</td>
     <td style="font-family:monospace">
-      <a class="list" href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
+      {changesetlink}
     </td>
   </tr>'
+changesetparentdiff = '
+  <tr>
+    <td>parent {rev}</td>
+    <td style="font-family:monospace">
+      {changesetlink} {ifeq(node, basenode, '(current diff)', \'({difffrom})\')}
+    </td>
+  </tr>'
+difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">diff</a>'
 filerevbranch = '<tr><td>branch</td><td>{name|escape}</td></tr>'
 filerevparent = '
   <tr>
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,7 +48,7 @@
         {branch%changesetbranch}
         <dt>changeset {rev}</dt>
         <dd>{node|short}</dd>
-        {parent%changesetparent}
+        {ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
         {child%changesetchild}
     </dl>
 
diff --git a/mercurial/templates/monoblue/map b/mercurial/templates/monoblue/map
--- a/mercurial/templates/monoblue/map
+++ b/mercurial/templates/monoblue/map
@@ -115,17 +115,22 @@ comparisonline = '
     <td class="source {type}"><a class="linenr" href="#{lineid}" id="{lineid}">{rightlinenumber}</a> {rightline|escape}</td>
   </tr>'
 
+changesetlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>'
 changelogparent = '
   <tr>
     <th class="parent">parent {rev}:</th>
     <td class="parent">
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
+      {changesetlink}
     </td>
   </tr>'
 changesetbranch = '<dt>branch</dt><dd>{name|escape}</dd>'
 changesetparent = '
   <dt>parent {rev}</dt>
-  <dd><a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></dd>'
+  <dd>{changesetlink}</dd>'
+changesetparentdiff = '
+  <dt>parent {rev}</dt>
+  <dd>{changesetlink} {ifeq(node, basenode, '(current diff)', \'({difffrom})\')}</dd>'
+difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">diff</a>'
 filerevbranch = '<dt>branch</dt><dd>{name|escape}</dd>'
 filerevparent = '
   <dt>parent {rev}</dt>
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
@@ -51,7 +51,7 @@
  <td class="date age">{date|rfc822date}</td></tr>
 <tr>
  <th class="author">parents</th>
- <td class="author">{parent%changesetparent}</td>
+ <td class="author">{ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}</td>
 </tr>
 <tr>
  <th class="author">children</th>
diff --git a/mercurial/templates/paper/map b/mercurial/templates/paper/map
--- a/mercurial/templates/paper/map
+++ b/mercurial/templates/paper/map
@@ -112,7 +112,11 @@ changelogparent = '
 
 changesetparent = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a> '
 
-difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">{node|short}</a> '
+changesetparentdiff = '
+  {changesetparent}
+  {ifeq(node, basenode, '(current diff)', '({difffrom})')}'
+
+difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">diff</a>'
 
 filerevparent = '<a href="{url|urlescape}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{rename%filerename}{node|short}</a> '
 filerevchild = '<a href="{url|urlescape}file/{node|short}/{file|urlescape}{sessionvars%urlparameter}">{node|short}</a> '
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
@@ -22,7 +22,7 @@
  <th class="changeset">changeset {rev}:</th>
  <td class="changeset"><a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></td>
 </tr>
-{parent%changesetparent}
+{ifeq(count(parent), '2', parent%changesetparentdiff, parent%changesetparent)}
 {child%changesetchild}
 {changesettag}
 <tr>
diff --git a/mercurial/templates/spartan/map b/mercurial/templates/spartan/map
--- a/mercurial/templates/spartan/map
+++ b/mercurial/templates/spartan/map
@@ -68,18 +68,25 @@ difflineplus = '<span class="plusline"><
 difflineminus = '<span class="minusline"><a class="lineno" href="#{lineid}" id="{lineid}">{linenumber}</a>{line|escape}</span>'
 difflineat = '<span class="atline"><a class="lineno" href="#{lineid}" id="{lineid}">{linenumber}</a>{line|escape}</span>'
 diffline = '<a class="lineno" href="#{lineid}" id="{lineid}">{linenumber}</a>{line|escape}'
+changesetlink = '<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>'
 changelogparent = '
   <tr>
     <th class="parent">parent {rev}:</th>
     <td class="parent">
-      <a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
+      {changesetlink}
     </td>
   </tr>'
 changesetparent = '
   <tr>
     <th class="parent">parent {rev}:</th>
-    <td class="parent"><a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a></td>
+    <td class="parent">{changesetlink}</td>
   </tr>'
+changesetparentdiff = '
+  <tr>
+    <th class="parent">parent {rev}:</th>
+    <td class="parent">{changesetlink} {ifeq(node, basenode, '(current diff)', '({difffrom})')}</td>
+  </tr>'
+difffrom = '<a href="{url|urlescape}rev/{node|short}:{originalnode|short}{sessionvars%urlparameter}">diff</a>'
 filerevparent = '
   <tr>
     <td class="metatag">parent:</td>


More information about the Mercurial-devel mailing list