# HG changeset patch # User Dustin Sallings # Date 2007-11-01 19:17:59 # Node ID e5eedd74e70f7f02621dc8dcff52cb35ce9a08d2 # Parent 003d1f174fe1ad254a334b58faf4441a069a817a Use both the from and to name in mdiff.unidiff. This fixes a compatibility issue with git diffs. * * * diff --git a/contrib/churn.py b/contrib/churn.py --- a/contrib/churn.py +++ b/contrib/churn.py @@ -43,7 +43,7 @@ def __gather(ui, repo, node1, node2): 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: diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -873,7 +873,8 @@ def debuginstall(ui): 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 = {} diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py --- a/mercurial/mdiff.py +++ b/mercurial/mdiff.py @@ -59,11 +59,11 @@ def wsclean(opts, text): 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 @@ def unidiff(a, ad, b, bd, fn, r=None, op 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 @@ def unidiff(a, ad, b, bd, fn, r=None, op 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) diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1230,6 +1230,7 @@ def diff(repo, node1=None, node2=None, f 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 @@ def diff(repo, node1=None, node2=None, f 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 @@ def diff(repo, node1=None, node2=None, f 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) diff --git a/tests/test-git-export.out b/tests/test-git-export.out --- a/tests/test-git-export.out +++ b/tests/test-git-export.out @@ -33,7 +33,7 @@ old mode 100755 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 @@ rename to dst2 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 @@ rename to bar 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 @@ rename to foo 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 @@ rename to bar diff --git a/bar b/foo rename from bar rename to foo ---- a/foo +--- a/bar +++ b/foo @@ -1,3 +1,1 @@ a a