changeset 31821:66a9faadbc83

patch: make diff in git mode respect --text option (issue5510) This changeset makes patch respect -a/--text option in --git mode by aligning its behaviour with git itself.
author Alexander Fomin <afomin@fb.com>
date Wed, 05 Apr 2017 15:15:06 -0700
parents 45761ef1bc93
children fde4822b0102
files mercurial/patch.py tests/test-diff-binary-file.t
diffstat 2 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Wed Apr 05 00:34:58 2017 +0900
+++ b/mercurial/patch.py	Wed Apr 05 15:15:06 2017 -0700
@@ -2552,7 +2552,7 @@
         elif revs and not repo.ui.quiet:
             header.append(diffline(path1, revs))
 
-        if binary and opts.git and not opts.nobinary:
+        if binary and opts.git and not opts.nobinary and not opts.text:
             text = mdiff.b85diff(content1, content2)
             if text:
                 header.append('index %s..%s' %
--- a/tests/test-diff-binary-file.t	Wed Apr 05 00:34:58 2017 +0900
+++ b/tests/test-diff-binary-file.t	Wed Apr 05 15:15:06 2017 -0700
@@ -73,5 +73,39 @@
   literal 5
   Mc$_OqttjCF00uV!&;S4c
   
+  $ cd ..
+
+Test text mode with extended git-style diff format
+  $ hg init b
+  $ cd b
+  $ cat > writebin.py <<EOF
+  > import sys
+  > path = sys.argv[1]
+  > open(path, 'wb').write('\x00\x01\x02\x03')
+  > EOF
+  $ python writebin.py binfile.bin
+  $ hg add binfile.bin
+  $ hg ci -m 'add binfile.bin'
+
+  $ echo >> binfile.bin
+  $ hg ci -m 'change binfile.bin'
+
+  $ hg diff --git -a -r 0 -r 1
+  diff --git a/binfile.bin b/binfile.bin
+  --- a/binfile.bin
+  +++ b/binfile.bin
+  @@ -1,1 +1,1 @@
+  -\x00\x01\x02\x03 (esc)
+  \ No newline at end of file
+  +\x00\x01\x02\x03 (esc)
+
+  $ HGPLAIN=1 hg diff --git -a -r 0 -r 1
+  diff --git a/binfile.bin b/binfile.bin
+  --- a/binfile.bin
+  +++ b/binfile.bin
+  @@ -1,1 +1,1 @@
+  -\x00\x01\x02\x03 (esc)
+  \ No newline at end of file
+  +\x00\x01\x02\x03 (esc)
 
   $ cd ..