[PATCH 02 of 12] diff: unify calls to diffline

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


# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1353010568 28800
# Node ID f0a4f2cff9298f78579ab69b640e0ff961474a2e
# Parent  7234402c9fe3f4520692876ec9fdf6bc1081d2e1
diff: unify calls to diffline

diffline was called from trydiff for binary diffs and from unidiff
for text diffs. In this patch we unify those calls into one.

diffline is also a header, not part of diff mechanisms, so makes
sense to remove that responsability from mdiff module. In
upcoming patches we will move diffline to patch module and
keep grouping responsabilities.

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -156,7 +156,7 @@
         parts.append(a)
     return ' '.join(parts) + '\n'
 
-def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts):
+def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
     def datetag(date, fn=None):
         if not opts.git and not opts.nodates:
             return '\t%s\n' % date
@@ -207,9 +207,6 @@
         if l[ln][-1] != '\n':
             l[ln] += "\n\ No newline at end of file\n"
 
-    if r:
-        l.insert(0, diffline(r, fn1, fn2, opts))
-
     return "".join(l)
 
 # creates a headerless unified diff
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1746,17 +1746,17 @@
                         dodiff = 'binary'
                 elif binary or nflag != oflag:
                     losedatafn(f)
-            if opts.git:
-                header.insert(0, mdiff.diffline(revs, join(a), join(b), opts))
 
         if dodiff:
+            if opts.git or revs:
+                header.insert(0, mdiff.diffline(revs, join(a), join(b), opts))
             if dodiff == 'binary':
                 text = mdiff.b85diff(to, tn)
             else:
                 text = mdiff.unidiff(to, date1,
                                     # ctx2 date may be dynamic
                                     tn, util.datestr(ctx2.date()),
-                                    join(a), join(b), revs, opts=opts)
+                                    join(a), join(b), opts=opts)
             if header and (text or len(header) > 1):
                 yield ''.join(header)
             if text:


More information about the Mercurial-devel mailing list