[PATCH 4 of 7] trydiff: set filename variables to None even when not opts.git or losedatafn

Martin von Zweigbergk martinvonz at google.com
Fri Feb 6 19:13:33 CST 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1421997228 28800
#      Thu Jan 22 23:13:48 2015 -0800
# Node ID b66e35f2e7ee0f247e90ee032f1b1559c998722b
# Parent  1b9ee5ff67792fa63f31411f6830690a88e5befa
trydiff: set filename variables to None even when not opts.git or losedatafn

There is not much left of the first block "if opts.git or losedatafn"
block now. The next patch will move the call to getfilectx() out of
that block. We will then be using the defined-ness of 'f1' to tell
whether the file existed in ctx1 (and under what name). We will need
this information whether or not opts.git or losedatafn was set, so
just remove that guard. The only operation in the block that is not
cheap is the call to getfilectx(), but that has an extra 'if opts.git'
guard already.

--ignore-space-change proves that only 'if opts.git or losedatafn:'
  was removed.

diff -r 1b9ee5ff6779 -r b66e35f2e7ee mercurial/patch.py
--- a/mercurial/patch.py	Thu Jan 22 23:01:00 2015 -0800
+++ b/mercurial/patch.py	Thu Jan 22 23:13:48 2015 -0800
@@ -1780,25 +1780,24 @@
         if f not in removedset:
             content2 = getfilectx(f, ctx2).data()
         f1, f2 = f, f
-        if opts.git or losedatafn:
-            if f in addedset:
-                f1 = None
-                if f in copy:
-                    if opts.git:
-                        f1 = copy[f]
-                        if f1 in removedset and f1 not in gone:
-                            copyop = 'rename'
-                            gone.add(f1)
-                        else:
-                            copyop = 'copy'
-                        content1 = getfilectx(f1, ctx1).data()
-            elif f in removedset:
-                f2 = None
+        if f in addedset:
+            f1 = None
+            if f in copy:
                 if opts.git:
-                    # have we already reported a copy above?
-                    if (f in copyto and copyto[f] in addedset
-                        and copy[copyto[f]] == f):
-                        continue
+                    f1 = copy[f]
+                    if f1 in removedset and f1 not in gone:
+                        copyop = 'rename'
+                        gone.add(f1)
+                    else:
+                        copyop = 'copy'
+                    content1 = getfilectx(f1, ctx1).data()
+        elif f in removedset:
+            f2 = None
+            if opts.git:
+                # have we already reported a copy above?
+                if (f in copyto and copyto[f] in addedset
+                    and copy[copyto[f]] == f):
+                    continue
 
         flag1 = None
         flag2 = None


More information about the Mercurial-devel mailing list