Patchwork [4,of,5,V2] diff: correct binary testing logic

login
register
mail settings
Submitter Jun Wu
Date May 6, 2017, 1:27 a.m.
Message ID <43b7e046f5e1b36041c8.1494034041@x1c>
Download mbox | patch
Permalink /patch/20467/
State Accepted
Headers show

Comments

Jun Wu - May 6, 2017, 1:27 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1494030032 25200
#      Fri May 05 17:20:32 2017 -0700
# Node ID 43b7e046f5e1b36041c8ce124a27e5c5f3ba27fd
# Parent  efded9da711f0c0fc129f13577c6ce3789f1f183
# Available At https://bitbucket.org/quark-zju/hg-draft
#              hg pull https://bitbucket.org/quark-zju/hg-draft -r 43b7e046f5e1
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

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2541,7 +2541,7 @@  def trydiff(repo, revs, ctx1, ctx2, modi
             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:
@@ -2596,5 +2596,5 @@  def trydiff(repo, revs, ctx1, ctx2, modi
         #  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: