diff: use binary diff when copy source is binary stable
authorMartin von Zweigbergk <martinvonz@google.com>
Sat, 17 Jan 2015 15:03:41 -0800
branchstable
changeset 23924 0db6810e84e8
parent 23923 ab6fd3205dad
child 23925 e563e0cfe08c
diff: use binary diff when copy source is binary When a binary source has been copied or renamed into a non-binary file, we don't check whether the copy source was binary. There is a code comment explaining that a git mode will be forced anyway in order to capture the copy record (i.e. losedatafn() will be called). This is true, but forcing git mode is not the only effect binary files have: when git mode was already requested, we use the binary-ness to tell us whether to use a regular unified diff or a git binary diff. The user sees this as a "Binary file $file has changed" instead of the binary
mercurial/patch.py
tests/test-diff-binary-file.t
--- a/mercurial/patch.py	Sun Jan 18 15:15:40 2015 -0500
+++ b/mercurial/patch.py	Sat Jan 17 15:03:41 2015 -0800
@@ -1831,10 +1831,7 @@
                         header.append('new file mode %s\n' % mode)
                     elif ctx2.flags(f):
                         losedatafn(f)
-                # In theory, if tn was copied or renamed we should check
-                # if the source is binary too but the copy record already
-                # forces git mode.
-                if util.binary(tn):
+                if util.binary(to) or util.binary(tn):
                     if opts.git:
                         binarydiff = True
                     else:
--- a/tests/test-diff-binary-file.t	Sun Jan 18 15:15:40 2015 -0500
+++ b/tests/test-diff-binary-file.t	Sat Jan 17 15:03:41 2015 -0800
@@ -9,6 +9,9 @@
 
   $ hg revert -r 0 binfile.bin
   $ hg ci -m 'revert binfile.bin'
+  $ hg cp binfile.bin nonbinfile
+  $ echo text > nonbinfile
+  $ hg ci -m 'make non-binary copy of binary file'
 
   $ hg diff --nodates -r 0 -r 1
   diff -r 48b371597640 -r acea2ab458c8 binfile.bin
@@ -41,4 +44,14 @@
   diff --git a/binfile.bin b/binfile.bin
   Binary file binfile.bin has changed
 
+  $ hg diff --git -r 2 -r 3
+  diff --git a/binfile.bin b/nonbinfile
+  copy from binfile.bin
+  copy to nonbinfile
+  index 37ba3d1c6f17137d9c5f5776fa040caf5fe73ff9..8e27be7d6154a1f68ea9160ef0e18691d20560dc
+  GIT binary patch
+  literal 5
+  Mc$_OqttjCF00uV!&;S4c
+  
+
   $ cd ..