Patchwork [3,of,3,v2] changeset: adjust json output to use new/old

login
register
mail settings
Submitter timeless@mozdev.org
Date Feb. 26, 2016, 6:12 p.m.
Message ID <3e1dbbc6ece30c6207c2.1456510362@waste.org>
Download mbox | patch
Permalink /patch/13425/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - Feb. 26, 2016, 6:12 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1456455801 0
#      Fri Feb 26 03:03:21 2016 +0000
# Node ID 3e1dbbc6ece30c6207c21bb47b888b39e1052a02
# Parent  d66dc235bd21ed08c5661fd62604d0c1bcfd0f8a
changeset: adjust json output to use new/old

The previous json structure was not friendly to strongly structured parsing.
Yuya Nishihara - Feb. 27, 2016, 10:04 a.m.
On Fri, 26 Feb 2016 12:12:42 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1456455801 0
> #      Fri Feb 26 03:03:21 2016 +0000
> # Node ID 3e1dbbc6ece30c6207c21bb47b888b39e1052a02
> # Parent  d66dc235bd21ed08c5661fd62604d0c1bcfd0f8a
> changeset: adjust json output to use new/old

Also, this is (BC). Be aware that changing JSON format can break existing
scripts. And log output would be more widely used than other formatter commands.

> The previous json structure was not friendly to strongly structured parsing.

How was it unfriendly? Can you elaborate?

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1395,8 +1395,9 @@ 
                           ", ".join('"%s"' % j(f) for f in ctx.files()))
 
             if copies:
-                self.ui.write(',\n  "copies": {%s}' %
-                              ", ".join('"%s": "%s"' % (j(k), j(v))
+                self.ui.write(',\n  "copies": [%s]' %
+                              ", ".join('{"new": {"path": "%s"}, '
+                                         '"old": {"path": "%s"}}' % (j(k), j(v))
                                                         for k, v in copies))
 
         matchfn = self.matchfn
diff --git a/tests/test-log.t b/tests/test-log.t
--- a/tests/test-log.t
+++ b/tests/test-log.t
@@ -524,7 +524,7 @@ 
     "tags": ["tip"],
     "parents": ["2ca5ba7019804f1f597249caddf22a64d34df0ba"],
     "files": ["dir/b", "e"],
-    "copies": {"e": "dir/b"}
+    "copies": [{"new": {"path": "e"}, "old": {"path": "dir/b"}}]
    }
   ]