patch.trydiff: add support for noprefix
authorSiddharth Agarwal <sid0@fb.com>
Wed, 12 Nov 2014 23:50:21 -0800
changeset 23300 f8b5c3e77d4b
parent 23299 1f510efcd5f3
child 23301 c10dc5568069
patch.trydiff: add support for noprefix
mercurial/patch.py
tests/test-diff-unified.t
--- a/mercurial/patch.py	Wed Nov 12 23:29:14 2014 -0800
+++ b/mercurial/patch.py	Wed Nov 12 23:50:21 2014 -0800
@@ -1738,9 +1738,15 @@
         s.update(text)
         return s.hexdigest()
 
+    if opts.noprefix:
+        aprefix = bprefix = ''
+    else:
+        aprefix = 'a/'
+        bprefix = 'b/'
+
     def diffline(a, b, revs):
         if opts.git:
-            line = 'diff --git a/%s b/%s\n' % (a, b)
+            line = 'diff --git %s%s %s%s\n' % (aprefix, a, bprefix, b)
         elif not repo.ui.quiet:
             if revs:
                 revinfo = ' '.join(["-r %s" % rev for rev in revs])
--- a/tests/test-diff-unified.t	Wed Nov 12 23:29:14 2014 -0800
+++ b/tests/test-diff-unified.t	Wed Nov 12 23:50:21 2014 -0800
@@ -232,7 +232,7 @@
 Git diff with noprefix
 
   $ hg --config diff.noprefix=True diff --git --nodates
-  diff --git a/f1 b/f 1
+  diff --git f1 f 1
   rename from f1
   rename to f 1
   --- f1
@@ -253,7 +253,7 @@
   -a
   +b
   $ HGPLAIN=1 hg diff --git --noprefix --nodates
-  diff --git a/f1 b/f 1
+  diff --git f1 f 1
   rename from f1
   rename to f 1
   --- f1