Patchwork [3,of,5] log: fill in pseudo rev and node as wdir() manifest identifiers

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 23, 2018, 1:28 p.m.
Message ID <0027f3043539df28672a.1537709299@mimosa>
Download mbox | patch
Permalink /patch/34953/
State New
Headers show

Comments

Yuya Nishihara - Sept. 23, 2018, 1:28 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1536999981 -32400
#      Sat Sep 15 17:26:21 2018 +0900
# Node ID 0027f3043539df28672a15c7579393150ae8ff6e
# Parent  9902b9afed7e73e5e84415d424014d27bc8f7c66
log: fill in pseudo rev and node as wdir() manifest identifiers

While we'll never support such identifiers to look up the manifest,
this behavior seems more consistent.

Patch

diff --git a/mercurial/logcmdutil.py b/mercurial/logcmdutil.py
--- a/mercurial/logcmdutil.py
+++ b/mercurial/logcmdutil.py
@@ -13,6 +13,8 @@  import os
 from .i18n import _
 from .node import (
     nullid,
+    wdirid,
+    wdirrev,
 )
 
 from . import (
@@ -191,7 +193,6 @@  class changesetprinter(object):
     def _show(self, ctx, copies, props):
         '''show a single changeset or file revision'''
         changenode = ctx.node()
-        rev = ctx.rev()
 
         if self.ui.quiet:
             self.ui.write("%s\n" % scmutil.formatchangeid(ctx),
@@ -226,9 +227,13 @@  class changesetprinter(object):
             self.ui.write(columns['parent'] % scmutil.formatchangeid(pctx),
                           label=label)
 
-        if self.ui.debugflag and rev is not None:
+        if self.ui.debugflag:
             mnode = ctx.manifestnode()
-            mrev = self.repo.manifestlog.rev(mnode)
+            if mnode is None:
+                mnode = wdirid
+                mrev = wdirrev
+            else:
+                mrev = self.repo.manifestlog.rev(mnode)
             self.ui.write(columns['manifest']
                           % scmutil.formatrevnode(self.ui, mrev, mnode),
                           label='ui.debug log.manifest')
@@ -343,11 +348,7 @@  class changesetformatter(changesetprinte
                                        for c in ctx.parents()], name='node'))
 
         if self.ui.debugflag:
-            if ctx.rev() is None:
-                hexnode = None
-            else:
-                hexnode = fm.hexfunc(ctx.manifestnode())
-            fm.data(manifest=hexnode,
+            fm.data(manifest=fm.hexfunc(ctx.manifestnode() or wdirid),
                     extra=fm.formatdict(ctx.extra()))
 
             files = ctx.p1().status(ctx)
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -11,6 +11,8 @@  from .i18n import _
 from .node import (
     hex,
     nullid,
+    wdirid,
+    wdirrev,
 )
 
 from . import (
@@ -475,9 +477,10 @@  def showmanifest(context, mapping):
     ctx = context.resource(mapping, 'ctx')
     mnode = ctx.manifestnode()
     if mnode is None:
-        # just avoid crash, we might want to use the 'ff...' hash in future
-        return
-    mrev = repo.manifestlog.rev(mnode)
+        mnode = wdirid
+        mrev = wdirrev
+    else:
+        mrev = repo.manifestlog.rev(mnode)
     mhex = hex(mnode)
     mapping = context.overlaymap(mapping, {'rev': mrev, 'node': mhex})
     f = context.process('manifest', mapping)
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -2126,6 +2126,7 @@  clean:
   phase:       draft
   parent:      0:65624cd9070a035fa7191a54f2b8af39f16b0c08
   parent:      -1:0000000000000000000000000000000000000000
+  manifest:    2147483647:ffffffffffffffffffffffffffffffffffffffff
   user:        test
   date:        [A-Za-z0-9:+ ]+ (re)
   extra:       branch=default
@@ -2164,6 +2165,7 @@  dirty:
   phase:       draft
   parent:      0:65624cd9070a035fa7191a54f2b8af39f16b0c08
   parent:      -1:0000000000000000000000000000000000000000
+  manifest:    2147483647:ffffffffffffffffffffffffffffffffffffffff
   user:        test
   date:        [A-Za-z0-9:+ ]+ (re)
   files:       d1/f1
@@ -2234,7 +2236,7 @@  dirty:
     "date": [*, 0], (glob)
     "desc": "",
     "extra": {"branch": "default"},
-    "manifest": null,
+    "manifest": "ffffffffffffffffffffffffffffffffffffffff",
     "modified": ["d1/f1"],
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"],
diff --git a/tests/test-template-keywords.t b/tests/test-template-keywords.t
--- a/tests/test-template-keywords.t
+++ b/tests/test-template-keywords.t
@@ -61,7 +61,7 @@  experimental:
     "date": [0, 0],
     "desc": "",
     "extra": {"branch": "default"},
-    "manifest": null,
+    "manifest": "ffffffffffffffffffffffffffffffffffffffff",
     "modified": [],
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["95c24699272ef57d062b8bccc32c878bf841784a"],
@@ -73,11 +73,8 @@  experimental:
    }
   ]
 
-Some keywords are invalid for working-directory revision, but they should
-never cause crash:
-
   $ hg log -r 'wdir()' -T '{manifest}\n'
-  
+  2147483647:ffffffffffff
 
 Changectx-derived keywords are disabled within {manifest} as {node} changes: