Patchwork [2,of,2] jsonchangeset: set "null" to manifest node for workingctx

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

Comments

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

Unlike changeset_printer, it does not hide the manifest field because JSON
output will be parsed by machine where explicit "null" will be more useful
than nothing.
Matt Mackall - April 3, 2015, 9:39 p.m.
On Fri, 2015-04-03 at 22:35 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1426331795 -32400
> #      Sat Mar 14 20:16:35 2015 +0900
> # Node ID 916dd2c469982d3254caceb30ee8fe2d67813cac
> # Parent  879585b9af3132d55eb14c829034fdb19768dd25
> jsonchangeset: set "null" to manifest node for workingctx

These are queued for default, thanks. I swapped "set null to X" for "set
X to null" in their descriptions.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1296,7 +1296,11 @@  class jsonchangeset(changeset_printer):
                       ", ".join('"%s"' % c.hex() for c in ctx.parents()))
 
         if self.ui.debugflag:
-            self.ui.write(',\n  "manifest": "%s"' % hex(ctx.manifestnode()))
+            if rev is None:
+                jmanifestnode = 'null'
+            else:
+                jmanifestnode = '"%s"' % hex(ctx.manifestnode())
+            self.ui.write(',\n  "manifest": %s' % jmanifestnode)
 
             self.ui.write(',\n  "extra": {%s}' %
                           ", ".join('"%s": "%s"' % (j(k), j(v))
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -1666,6 +1666,27 @@  working-directory revision requires spec
    }
   ]
 
+  $ hg log -r 'wdir()' -Tjson --debug
+  [
+   {
+    "rev": null,
+    "node": null,
+    "branch": "default",
+    "phase": "draft",
+    "user": "test",
+    "date": [*, 0], (glob)
+    "desc": "",
+    "bookmarks": [],
+    "tags": ["tip"],
+    "parents": ["65624cd9070a035fa7191a54f2b8af39f16b0c08"],
+    "manifest": null,
+    "extra": {"branch": "default"},
+    "modified": [],
+    "added": [],
+    "removed": []
+   }
+  ]
+
 Check that adding an arbitrary name shows up in log automatically
 
   $ cat > ../names.py <<EOF