trydiff: collect all lossiness checks in one place
By having all the checks for lossiness in one place, it becomes much
easier to get an overview of the conditions that lead to losedatafn()
being called. It also makes it obvious that it can not be called
multiple times for a single time (something that was rather tricky to
determine before).
--- a/mercurial/patch.py Thu Jan 22 21:03:57 2015 -0800
+++ b/mercurial/patch.py Thu Jan 22 21:35:57 2015 -0800
@@ -1796,17 +1796,7 @@
else:
copyop = 'copy'
content1 = getfilectx(f1, ctx1).data()
- else:
- losedatafn(f)
- else:
- if not opts.git and flag2:
- 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)
elif f in removedset:
if opts.git:
# have we already reported a copy above?
@@ -1818,15 +1808,25 @@
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 not opts.git and (binary or flag2 != flag1):
- losedatafn(f)
+
+ if losedatafn and not opts.git:
+ if (binary or
+ # copy/rename
+ f in copy or
+ # empty file creation
+ (content1 is None and not content2) or
+ # empty file deletion
+ (not content1 and content2 is None) or
+ # create with flags
+ (content1 is None and flag2) or
+ # change flags
+ (content1 is not None and content2 is not None and
+ flag1 != flag2)):
+ losedatafn(f)
path1 = posixpath.join(prefix, f1)
path2 = posixpath.join(prefix, f2)