##// END OF EJS Templates
patch: avoid repeated binary checks if all files in a patch are text...
Joerg Sonnenberger -
r35868:079b27b5 default
parent child Browse files
Show More
@@ -234,13 +234,16 b' def allblocks(text1, text2, opts=None, l'
234 yield s, type
234 yield s, type
235 yield s1, '='
235 yield s1, '='
236
236
237 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
237 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts, check_binary=True):
238 """Return a unified diff as a (headers, hunks) tuple.
238 """Return a unified diff as a (headers, hunks) tuple.
239
239
240 If the diff is not null, `headers` is a list with unified diff header
240 If the diff is not null, `headers` is a list with unified diff header
241 lines "--- <original>" and "+++ <new>" and `hunks` is a generator yielding
241 lines "--- <original>" and "+++ <new>" and `hunks` is a generator yielding
242 (hunkrange, hunklines) coming from _unidiff().
242 (hunkrange, hunklines) coming from _unidiff().
243 Otherwise, `headers` and `hunks` are empty.
243 Otherwise, `headers` and `hunks` are empty.
244
245 Setting `check_binary` to false will skip the binary check, i.e. when
246 it has been done in advance. Files are expected to be text in this case.
244 """
247 """
245 def datetag(date, fn=None):
248 def datetag(date, fn=None):
246 if not opts.git and not opts.nodates:
249 if not opts.git and not opts.nodates:
@@ -270,7 +273,7 b' def unidiff(a, ad, b, bd, fn1, fn2, opts'
270 text += "\n\ No newline at end of file\n"
273 text += "\n\ No newline at end of file\n"
271 yield text
274 yield text
272
275
273 if not opts.text and (util.binary(a) or util.binary(b)):
276 if not opts.text and check_binary and (util.binary(a) or util.binary(b)):
274 if a and b and len(a) == len(b) and a == b:
277 if a and b and len(a) == len(b) and a == b:
275 return sentinel
278 return sentinel
276 headerlines = []
279 headerlines = []
@@ -2698,8 +2698,13 b' def trydiff(repo, revs, ctx1, ctx2, modi'
2698 if opts.git or losedatafn:
2698 if opts.git or losedatafn:
2699 flag2 = ctx2.flags(f2)
2699 flag2 = ctx2.flags(f2)
2700 # if binary is True, output "summary" or "base85", but not "text diff"
2700 # if binary is True, output "summary" or "base85", but not "text diff"
2701 binary = not opts.text and any(f.isbinary()
2701 if opts.text:
2702 for f in [fctx1, fctx2] if f is not None)
2702 check_binary = True
2703 binary = False
2704 else:
2705 check_binary = any(f.isbinary()
2706 for f in [fctx1, fctx2] if f is not None)
2707 binary = check_binary
2703
2708
2704 if losedatafn and not opts.git:
2709 if losedatafn and not opts.git:
2705 if (binary or
2710 if (binary or
@@ -2789,7 +2794,8 b' def trydiff(repo, revs, ctx1, ctx2, modi'
2789
2794
2790 uheaders, hunks = mdiff.unidiff(content1, date1,
2795 uheaders, hunks = mdiff.unidiff(content1, date1,
2791 content2, date2,
2796 content2, date2,
2792 path1, path2, opts=opts)
2797 path1, path2, opts=opts,
2798 check_binary=check_binary)
2793 header.extend(uheaders)
2799 header.extend(uheaders)
2794 yield fctx1, fctx2, header, hunks
2800 yield fctx1, fctx2, header, hunks
2795
2801
General Comments 0
You need to be logged in to leave comments. Login now