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

login
register
mail settings
Submitter timeless@mozdev.org
Date March 8, 2016, 7:44 p.m.
Message ID <a937921be52a4dd619dc.1457466268@waste.org>
Download mbox | patch
Permalink /patch/13686/
State Changes Requested
Delegated to: Yuya Nishihara
Headers show

Comments

timeless@mozdev.org - March 8, 2016, 7:44 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1456455801 0
#      Fri Feb 26 03:03:21 2016 +0000
# Node ID a937921be52a4dd619dcec9cff852b4f47afa565
# Parent  ec4546f50c52baae1db569008c33de7ac06949e3
changeset: adjust json output to use new/old (BC)

The previous json structure was not friendly to strongly structured parsing.
Yuya Nishihara - March 9, 2016, 2:39 p.m.
On Tue, 08 Mar 2016 13:44:28 -0600, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1456455801 0
> #      Fri Feb 26 03:03:21 2016 +0000
> # Node ID a937921be52a4dd619dcec9cff852b4f47afa565
> # Parent  ec4546f50c52baae1db569008c33de7ac06949e3
> changeset: adjust json output to use new/old (BC)
> 
> The previous json structure was not friendly to strongly structured parsing.

Repeat: I can't see why it was not friendly. Can you elaborate?

> --- 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"}}]
>     }
>    ]

Also, {"path": ..} is inconsistent because:

 - an item of "files" isn't wrapped by {"path": ..}
 - it is an absolute (repository-relative) path

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1423,8 +1423,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"}}]
    }
   ]