diff: correct binary testing logic
authorJun Wu <quark@fb.com>
Fri, 05 May 2017 17:20:32 -0700
changeset 32190 0c67ab3d77d5
parent 32189 15f10ee778f8
child 32191 31f42e683321
diff: correct binary testing logic This seems to be more correct given the table drawn in the previous patch. Namely, "losedatafn" and "opts.git" are removed, "not opts.text" is added. - losedatafn: diff output (binary) should not be affected by "losedatafn" - opts.git: binary testing is helpful for detecting a fast path in the next path. the fast path can also be used if opts.git is False - opts.text: if it's set, we should treat the content as non-binary
mercurial/patch.py
--- a/mercurial/patch.py	Fri May 05 16:48:58 2017 -0700
+++ b/mercurial/patch.py	Fri May 05 17:20:32 2017 -0700
@@ -2540,9 +2540,9 @@
             content2 = fctx2.data()
             if opts.git or losedatafn:
                 flag2 = ctx2.flags(f2)
-        binary = False
-        if opts.git or losedatafn:
-            binary = any(f.isbinary() for f in [fctx1, fctx2] if f is not None)
+        # if binary is True, output "summary" or "base85", but not "text diff"
+        binary = not opts.text and any(f.isbinary()
+                                       for f in [fctx1, fctx2] if f is not None)
 
         if losedatafn and not opts.git:
             if (binary or
@@ -2595,7 +2595,7 @@
         #  yes      | yes  *        *   *     | text diff | yes
         #  no       | *    *        *   *     | text diff | yes
         # [1]: hash(fctx.data()) is outputted. so fctx.data() cannot be faked
-        if binary and opts.git and not opts.nobinary and not opts.text:
+        if binary and opts.git and not opts.nobinary:
             text = mdiff.b85diff(content1, content2)
             if text:
                 header.append('index %s..%s' %