changeset 39811:ba93db1745ba

log: have changesetformatter fill in wdir() rev and node (BC) This matches the behavior of the default template keywords. wdir() support is still experimental so we can change the output.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Sep 2018 17:26:20 +0900
parents 4f44f747f094
children 94ca3579e84e
files mercurial/logcmdutil.py tests/test-log.t tests/test-template-keywords.t
diffstat 3 files changed, 30 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/logcmdutil.py	Sun Sep 23 16:11:01 2018 +0900
+++ b/mercurial/logcmdutil.py	Sat Sep 15 17:26:20 2018 +0900
@@ -325,16 +325,9 @@
         '''show a single changeset or file revision'''
         fm = self._fm
         fm.startitem()
-
         fm.context(ctx=ctx)
-        # TODO: maybe this should be wdirrev/wdirnode?
-        rev = ctx.rev()
-        if rev is None:
-            hexnode = None
-        else:
-            hexnode = fm.hexfunc(ctx.node())
-        fm.data(rev=rev,
-                node=hexnode)
+        fm.data(rev=scmutil.intrev(ctx),
+                node=fm.hexfunc(scmutil.binnode(ctx)))
 
         if self.ui.quiet:
             return
@@ -350,7 +343,7 @@
                                        for c in ctx.parents()], name='node'))
 
         if self.ui.debugflag:
-            if rev is None:
+            if ctx.rev() is None:
                 hexnode = None
             else:
                 hexnode = fm.hexfunc(ctx.manifestnode())
--- a/tests/test-log.t	Sun Sep 23 16:11:01 2018 +0900
+++ b/tests/test-log.t	Sat Sep 15 17:26:20 2018 +0900
@@ -2208,10 +2208,10 @@
     "branch": "default",
     "date": [*, 0], (glob)
     "desc": "",
-    "node": null,
+    "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"],
     "phase": "draft",
-    "rev": null,
+    "rev": 2147483647,
     "tags": [],
     "user": "test"
    }
@@ -2220,8 +2220,8 @@
   $ hg log -r 'wdir()' -Tjson -q
   [
    {
-    "node": null,
-    "rev": null
+    "node": "ffffffffffffffffffffffffffffffffffffffff",
+    "rev": 2147483647
    }
   ]
 
@@ -2236,11 +2236,11 @@
     "extra": {"branch": "default"},
     "manifest": null,
     "modified": ["d1/f1"],
-    "node": null,
+    "node": "ffffffffffffffffffffffffffffffffffffffff",
     "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"],
     "phase": "draft",
     "removed": [".d6/f1"],
-    "rev": null,
+    "rev": 2147483647,
     "tags": [],
     "user": "test"
    }
--- a/tests/test-template-keywords.t	Sun Sep 23 16:11:01 2018 +0900
+++ b/tests/test-template-keywords.t	Sat Sep 15 17:26:20 2018 +0900
@@ -52,6 +52,27 @@
   $ hg log -r 'wdir()' -T '{rev}:{node}\n'
   2147483647:ffffffffffffffffffffffffffffffffffffffff
 
+  $ hg log -r 'wdir()' -Tjson --debug
+  [
+   {
+    "added": [],
+    "bookmarks": [],
+    "branch": "default",
+    "date": [0, 0],
+    "desc": "",
+    "extra": {"branch": "default"},
+    "manifest": null,
+    "modified": [],
+    "node": "ffffffffffffffffffffffffffffffffffffffff",
+    "parents": ["95c24699272ef57d062b8bccc32c878bf841784a"],
+    "phase": "draft",
+    "removed": [],
+    "rev": 2147483647,
+    "tags": [],
+    "user": "test"
+   }
+  ]
+
 Some keywords are invalid for working-directory revision, but they should
 never cause crash: