Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/mdiff.py @ 318:2819f63b16bf
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-----
author | mpm@selenic.com |
---|---|
date | Sun, 12 Jun 2005 10:20:07 -0800 |
parents | b18ce742566a |
children | ad87e19854a6 27d08c0c2a7e |
comparison
equal
deleted
inserted
replaced
317:b18ce742566a | 318:2819f63b16bf |
---|---|
41 def textdiff(a, b): | 41 def textdiff(a, b): |
42 return diff(a.splitlines(1), b.splitlines(1)) | 42 return diff(a.splitlines(1), b.splitlines(1)) |
43 | 43 |
44 def sortdiff(a, b): | 44 def sortdiff(a, b): |
45 la = lb = 0 | 45 la = lb = 0 |
46 lena = len(a) | 46 |
47 lenb = len(b) | |
48 while 1: | 47 while 1: |
49 am, bm, = la, lb | 48 if la >= len(a) or lb >= len(b): break |
50 while lb < lenb and la < len and a[la] == b[lb] : | 49 if b[lb] < a[la]: |
50 si = lb | |
51 while lb < len(b) and b[lb] < a[la] : lb += 1 | |
52 yield "insert", la, la, si, lb | |
53 elif a[la] < b[lb]: | |
54 si = la | |
55 while la < len(a) and a[la] < b[lb]: la += 1 | |
56 yield "delete", si, la, lb, lb | |
57 else: | |
51 la += 1 | 58 la += 1 |
52 lb += 1 | 59 lb += 1 |
53 if la>am: yield (am, bm, la-am) | 60 |
54 while lb < lenb and b[lb] < a[la]: lb += 1 | 61 if lb < len(b): |
55 if lb>=lenb: break | 62 yield "insert", la, la, lb, len(b) |
56 while la < lena and b[lb] > a[la]: la += 1 | 63 |
57 if la>=lena: break | 64 if la < len(a): |
58 yield (lena, lenb, 0) | 65 yield "delete", la, len(a), lb, lb |
59 | 66 |
60 def diff(a, b, sorted=0): | 67 def diff(a, b, sorted=0): |
61 if not a: | |
62 s = "".join(b) | |
63 return s and (struct.pack(">lll", 0, 0, len(s)) + s) | |
64 | |
65 bin = [] | 68 bin = [] |
66 p = [0] | 69 p = [0] |
67 for i in a: p.append(p[-1] + len(i)) | 70 for i in a: p.append(p[-1] + len(i)) |
68 | 71 |
69 if sorted: | 72 if sorted: |
71 d = sortdiff(a, b) | 74 d = sortdiff(a, b) |
72 except: | 75 except: |
73 print a, b | 76 print a, b |
74 raise | 77 raise |
75 else: | 78 else: |
76 d = difflib.SequenceMatcher(None, a, b).get_matching_blocks() | 79 d = difflib.SequenceMatcher(None, a, b).get_opcodes() |
77 la = 0 | 80 |
78 lb = 0 | 81 for o, m, n, s, t in d: |
79 for am, bm, size in d: | 82 if o == 'equal': continue |
80 s = "".join(b[lb:bm]) | 83 s = "".join(b[s:t]) |
81 if am > la or s: | 84 bin.append(struct.pack(">lll", p[m], p[n], len(s)) + s) |
82 bin.append(struct.pack(">lll", p[la], p[am], len(s)) + s) | 85 |
83 la = am + size | |
84 lb = bm + size | |
85 | |
86 return "".join(bin) | 86 return "".join(bin) |
87 | 87 |
88 def patchtext(bin): | 88 def patchtext(bin): |
89 pos = 0 | 89 pos = 0 |
90 t = [] | 90 t = [] |