log: fill in pseudo rev and node as wdir() manifest identifiers
authorYuya Nishihara <yuya@tcha.org>
Sat, 15 Sep 2018 17:26:21 +0900
changeset 39796 94ca3579e84e
parent 39795 ba93db1745ba
child 39797 a677261e7422
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.
mercurial/logcmdutil.py
mercurial/templatekw.py
tests/test-log.t
tests/test-template-keywords.t
--- a/mercurial/logcmdutil.py	Sat Sep 15 17:26:20 2018 +0900
+++ b/mercurial/logcmdutil.py	Sat Sep 15 17:26:21 2018 +0900
@@ -13,6 +13,8 @@
 from .i18n import _
 from .node import (
     nullid,
+    wdirid,
+    wdirrev,
 )
 
 from . import (
@@ -191,7 +193,6 @@
     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 @@
             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 @@
                                        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)
--- a/mercurial/templatekw.py	Sat Sep 15 17:26:20 2018 +0900
+++ b/mercurial/templatekw.py	Sat Sep 15 17:26:21 2018 +0900
@@ -11,6 +11,8 @@
 from .node import (
     hex,
     nullid,
+    wdirid,
+    wdirrev,
 )
 
 from . import (
@@ -475,9 +477,10 @@
     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)
--- a/tests/test-log.t	Sat Sep 15 17:26:20 2018 +0900
+++ b/tests/test-log.t	Sat Sep 15 17:26:21 2018 +0900
@@ -2126,6 +2126,7 @@
   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 @@
   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 @@
     "date": [*, 0], (glob)
     "desc": "",
     "extra": {"branch": "default"},
-    "manifest": null,
+    "manifest": "ffffffffffffffffffffffffffffffffffffffff",
     "modified": ["d1/f1"],
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"],
--- a/tests/test-template-keywords.t	Sat Sep 15 17:26:20 2018 +0900
+++ b/tests/test-template-keywords.t	Sat Sep 15 17:26:21 2018 +0900
@@ -61,7 +61,7 @@
     "date": [0, 0],
     "desc": "",
     "extra": {"branch": "default"},
-    "manifest": null,
+    "manifest": "ffffffffffffffffffffffffffffffffffffffff",
     "modified": [],
     "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["95c24699272ef57d062b8bccc32c878bf841784a"],
@@ -73,11 +73,8 @@
    }
   ]
 
-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: