hgweb: show as same parents as "hg parents -r REV FILE" in pages for file
Before this patch, "parents" in pages for file doesn't show as same
parents as "hg parents -r REV FILE", when the specified file is not
modified in the specified revision.
For example, it is assumed that revision A, B and D change file "f".
changelog (A) ---> (B) ---> (C) ---> (D)
filelog "f" (x) ---> (y) ------------> (z)
"/file/D/f" invokes "webutil.parents()" with filectx(z) gotten from
changectx(D), and it returns changectx(B). This is as same result as
"hg parents -r D f".
In the other hand, "/file/C/f" invokes "webutil.parents()" with
filectx(y') gotten from changectx(C), and it returns changectx(A),
because filectx(y') is linked to changectx(B), and works like
filectx(y) in some cases.
In this case, revision B is hidden from users browsing file "f" in
revision C.
This patch shows as same parents as "hg parents -r REV FILE" in pages
for file, by making "webutil.parents()" return:
- "linkrev()"-ed revision only, if:
- specified context instance is "filectx" (because
"webutil.parents()" is invoked with changectx, too), and
- (1) the revision from which filectx is gotten and (2) the one to
which filectx is linked are different from each other
- revision gotten from "ctx.parents()", otherwise
--- a/mercurial/hgweb/webutil.py Thu Apr 17 09:36:08 2014 +0900
+++ b/mercurial/hgweb/webutil.py Thu Apr 17 09:36:08 2014 +0900
@@ -7,7 +7,7 @@
# GNU General Public License version 2 or any later version.
import os, copy
-from mercurial import match, patch, error, ui, util, pathutil
+from mercurial import match, patch, error, ui, util, pathutil, context
from mercurial.i18n import _
from mercurial.node import hex, nullid
from common import ErrorResponse
@@ -138,6 +138,9 @@
yield d
def parents(ctx, hide=None):
+ if (isinstance(ctx, context.basefilectx) and
+ ctx.changectx().rev() != ctx.linkrev()):
+ return _siblings([ctx._repo[ctx.linkrev()]], hide)
return _siblings(ctx.parents(), hide)
def children(ctx, hide=None):
--- a/tests/test-hgweb-commands.t Thu Apr 17 09:36:08 2014 +0900
+++ b/tests/test-hgweb-commands.t Thu Apr 17 09:36:08 2014 +0900
@@ -928,6 +928,13 @@
-rw-r--r-- 4 foo
+ $ hg log --template "{file_mods}\n" -r 1
+
+ $ hg parents --template "{node|short}\n" -r 1
+ 2ef0ac749a14
+ $ hg parents --template "{node|short}\n" -r 1 foo
+ 2ef0ac749a14
+
$ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'file/1/foo'
200 Script output follows
@@ -998,7 +1005,7 @@
</tr>
<tr>
<th class="author">parents</th>
- <td class="author"></td>
+ <td class="author"><a href="/file/2ef0ac749a14/foo">2ef0ac749a14</a> </td>
</tr>
<tr>
<th class="author">children</th>
@@ -1045,6 +1052,109 @@
+ $ hg log --template "{file_mods}\n" -r 2
+ foo
+ $ hg parents --template "{node|short}\n" -r 2
+ a4f92ed23982
+ $ hg parents --template "{node|short}\n" -r 2 foo
+ 2ef0ac749a14
+
+ $ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'file/2/foo'
+ 200 Script output follows
+
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
+ <head>
+ <link rel="icon" href="/static/hgicon.png" type="image/png" />
+ <meta name="robots" content="index, nofollow" />
+ <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
+ <script type="text/javascript" src="/static/mercurial.js"></script>
+
+ <title>test: 1d22e65f027e foo</title>
+ </head>
+ <body>
+
+ <div class="container">
+ <div class="menu">
+ <div class="logo">
+ <a href="http://mercurial.selenic.com/">
+ <img src="/static/hglogo.png" alt="mercurial" /></a>
+ </div>
+ <ul>
+ <li><a href="/shortlog/1d22e65f027e">log</a></li>
+ <li><a href="/graph/1d22e65f027e">graph</a></li>
+ <li><a href="/tags">tags</a></li>
+ <li><a href="/bookmarks">bookmarks</a></li>
+ <li><a href="/branches">branches</a></li>
+ </ul>
+ <ul>
+ <li><a href="/rev/1d22e65f027e">changeset</a></li>
+ <li><a href="/file/1d22e65f027e/">browse</a></li>
+ </ul>
+ <ul>
+ <li class="active">file</li>
+ <li><a href="/file/tip/foo">latest</a></li>
+ <li><a href="/diff/1d22e65f027e/foo">diff</a></li>
+ <li><a href="/comparison/1d22e65f027e/foo">comparison</a></li>
+ <li><a href="/annotate/1d22e65f027e/foo">annotate</a></li>
+ <li><a href="/log/1d22e65f027e/foo">file log</a></li>
+ <li><a href="/raw-file/1d22e65f027e/foo">raw</a></li>
+ </ul>
+ <ul>
+ <li><a href="/help">help</a></li>
+ </ul>
+ </div>
+
+ <div class="main">
+ <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2>
+ <h3>view foo @ 2:1d22e65f027e</h3>
+
+ <form class="search" action="/log">
+
+ <p><input name="rev" id="search1" type="text" size="30" /></p>
+ <div id="hint">Find changesets by keywords (author, files, the commit message), revision
+ number or hash, or <a href="/help/revsets">revset expression</a>.</div>
+ </form>
+
+ <div class="description">branch</div>
+
+ <table id="changesetEntry">
+ <tr>
+ <th class="author">author</th>
+ <td class="author">test</td>
+ </tr>
+ <tr>
+ <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="/file/2ef0ac749a14/foo">2ef0ac749a14</a> </td>
+ </tr>
+ <tr>
+ <th class="author">children</th>
+ <td class="author"></td>
+ </tr>
+ </table>
+
+ <div class="overflow">
+ <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
+ <div class="sourcefirst"> line source</div>
+ <pre class="sourcelines stripes4 wrap">
+ <span id="l1">another</span><a href="#l1"></a></pre>
+ <div class="sourcelast"></div>
+ </div>
+ </div>
+ </div>
+
+ <script type="text/javascript">process_dates()</script>
+
+
+ </body>
+ </html>
+
+
+
Overviews
$ "$TESTDIR/get-with-headers.py" 127.0.0.1:$HGPORT 'raw-tags'
--- a/tests/test-hgweb-diffs.t Thu Apr 17 09:36:08 2014 +0900
+++ b/tests/test-hgweb-diffs.t Thu Apr 17 09:36:08 2014 +0900
@@ -193,6 +193,14 @@
diff removed file
+ $ hg log --template "{file_mods}\n{file_dels}\n" -r tip
+ a
+ b
+ $ hg parents --template "{node|short}\n" -r tip
+ 0cd96de13884
+ $ hg parents --template "{node|short}\n" -r tip b
+ 0cd96de13884
+
$ "$TESTDIR/get-with-headers.py" localhost:$HGPORT 'diff/tip/b'
200 Script output follows
@@ -459,7 +467,15 @@
+b
-diff removed file
+diff modified file
+
+ $ hg log --template "{file_mods}\n{file_dels}\n" -r tip
+ a
+ b
+ $ hg parents --template "{node|short}\n" -r tip
+ 0cd96de13884
+ $ hg parents --template "{node|short}\n" -r tip a
+ 0cd96de13884
$ "$TESTDIR/get-with-headers.py" localhost:$HGPORT 'diff/tip/a'
200 Script output follows
@@ -531,7 +547,7 @@
</tr>
<tr>
<th>parents</th>
- <td></td>
+ <td><a href="/file/0cd96de13884/a">0cd96de13884</a> </td>
</tr>
<tr>
<th>children</th>
@@ -934,6 +950,10 @@
$ hg tip --template "{node|short}\n"
41d9fc4a6ae1
$ hg diff -c tip e
+ $ hg parents --template "{node|short}\n" -r tip
+ 402bea3b0976
+ $ hg parents --template "{node|short}\n" -r tip e
+ 402bea3b0976
$ "$TESTDIR/get-with-headers.py" localhost:$HGPORT 'comparison/tip/e'
200 Script output follows
@@ -1005,7 +1025,7 @@
</tr>
<tr>
<th>parents</th>
- <td></td>
+ <td><a href="/file/402bea3b0976/e">402bea3b0976</a> </td>
</tr>
<tr>
<th>children</th>