webcommands: get correct parents when comparing a removed file (issue4962)
authorAnton Shestakov <av6@dwimlabs.net>
Sat, 28 Nov 2015 16:02:22 +0800
changeset 27158 522ffc189671
parent 27157 5f2e4eb08e41
child 27159 7e10b860c174
webcommands: get correct parents when comparing a removed file (issue4962) When comparing a file that was removed at the current revision, parents used to show grandparents instead, due to how fctx was "shifted" from the current revision to its p1. Let's not do that. The fix is pretty much copied from webcommands.filediff().
mercurial/hgweb/webcommands.py
tests/test-hgweb-diffs.t
--- a/mercurial/hgweb/webcommands.py	Mon Nov 30 16:38:29 2015 -0800
+++ b/mercurial/hgweb/webcommands.py	Sat Nov 28 16:02:22 2015 +0800
@@ -854,6 +854,7 @@
             return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
         return f.data().splitlines()
 
+    fctx = None
     parent = ctx.p1()
     leftrev = parent.rev()
     leftnode = parent.node()
@@ -869,10 +870,14 @@
             leftlines = filelines(pfctx)
     else:
         rightlines = ()
-        fctx = ctx.parents()[0][path]
-        leftlines = filelines(fctx)
+        pfctx = ctx.parents()[0][path]
+        leftlines = filelines(pfctx)
 
     comparison = webutil.compare(tmpl, context, leftlines, rightlines)
+    if fctx is not None:
+        ctx = fctx
+    else:
+        ctx = ctx
     return tmpl('filecomparison',
                 file=path,
                 node=hex(ctx.node()),
@@ -884,8 +889,8 @@
                 author=ctx.user(),
                 rename=rename,
                 branch=webutil.nodebranchnodefault(ctx),
-                parent=webutil.parents(fctx),
-                child=webutil.children(fctx),
+                parent=webutil.parents(ctx),
+                child=webutil.children(ctx),
                 tags=webutil.nodetagsdict(web.repo, ctx.node()),
                 bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()),
                 leftrev=leftrev,
--- a/tests/test-hgweb-diffs.t	Mon Nov 30 16:38:29 2015 -0800
+++ b/tests/test-hgweb-diffs.t	Sat Nov 28 16:02:22 2015 +0800
@@ -927,7 +927,7 @@
   </tr>
   <tr>
    <th>parents</th>
-   <td><a href="/file/0cd96de13884/a">0cd96de13884</a> </td>
+   <td><a href="/file/d73db4d812ff/a">d73db4d812ff</a> </td>
   </tr>
   <tr>
    <th>children</th>