[PATCH 3 of 7] trydiff: read flags in one place

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


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1421996460 28800
#      Thu Jan 22 23:01:00 2015 -0800
# Node ID 1b9ee5ff67792fa63f31411f6830690a88e5befa
# Parent  446a4c532ae41128967da6ed846478bbd6db057d
trydiff: read flags in one place

Now that we can trust f1/f2 to indicate whether that side of the diff
exists, we can move the calls to ctx.flag() to a single place.

diff -r 446a4c532ae4 -r 1b9ee5ff6779 mercurial/patch.py
--- a/mercurial/patch.py	Fri Feb 06 15:21:56 2015 -0800
+++ b/mercurial/patch.py	Thu Jan 22 23:01:00 2015 -0800
@@ -1772,8 +1772,6 @@
         if f not in ctx1:
             addedset.add(f)
     for f in sorted(modified + added + removed):
-        flag1 = None
-        flag2 = None
         content1 = None
         content2 = None
         copyop = None
@@ -1785,11 +1783,9 @@
         if opts.git or losedatafn:
             if f in addedset:
                 f1 = None
-                flag2 = ctx2.flags(f)
                 if f in copy:
                     if opts.git:
                         f1 = copy[f]
-                        flag1 = ctx1.flags(f1)
                         if f1 in removedset and f1 not in gone:
                             copyop = 'rename'
                             gone.add(f1)
@@ -1803,14 +1799,15 @@
                     if (f in copyto and copyto[f] in addedset
                         and copy[copyto[f]] == f):
                         continue
-                    else:
-                        flag1 = ctx1.flags(f)
-            else:
-                flag1 = ctx1.flags(f)
-                flag2 = ctx2.flags(f)
 
+        flag1 = None
+        flag2 = None
         binary = False
         if opts.git or losedatafn:
+            if f1:
+                flag1 = ctx1.flags(f1)
+            if f2:
+                flag2 = ctx2.flags(f2)
             binary = util.binary(content1) or util.binary(content2)
 
         if losedatafn and not opts.git:


More information about the Mercurial-devel mailing list