[PATCH 4 of 5] trydiff: replace 'dodiff = False' by 'continue'

Martin von Zweigbergk martinvonz at google.com
Wed Jan 7 13:53:19 CST 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1420657180 28800
#      Wed Jan 07 10:59:40 2015 -0800
# Node ID dd66ac280e5bf951aaee2958617ceaf038b441c7
# Parent  e5ae546bf7539d680cb65e7d5c7dbf96e3d322ae
trydiff: replace 'dodiff = False' by 'continue'

The 'dodiff' variable is initialized to True and may later be set to
either False or "binary". When it's set to False, we skip everything
after that point, so we can simplify by instead continue-ing (the
loop). We can then also drop the 'if dodiff', since it will always be
true.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1849,7 +1849,7 @@
                          and copyto[copy[f]] == f) or
                         (f in copyto and copyto[f] in addedset
                          and copy[copyto[f]] == f)):
-                        dodiff = False
+                        continue
                     else:
                         header.append('deleted file mode %s\n' %
                                       gitmode[ctx1.flags(f)])
@@ -1869,21 +1869,20 @@
                 elif binary or nflag != oflag:
                     losedatafn(f)
 
-        if dodiff:
-            if opts.git or revs:
-                header.insert(0, diffline(join(a), join(b), revs))
-            if dodiff == 'binary' and not opts.nobinary:
-                text = mdiff.b85diff(to, tn)
-                if text and opts.git:
-                    addindexmeta(header, gitindex(to), gitindex(tn))
-            else:
-                text = mdiff.unidiff(to, date1,
-                                     tn, date2,
-                                     join(a), join(b), opts=opts)
-            if header and (text or len(header) > 1):
-                yield ''.join(header)
-            if text:
-                yield text
+        if opts.git or revs:
+            header.insert(0, diffline(join(a), join(b), revs))
+        if dodiff == 'binary' and not opts.nobinary:
+            text = mdiff.b85diff(to, tn)
+            if text and opts.git:
+                addindexmeta(header, gitindex(to), gitindex(tn))
+        else:
+            text = mdiff.unidiff(to, date1,
+                                 tn, date2,
+                                 join(a), join(b), opts=opts)
+        if header and (text or len(header) > 1):
+            yield ''.join(header)
+        if text:
+            yield text
 
 def diffstatsum(stats):
     maxfile, maxtotal, addtotal, removetotal, binary = 0, 0, 0, 0, False


More information about the Mercurial-devel mailing list