diff mercurial/patch.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 a981ab2a1b4c
children c8e2d6ed1f9e
line wrap: on
line diff
--- a/mercurial/patch.py	Thu Feb 01 10:29:24 2018 -0800
+++ b/mercurial/patch.py	Thu Jan 25 22:40:19 2018 +0100
@@ -2698,8 +2698,13 @@
             if opts.git or losedatafn:
                 flag2 = ctx2.flags(f2)
         # 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 opts.text:
+            check_binary = True
+            binary = False
+        else:
+            check_binary = any(f.isbinary()
+                               for f in [fctx1, fctx2] if f is not None)
+            binary = check_binary
 
         if losedatafn and not opts.git:
             if (binary or
@@ -2789,7 +2794,8 @@
 
             uheaders, hunks = mdiff.unidiff(content1, date1,
                                             content2, date2,
-                                            path1, path2, opts=opts)
+                                            path1, path2, opts=opts,
+                                            check_binary=check_binary)
             header.extend(uheaders)
         yield fctx1, fctx2, header, hunks