[PATCH 03 of 12] diff: move diffline to patch module

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


# HG changeset patch
# User Guillermo Pérez <bisho at fb.com>
# Date 1353010743 28800
# Node ID 76f999812cd7ea64a1646cd88201afe492d29938
# Parent  f0a4f2cff9298f78579ab69b640e0ff961474a2e
diff: move diffline to patch module

diffline is not part of diff computation, so makes more sense to
place it with other header generation in patch module.

In upcoming patches we will generalize this approach for
all headers added in the patch, including the git index
header.

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -143,19 +143,6 @@
             yield s, type
         yield s1, '='
 
-def diffline(revs, a, b, opts):
-    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)
-    else:
-        parts.append(a)
-    return ' '.join(parts) + '\n'
-
 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
     def datetag(date, fn=None):
         if not opts.git and not opts.nodates:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1664,6 +1664,20 @@
     def join(f):
         return os.path.join(prefix, f)
 
+    ''' Helper header functions '''
+    def diffline(revs, a, b, opts):
+        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)
+        else:
+            parts.append(a)
+        return ' '.join(parts) + '\n'
+
     date1 = util.datestr(ctx1.date())
     man1 = ctx1.manifest()
 
@@ -1749,7 +1763,7 @@
 
         if dodiff:
             if opts.git or revs:
-                header.insert(0, mdiff.diffline(revs, join(a), join(b), opts))
+                header.insert(0, diffline(revs, join(a), join(b), opts))
             if dodiff == 'binary':
                 text = mdiff.b85diff(to, tn)
             else:


More information about the Mercurial-devel mailing list