[PATCH 3 of 4] trydiff: inline sole addmodehdr() call

Martin von Zweigbergk martinvonz at google.com
Mon Feb 2 17:45:12 CST 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1421448817 28800
#      Fri Jan 16 14:53:37 2015 -0800
# Node ID 31dcd28149e033c4bf523790d1a266628684d294
# Parent  2ab403e0f991311b6698038b47bf84ed26ba2ed5
trydiff: inline sole addmodehdr() call

Now that there is only a single call to addmodehdr() left, and there
is other similar code (for new/deleted files) around that call site,
let's inline the function there. That also makes it clearer under what
circumstances the header is actually written (when modes differ).

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1739,11 +1739,6 @@
 def trydiff(repo, revs, ctx1, ctx2, modified, added, removed,
             copy, getfilectx, opts, losedatafn, prefix):
 
-    def addmodehdr(header, mode1, mode2):
-        if mode1 != mode2:
-            header.append('old mode %s\n' % mode1)
-            header.append('new mode %s\n' % mode2)
-
     def addindexmeta(meta, index1, index2):
         meta.append('index %s..%s\n' % (index1, index2))
 
@@ -1861,7 +1856,10 @@
             elif content2 is None: # removed
                 header.append('deleted file mode %s\n' % gitmode[flag1])
             else:  # modified/copied/renamed
-                addmodehdr(header, gitmode[flag1], gitmode[flag2])
+                mode1, mode2 = gitmode[flag1], gitmode[flag2]
+                if mode1 != mode2:
+                    header.append('old mode %s\n' % mode1)
+                    header.append('new mode %s\n' % mode2)
                 if op is not None:
                     header.append('%s from %s\n' % (op, path1))
                     header.append('%s to %s\n' % (op, path2))


More information about the Mercurial-devel mailing list