trydiff: move git-header code out of diffline function
authorMartin von Zweigbergk <martinvonz@google.com>
Fri, 16 Jan 2015 14:58:06 -0800
changeset 24020 cc81e6da0757
parent 24019 26fbf07482b2
child 24021 f51a822dcf3b
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.
mercurial/patch.py
--- a/mercurial/patch.py	Tue Jan 27 09:22:59 2015 -0500
+++ 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