Patchwork [3,of,4] trydiff: collect all lossiness checks in one place

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 6, 2015, midnight
Message ID <282e35936726d0267ffc.1423180845@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7697/
State Accepted
Commit 696d0fd77d94ffec5e498968dd3bd9b3b251f704
Headers show

Comments

Martin von Zweigbergk - Feb. 6, 2015, midnight
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421991357 28800
#      Thu Jan 22 21:35:57 2015 -0800
# Node ID 282e35936726d0267ffcf58f949c56d8de1b33f8
# Parent  81d13573f5528ec86c90ebb49a3b3424a07b8833
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).

Patch

diff -r 81d13573f552 -r 282e35936726 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)