Patchwork [5,of,6,for-clowncopter] trydiff: move check for quietness out of diffline()

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

Comments

Martin von Zweigbergk - Feb. 3, 2015, 4:58 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1421450824 28800
#      Fri Jan 16 15:27:04 2015 -0800
# Node ID 1522a50d388c8284f16d22b9e01a087966c35f5f
# Parent  fc234a3f6f8ac43ef2067aef9136c012bccbe6eb
trydiff: move check for quietness out of diffline()

By moving the condition out of diffline(), the call site becomes
clearer and diffline() no longer closes on any variables.

Note that this changes the value of the header variable from [''] to
[], but there is no difference in how these two are treated by the
following code. The new value seems more natural anyway.

Patch

diff -r fc234a3f6f8a -r 1522a50d388c mercurial/patch.py
--- a/mercurial/patch.py	Fri Jan 16 15:22:29 2015 -0800
+++ b/mercurial/patch.py	Fri Jan 16 15:27:04 2015 -0800
@@ -1754,12 +1754,8 @@ 
         bprefix = 'b/'
 
     def diffline(f, revs):
-        if not repo.ui.quiet:
-            revinfo = ' '.join(["-r %s" % rev for rev in revs])
-            line = 'diff %s %s\n' % (revinfo, f)
-        else:
-            line = ''
-        return line
+        revinfo = ' '.join(["-r %s" % rev for rev in revs])
+        return 'diff %s %s\n' % (revinfo, f)
 
     date1 = util.datestr(ctx1.date())
     date2 = util.datestr(ctx2.date())
@@ -1854,7 +1850,7 @@ 
                 if op is not None:
                     header.append('%s from %s\n' % (op, path1))
                     header.append('%s to %s\n' % (op, path2))
-        elif revs:
+        elif revs and not repo.ui.quiet:
             header.append(diffline(path1, revs))
 
         if binarydiff and not opts.nobinary: