changeset 17944:7ac2a7720724

diff: rewrite diffline Make diffline more readable, using strings with placeholders rather than appending to a list from many ifs that makes difficult to understand the actual output format.
author Guillermo Pérez <bisho@fb.com>
date Thu, 15 Nov 2012 13:57:03 -0800
parents 66b9832331c9
children 45766e2a7384
files mercurial/patch.py
diffstat 1 files changed, 9 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Thu Nov 15 13:52:51 2012 -0800
+++ b/mercurial/patch.py	Thu Nov 15 13:57:03 2012 -0800
@@ -1664,19 +1664,17 @@
         return os.path.join(prefix, f)
 
     def diffline(a, b, revs):
-        if repo.ui.quiet and not opts.git:
-            return ''
-        parts = ['diff']
         if opts.git:
-            parts.append('--git')
-        if revs and not opts.git:
-            parts.append(' '.join(["-r %s" % rev for rev in revs]))
-        if opts.git:
-            parts.append('a/%s' % a)
-            parts.append('b/%s' % b)
+            line = 'diff --git a/%s b/%s\n' % (a, b)
+        elif not repo.ui.quiet:
+            if revs:
+                revinfo = ' '.join(["-r %s" % rev for rev in revs])
+                line = 'diff %s %s\n' % (revinfo, a)
+            else:
+                line = 'diff %s\n' % a
         else:
-            parts.append(a)
-        return ' '.join(parts) + '\n'
+            line = ''
+        return line
 
     date1 = util.datestr(ctx1.date())
     man1 = ctx1.manifest()