[PATCH 1 of 6 for-clowncopter] trydiff: move git-header code out of diffline function

Martin von Zweigbergk martinvonz at google.com
Tue Feb 3 10:58:27 CST 2015


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1421449086 28800
#      Fri Jan 16 14:58:06 2015 -0800
# Node ID 77066b7b7b26ff04e7928fe79ef5f03219ae26b7
# Parent  891ed406d6bdb81faaf6619a89f37ce0c95bb579
trydiff: move git-header code out of diffline function

This collects more of the code for writing git headers in a single
place and makes diffline() close on a few variables less.

diff -r 891ed406d6bd -r 77066b7b7b26 mercurial/patch.py
--- a/mercurial/patch.py	Fri Jan 16 15:40:59 2015 -0800
+++ b/mercurial/patch.py	Fri Jan 16 14:58:06 2015 -0800
@@ -1754,9 +1754,7 @@
         bprefix = 'b/'
 
     def diffline(a, b, revs):
-        if opts.git:
-            line = 'diff --git %s%s %s%s\n' % (aprefix, a, bprefix, b)
-        elif not repo.ui.quiet:
+        if not repo.ui.quiet:
             if revs:
                 revinfo = ' '.join(["-r %s" % rev for rev in revs])
                 line = 'diff %s %s\n' % (revinfo, a)
@@ -1847,9 +1845,11 @@
         path1 = posixpath.join(prefix, f1)
         path2 = posixpath.join(prefix, f2)
         header = []
-        if opts.git or revs:
+        if revs:
             header.append(diffline(path1, path2, revs))
-        if opts.git:
+        elif opts.git:
+            header.append('diff --git %s%s %s%s\n' %
+                          (aprefix, path1, bprefix, path2))
             if content1 is None: # added
                 header.append('new file mode %s\n' % gitmode[flag2])
             elif content2 is None: # removed


More information about the Mercurial-devel mailing list