Mercurial > hg-stable
changeset 24056:ae453d166d51
trydiff: replace 'binarydiff' variable by 'binary' variable
It's not obvious, but every path in the 'if opts.git or losedatafn:'
block will have checked whether the file is binary [1]. Let's assign
the result of this check to a variable so we can simplify by checking
'binary and opts.git' in only one place instead of every place we
currently assign to 'binarydiff'.
[1] Except when deleting an empty file, but checking whether an empty
string is binary is very cheap anyway.
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 22 Jan 2015 21:03:57 -0800 |
parents | 7f4e6b5fce03 |
children | 696d0fd77d94 |
files | mercurial/patch.py |
diffstat | 1 files changed, 13 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Fri Jan 16 15:09:21 2015 -0800 +++ b/mercurial/patch.py Thu Jan 22 21:03:57 2015 -0800 @@ -1776,7 +1776,7 @@ flag2 = None content1 = None content2 = None - binarydiff = False + binary = False copyop = None if f not in addedset: content1 = getfilectx(f, ctx1).data() @@ -1801,11 +1801,9 @@ else: if not opts.git and flag2: losedatafn(f) - if util.binary(content1) or util.binary(content2): - if opts.git: - binarydiff = True - else: - losedatafn(f) + binary = util.binary(content1) or util.binary(content2) + if not opts.git and binary: + losedatafn(f) if not opts.git and not content2: # regular diffs cannot represent new empty file losedatafn(f) @@ -1817,19 +1815,17 @@ continue else: flag1 = ctx1.flags(f) - if util.binary(content1): - binarydiff = True - elif not content1 or util.binary(content1): - # regular diffs cannot represent empty file deletion - losedatafn(f) + binary = util.binary(content1) + else: + binary = util.binary(content1) + if not content1 or binary: + # regular diffs cannot represent empty file deletion + losedatafn(f) else: flag1 = ctx1.flags(f) flag2 = ctx2.flags(f) binary = util.binary(content1) or util.binary(content2) - if opts.git: - if binary: - binarydiff = True - elif binary or flag2 != flag1: + if not opts.git and (binary or flag2 != flag1): losedatafn(f) path1 = posixpath.join(prefix, f1) @@ -1853,9 +1849,9 @@ elif revs and not repo.ui.quiet: header.append(diffline(path1, revs)) - if binarydiff and not opts.nobinary: + if binary and opts.git and not opts.nobinary: text = mdiff.b85diff(content1, content2) - if text and opts.git: + if text: header.append('index %s..%s' % (gitindex(content1), gitindex(content2))) else: