Patchwork [4,of,7] jsonchangeset: don't honor whitespace and format-changing diffopts

login
register
mail settings
Submitter Siddharth Agarwal
Date Dec. 2, 2014, 6:30 p.m.
Message ID <b1c21372050f7df60112.1417545015@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6955/
State Accepted
Commit d4da438745b0ae7c4b98fd34f81da569b3a25c69
Headers show

Comments

Siddharth Agarwal - Dec. 2, 2014, 6:30 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1416377585 28800
#      Tue Nov 18 22:13:05 2014 -0800
# Node ID b1c21372050f7df6011214a1c6c7b01f7267ea87
# Parent  d0567be37614d98bdb4da26d207b788094d1c3b1
jsonchangeset: don't honor whitespace and format-changing diffopts

JSON is meant to be parsed by computers, and format changes can break them.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1093,7 +1093,7 @@ 
         if matchfn:
             stat = self.diffopts.get('stat')
             diff = self.diffopts.get('patch')
-            diffopts = patch.diffopts(self.ui, self.diffopts)
+            diffopts = patch.difffeatureopts(self.ui, self.diffopts, git=True)
             node, prev = ctx.node(), ctx.p1().node()
             if stat:
                 self.ui.pushbuffer()
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -525,6 +525,25 @@ 
    }
   ]
 
+honor --git but not format-breaking diffopts
+  $ hg --config diff.noprefix=True log --git -vpr . -Tjson
+  [
+   {
+    "rev": 8,
+    "node": "95c24699272ef57d062b8bccc32c878bf841784a",
+    "branch": "default",
+    "phase": "draft",
+    "user": "test",
+    "date": [1577872860, 0],
+    "desc": "third",
+    "bookmarks": [],
+    "tags": ["tip"],
+    "parents": ["29114dbae42b9f078cf2714dbe3a86bba8ec7453"],
+    "files": ["fourth", "second", "third"],
+    "diff": "diff --git a/second b/fourth\nrename from second\nrename to fourth\ndiff --git a/third b/third\nnew file mode 100644\n--- /dev/null\n+++ b/third\n@@ -0,0 +1,1 @@\n+third\n"
+   }
+  ]
+
   $ hg log -T json
   [
    {