diff: rewrite diffline
authorGuillermo Pérez <bisho@fb.com>
Thu, 15 Nov 2012 13:57:03 -0800
changeset 17944 7ac2a7720724
parent 17943 66b9832331c9
child 17945 45766e2a7384
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.
mercurial/patch.py
--- 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()