Use both the from and to name in mdiff.unidiff.
authorDustin Sallings <dustin@spy.net>
Thu, 01 Nov 2007 12:17:59 -0700
changeset 5482 e5eedd74e70f
parent 5481 003d1f174fe1
child 5483 ec2cc1dadbf7
child 5500 43bb67f585f2
Use both the from and to name in mdiff.unidiff. This fixes a compatibility issue with git diffs. * * *
contrib/churn.py
mercurial/commands.py
mercurial/mdiff.py
mercurial/patch.py
tests/test-git-export.out
--- a/contrib/churn.py	Thu Nov 01 12:05:14 2007 +0100
+++ b/contrib/churn.py	Thu Nov 01 12:17:59 2007 -0700
@@ -43,7 +43,7 @@
         to = mmap1 and repo.file(f).read(mmap1[f]) or None
         tn = mmap2 and repo.file(f).read(mmap2[f]) or None
 
-        diff = mdiff.unidiff(to, "", tn, "", f).split("\n")
+        diff = mdiff.unidiff(to, "", tn, "", f, f).split("\n")
 
         for line in diff:
             if not line:
--- a/mercurial/commands.py	Thu Nov 01 12:05:14 2007 +0100
+++ b/mercurial/commands.py	Thu Nov 01 12:17:59 2007 -0700
@@ -873,7 +873,8 @@
     a = "1\n2\n3\n4\n"
     b = "1\n2\n3\ninsert\n4\n"
     fa = writetemp(a)
-    d = mdiff.unidiff(a, None, b, None, os.path.basename(fa))
+    d = mdiff.unidiff(a, None, b, None, os.path.basename(fa),
+        os.path.basename(fa))
     fd = writetemp(d)
 
     files = {}
--- a/mercurial/mdiff.py	Thu Nov 01 12:05:14 2007 +0100
+++ b/mercurial/mdiff.py	Thu Nov 01 12:17:59 2007 -0700
@@ -59,11 +59,11 @@
         text = re.sub('\n+', '', text)
     return text
 
-def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts):
+def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts):
     def datetag(date, addtab=True):
         if not opts.git and not opts.nodates:
             return '\t%s\n' % date
-        if addtab and ' ' in fn:
+        if addtab and ' ' in fn1:
             return '\t\n'
         return '\n'
 
@@ -76,29 +76,29 @@
             return md5.new(v).digest()
         if a and b and len(a) == len(b) and h(a) == h(b):
             return ""
-        l = ['Binary file %s has changed\n' % fn]
+        l = ['Binary file %s has changed\n' % fn1]
     elif not a:
         b = splitnewlines(b)
         if a is None:
             l1 = '--- /dev/null%s' % datetag(epoch, False)
         else:
-            l1 = "--- %s%s" % ("a/" + fn, datetag(ad))
-        l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
+            l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
+        l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
         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/" + fn, datetag(ad))
+        l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
         if b is None:
             l2 = '+++ /dev/null%s' % datetag(epoch, False)
         else:
-            l2 = "+++ %s%s" % ("b/" + fn, datetag(bd))
+            l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
         l3 = "@@ -1,%d +0,0 @@\n" % len(a)
         l = [l1, l2, l3] + ["-" + e for e in a]
     else:
         al = splitnewlines(a)
         bl = splitnewlines(b)
-        l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, opts=opts))
+        l = list(bunidiff(a, b, al, bl, "a/" + fn1, "b/" + fn2, opts=opts))
         if not l: return ""
         # difflib uses a space, rather than a tab
         l[0] = "%s%s" % (l[0][:-2], datetag(ad))
@@ -110,7 +110,7 @@
 
     if r:
         l.insert(0, "diff %s %s\n" %
-                    (' '.join(["-r %s" % rev for rev in r]), fn))
+                    (' '.join(["-r %s" % rev for rev in r]), fn1))
 
     return "".join(l)
 
--- a/mercurial/patch.py	Thu Nov 01 12:05:14 2007 +0100
+++ b/mercurial/patch.py	Thu Nov 01 12:17:59 2007 -0700
@@ -1230,6 +1230,7 @@
             to = getfilectx(f, ctx1).data()
         if f not in removed:
             tn = getfilectx(f, ctx2).data()
+        a, b = f, f
         if opts.git:
             def gitmode(x, l):
                 return l and '120000' or (x and '100755' or '100644')
@@ -1238,7 +1239,6 @@
                     header.append('old mode %s\n' % omode)
                     header.append('new mode %s\n' % nmode)
 
-            a, b = f, f
             if f in added:
                 mode = gitmode(execf2(f), linkf2(f))
                 if f in copied:
@@ -1278,7 +1278,7 @@
                 text = mdiff.unidiff(to, date1,
                                     # ctx2 date may be dynamic
                                     tn, util.datestr(ctx2.date()),
-                                    f, r, opts=opts)
+                                    a, b, r, opts=opts)
             if text or len(header) > 1:
                 fp.write(''.join(header))
             fp.write(text)
--- a/tests/test-git-export.out	Thu Nov 01 12:05:14 2007 +0100
+++ b/tests/test-git-export.out	Thu Nov 01 12:17:59 2007 -0700
@@ -33,7 +33,7 @@
 new mode 100644
 rename from src
 rename to dst
---- a/dst
+--- a/src
 +++ b/dst
 @@ -3,3 +3,4 @@ 3
  3
@@ -84,7 +84,7 @@
 diff --git a/foo b/bar
 rename from foo
 rename to bar
---- a/bar
+--- a/foo
 +++ b/bar
 @@ -1,2 +1,3 @@ a
  a
@@ -94,7 +94,7 @@
 diff --git a/bar b/foo
 rename from bar
 rename to foo
---- a/foo
+--- a/bar
 +++ b/foo
 @@ -1,3 +1,2 @@ a
  a
@@ -105,7 +105,7 @@
 diff --git a/foo b/bar
 rename from foo
 rename to bar
---- a/bar
+--- a/foo
 +++ b/bar
 @@ -1,1 +1,3 @@ a
  a
@@ -115,7 +115,7 @@
 diff --git a/bar b/foo
 rename from bar
 rename to foo
---- a/foo
+--- a/bar
 +++ b/foo
 @@ -1,3 +1,1 @@ a
  a