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

login
register
mail settings
Submitter Martin von Zweigbergk
Date Feb. 3, 2015, 4:58 p.m.
Message ID <77066b7b7b26ff04e792.1422982707@martinvonz.mtv.corp.google.com>
Download mbox | patch
Permalink /patch/7632/
State Accepted
Commit cc81e6da0757c0816a98ccd2b2c635681b2f816c
Headers show

Comments

Martin von Zweigbergk - Feb. 3, 2015, 4:58 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@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.

Patch

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