diff mercurial/mdiff.py @ 35850:079b27b5a869

patch: avoid repeated binary checks if all files in a patch are text Differential Revision: https://phab.mercurial-scm.org/D1940
author Joerg Sonnenberger <joerg@bec.de>
date Thu, 25 Jan 2018 22:40:19 +0100
parents 6f62a1c3e11d
children a9d07bd8f758
line wrap: on
line diff
--- a/mercurial/mdiff.py	Thu Feb 01 10:29:24 2018 -0800
+++ b/mercurial/mdiff.py	Thu Jan 25 22:40:19 2018 +0100
@@ -234,13 +234,16 @@
             yield s, type
         yield s1, '='
 
-def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
+def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts, check_binary=True):
     """Return a unified diff as a (headers, hunks) tuple.
 
     If the diff is not null, `headers` is a list with unified diff header
     lines "--- <original>" and "+++ <new>" and `hunks` is a generator yielding
     (hunkrange, hunklines) coming from _unidiff().
     Otherwise, `headers` and `hunks` are empty.
+
+    Setting `check_binary` to false will skip the binary check, i.e. when
+    it has been done in advance. Files are expected to be text in this case.
     """
     def datetag(date, fn=None):
         if not opts.git and not opts.nodates:
@@ -270,7 +273,7 @@
                 text += "\n\ No newline at end of file\n"
             yield text
 
-    if not opts.text and (util.binary(a) or util.binary(b)):
+    if not opts.text and check_binary and (util.binary(a) or util.binary(b)):
         if a and b and len(a) == len(b) and a == b:
             return sentinel
         headerlines = []