# HG changeset patch # User mpm@selenic.com # Date 1118600407 28800 # Node ID 2819f63b16bfbb72125a18d2ce8a4c211753ef8a # Parent b18ce742566a5c13a140b1177c39b577bee778ff mdiff: revert grouping optimization for the time being -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 mdiff: revert grouping optimization for the time being This had trouble with Ted T'so import test while the original didn't. manifest hash: e2fc49b5277096bd4c5081558af5efe9964d5310 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCrHzXywK+sNU5EO8RArocAJwKlxrnyVpdYaKzgJG/b4gSVOYBTwCgkl2t zD807fsMULRDdDe1k9jVPcU= =Iivz -----END PGP SIGNATURE----- diff -r b18ce742566a -r 2819f63b16bf mercurial/mdiff.py --- a/mercurial/mdiff.py Sun Jun 12 10:18:32 2005 -0800 +++ b/mercurial/mdiff.py Sun Jun 12 10:20:07 2005 -0800 @@ -43,25 +43,28 @@ def sortdiff(a, b): la = lb = 0 - lena = len(a) - lenb = len(b) + while 1: - am, bm, = la, lb - while lb < lenb and la < len and a[la] == b[lb] : + if la >= len(a) or lb >= len(b): break + if b[lb] < a[la]: + si = lb + while lb < len(b) and b[lb] < a[la] : lb += 1 + yield "insert", la, la, si, lb + elif a[la] < b[lb]: + si = la + while la < len(a) and a[la] < b[lb]: la += 1 + yield "delete", si, la, lb, lb + else: la += 1 lb += 1 - if la>am: yield (am, bm, la-am) - while lb < lenb and b[lb] < a[la]: lb += 1 - if lb>=lenb: break - while la < lena and b[lb] > a[la]: la += 1 - if la>=lena: break - yield (lena, lenb, 0) + + if lb < len(b): + yield "insert", la, la, lb, len(b) + + if la < len(a): + yield "delete", la, len(a), lb, lb def diff(a, b, sorted=0): - if not a: - s = "".join(b) - return s and (struct.pack(">lll", 0, 0, len(s)) + s) - bin = [] p = [0] for i in a: p.append(p[-1] + len(i)) @@ -73,16 +76,13 @@ print a, b raise else: - d = difflib.SequenceMatcher(None, a, b).get_matching_blocks() - la = 0 - lb = 0 - for am, bm, size in d: - s = "".join(b[lb:bm]) - if am > la or s: - bin.append(struct.pack(">lll", p[la], p[am], len(s)) + s) - la = am + size - lb = bm + size - + d = difflib.SequenceMatcher(None, a, b).get_opcodes() + + for o, m, n, s, t in d: + if o == 'equal': continue + s = "".join(b[s:t]) + bin.append(struct.pack(">lll", p[m], p[n], len(s)) + s) + return "".join(bin) def patchtext(bin):