changeset 23299:1f510efcd5f3

mdiff.unidiff: add support for noprefix
author Siddharth Agarwal <sid0@fb.com>
date Wed, 12 Nov 2014 23:29:14 -0800
parents dc4d0c7b7d94
children f8b5c3e77d4b
files mercurial/mdiff.py tests/test-diff-unified.t
diffstat 2 files changed, 23 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mdiff.py	Thu Nov 13 00:13:48 2014 -0800
+++ b/mercurial/mdiff.py	Wed Nov 12 23:29:14 2014 -0800
@@ -156,6 +156,13 @@
 
     if not a and not b:
         return ""
+
+    if opts.noprefix:
+        aprefix = bprefix = ''
+    else:
+        aprefix = 'a/'
+        bprefix = 'b/'
+
     epoch = util.datestr((0, 0))
 
     fn1 = util.pconvert(fn1)
@@ -170,17 +177,17 @@
         if a is None:
             l1 = '--- /dev/null%s' % datetag(epoch)
         else:
-            l1 = "--- %s%s" % ("a/" + fn1, datetag(ad, fn1))
-        l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd, fn2))
+            l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
+        l2 = "+++ %s%s" % (bprefix + fn2, datetag(bd, fn2))
         l3 = "@@ -0,0 +1,%d @@\n" % len(b)
         l = [l1, l2, l3] + ["+" + e for e in b]
     elif not b:
         a = splitnewlines(a)
-        l1 = "--- %s%s" % ("a/" + fn1, datetag(ad, fn1))
+        l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
         if b is None:
             l2 = '+++ /dev/null%s' % datetag(epoch)
         else:
-            l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd, fn2))
+            l2 = "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2))
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)
         l = [l1, l2, l3] + ["-" + e for e in a]
     else:
@@ -190,8 +197,8 @@
         if not l:
             return ""
 
-        l.insert(0, "--- a/%s%s" % (fn1, datetag(ad, fn1)))
-        l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd, fn2)))
+        l.insert(0, "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)))
+        l.insert(1, "+++ %s%s%s" % (bprefix, fn2, datetag(bd, fn2)))
 
     for ln in xrange(len(l)):
         if l[ln][-1] != '\n':
--- a/tests/test-diff-unified.t	Thu Nov 13 00:13:48 2014 -0800
+++ b/tests/test-diff-unified.t	Wed Nov 12 23:29:14 2014 -0800
@@ -93,8 +93,8 @@
 
   $ hg --config diff.noprefix=True diff --nodates
   diff -r cf9f4ba66af2 a
-  --- a/a
-  +++ b/a
+  --- a
+  +++ a
   @@ -2,7 +2,7 @@
    c
    a
@@ -106,8 +106,8 @@
    c
   $ hg diff --noprefix --nodates
   diff -r cf9f4ba66af2 a
-  --- a/a
-  +++ b/a
+  --- a
+  +++ a
   @@ -2,7 +2,7 @@
    c
    a
@@ -135,8 +135,8 @@
    c
   $ HGPLAIN=1 hg diff --noprefix --nodates
   diff -r cf9f4ba66af2 a
-  --- a/a
-  +++ b/a
+  --- a
+  +++ a
   @@ -2,7 +2,7 @@
    c
    a
@@ -235,8 +235,8 @@
   diff --git a/f1 b/f 1
   rename from f1
   rename to f 1
-  --- a/f1
-  +++ b/f 1	
+  --- f1
+  +++ f 1	
   @@ -1,1 +1,1 @@
   -a
   +b
@@ -256,8 +256,8 @@
   diff --git a/f1 b/f 1
   rename from f1
   rename to f 1
-  --- a/f1
-  +++ b/f 1	
+  --- f1
+  +++ f 1	
   @@ -1,1 +1,1 @@
   -a
   +b