[PATCH 06 of 12] diff: rewrite diffline

Guillermo Pérez bisho at fb.com
Thu Nov 15 17:23:36 CST 2012


# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1353016623 28800
# Node ID 80e1a05abbe1f3f92ec7efe149d6dda9fa512b63
# Parent  d2316f61c1d0978630802b80ef85c77b08ad9a09
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.

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1665,19 +1665,17 @@
 
     ''' Helper header functions '''
     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()


More information about the Mercurial-devel mailing list