changeset 1723:fde8fb2cbede

Fix diff against an empty file (issue124) and add a test for this.
author Thomas Arendsen Hein <thomas@intevation.de>
date Wed, 15 Feb 2006 14:22:16 +0100
parents 681c5c211b92
children 49004ad10cde ace6d26f78f1
files mercurial/mdiff.py tests/test-diffdir tests/test-diffdir.out
diffstat 3 files changed, 24 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/mdiff.py	Wed Feb 15 04:37:47 2006 +0100
+++ b/mercurial/mdiff.py	Wed Feb 15 14:22:16 2006 +0100
@@ -18,16 +18,22 @@
 
     if not text and (util.binary(a) or util.binary(b)):
         l = ['Binary file %s has changed\n' % fn]
-    elif a == None:
+    elif not a:
         b = b.splitlines(1)
-        l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
+        if a is None:
+            l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
+        else:
+            l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
         l2 = "+++ %s\t%s\n" % ("b/" + fn, bd)
         l3 = "@@ -0,0 +1,%d @@\n" % len(b)
         l = [l1, l2, l3] + ["+" + e for e in b]
-    elif b == None:
+    elif not b:
         a = a.splitlines(1)
         l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
-        l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
+        if b is None:
+            l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
+        else:
+            l2 = "+++ %s\t%s\n" % ("b/" + fn, bd)
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)
         l = [l1, l2, l3] + ["-" + e for e in a]
     else:
--- a/tests/test-diffdir	Wed Feb 15 04:37:47 2006 +0100
+++ b/tests/test-diffdir	Wed Feb 15 14:22:16 2006 +0100
@@ -12,3 +12,7 @@
 
 hg diff -r tip | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
                      -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
+
+echo foo > a
+hg diff | sed -e "s/\(+++ [a-zA-Z0-9_/.-]*\).*/\1/" \
+              -e "s/\(--- [a-zA-Z0-9_/.-]*\).*/\1/"
--- a/tests/test-diffdir.out	Wed Feb 15 04:37:47 2006 +0100
+++ b/tests/test-diffdir.out	Wed Feb 15 14:22:16 2006 +0100
@@ -8,3 +8,13 @@
 +++ b/b
 @@ -0,0 +1,1 @@
 +123
+diff -r 3903775176ed a
+--- a/a
++++ b/a
+@@ -0,0 +1,1 @@
++foo
+diff -r 3903775176ed b
+--- /dev/null
++++ b/b
+@@ -0,0 +1,1 @@
++123