[PATCH 7 of 8 V2] mdiff.unidiff: add support for noprefix

Siddharth Agarwal sid0 at fb.com
Thu Nov 13 17:08:52 CST 2014


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1415863754 28800
#      Wed Nov 12 23:29:14 2014 -0800
# Node ID 4b1e69979d7496f518ddd6a496cf45cfb212987f
# Parent  d7fcdbb45b8e76c527d6f45a3bba37135b9aefe1
mdiff.unidiff: add support for noprefix

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -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':
diff --git a/tests/test-diff-unified.t b/tests/test-diff-unified.t
--- a/tests/test-diff-unified.t
+++ b/tests/test-diff-unified.t
@@ -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


More information about the Mercurial-devel mailing list