changeset 264:4c1d7072d5cd

Attempt to make diff deal with null sources properly -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Attempt to make diff deal with null sources properly manifest hash: 7766ed2b885640157b93474b6e42573ec061fcfb -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCpJsdywK+sNU5EO8RAr5gAJ9sIik+3FDyI8UvIvrWlku4QgMZWQCcDFvh MvtqY8pFYTFLp7tM2zzTlu4= =a0oy -----END PGP SIGNATURE-----
author mpm@selenic.com
date Mon, 06 Jun 2005 10:51:09 -0800
parents e8eb427c6d71
children 7ca05593bd30
files mercurial/commands.py mercurial/mdiff.py
diffstat 2 files changed, 19 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Jun 05 10:50:03 2005 -0800
+++ b/mercurial/commands.py	Mon Jun 06 10:51:09 2005 -0800
@@ -61,12 +61,12 @@
         tn = read(f)
         sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
     for f in a:
-        to = ""
+        to = None
         tn = read(f)
         sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
     for f in d:
         to = repo.file(f).read(mmap[f])
-        tn = ""
+        tn = None
         sys.stdout.write(mdiff.unidiff(to, date1, tn, date2, f))
     
 def help(ui, cmd=None):
--- a/mercurial/mdiff.py	Sun Jun 05 10:50:03 2005 -0800
+++ b/mercurial/mdiff.py	Mon Jun 06 10:51:09 2005 -0800
@@ -10,9 +10,23 @@
 
 def unidiff(a, ad, b, bd, fn):
     if not a and not b: return ""
-    a = a.splitlines(1)
-    b = b.splitlines(1)
-    l = list(difflib.unified_diff(a, b, "a/" + fn, "b/" + fn, ad, bd))
+
+    if a == None:
+        b = b.splitlines(1)
+        l1 = "--- %s\t%s\n" % ("/dev/null", 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:
+        a = a.splitlines(1)
+        l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
+        l2 = "+++ %s\t%s\n" % ("/dev/null", bd)
+        l3 = "@@ -1,%d +0,0 @@\n" % len(a)
+        l = [l1, l2, l3] + ["-" + e for e in a]
+    else:
+        a = a.splitlines(1)
+        b = b.splitlines(1)
+        l = list(difflib.unified_diff(a, b, "a/" + fn, "b/" + fn, ad, bd))
 
     for ln in xrange(len(l)):
         if l[ln][-1] != '\n':