trydiff: collect all lossiness checks in one place
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 22 Jan 2015 21:35:57 -0800
changeset 24057 696d0fd77d94
parent 24056 ae453d166d51
child 24058 d1fcff9400c9
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).
mercurial/patch.py
--- 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)