Patchwork [1,of,2] jsonchangeset: set "null" to rev and node for workingctx

login
register
mail settings
Submitter Yuya Nishihara
Date April 3, 2015, 1:35 p.m.
Message ID <879585b9af3132d55eb1.1428068131@mimosa>
Download mbox | patch
Permalink /patch/8475/
State Accepted
Headers show

Comments

Yuya Nishihara - April 3, 2015, 1:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1426331740 -32400
#      Sat Mar 14 20:15:40 2015 +0900
# Node ID 879585b9af3132d55eb14c829034fdb19768dd25
# Parent  d7cf8102bf09a905662c1018e60a06e417a08af3
jsonchangeset: set "null" to rev and node for workingctx

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1260,8 +1260,12 @@  class jsonchangeset(changeset_printer):
 
     def _show(self, ctx, copies, matchfn, props):
         '''show a single changeset or file revision'''
-        hexnode = hex(ctx.node())
         rev = ctx.rev()
+        if rev is None:
+            jrev = jnode = 'null'
+        else:
+            jrev = str(rev)
+            jnode = '"%s"' % hex(ctx.node())
         j = encoding.jsonescape
 
         if self._first:
@@ -1271,13 +1275,13 @@  class jsonchangeset(changeset_printer):
             self.ui.write(",\n {")
 
         if self.ui.quiet:
-            self.ui.write('\n  "rev": %d' % rev)
-            self.ui.write(',\n  "node": "%s"' % hexnode)
+            self.ui.write('\n  "rev": %s' % jrev)
+            self.ui.write(',\n  "node": %s' % jnode)
             self.ui.write('\n }')
             return
 
-        self.ui.write('\n  "rev": %d' % rev)
-        self.ui.write(',\n  "node": "%s"' % hexnode)
+        self.ui.write('\n  "rev": %s' % jrev)
+        self.ui.write(',\n  "node": %s' % jnode)
         self.ui.write(',\n  "branch": "%s"' % j(ctx.branch()))
         self.ui.write(',\n  "phase": "%s"' % ctx.phasestr())
         self.ui.write(',\n  "user": "%s"' % j(ctx.user()))
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1642,6 +1642,30 @@  working-directory revision requires spec
   date:        [A-Za-z0-9:+ ]+ (re)
   extra:       branch=default
   
+  $ hg log -r 'wdir()' -Tjson
+  [
+   {
+    "rev": null,
+    "node": null,
+    "branch": "default",
+    "phase": "draft",
+    "user": "test",
+    "date": [*, 0], (glob)
+    "desc": "",
+    "bookmarks": [],
+    "tags": ["tip"],
+    "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"]
+   }
+  ]
+
+  $ hg log -r 'wdir()' -Tjson -q
+  [
+   {
+    "rev": null,
+    "node": null
+   }
+  ]
+
 Check that adding an arbitrary name shows up in log automatically
 
   $ cat > ../names.py <<EOF