[Pkg-bazaar-commits] ./bzr/unstable r838: - Merge3.find_sync_regions() - avoid problems with iters on python2.3 by
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:21:12 UTC 2009
------------------------------------------------------------
revno: 838
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Wed 2005-07-06 11:04:08 +1000
message:
- Merge3.find_sync_regions() - avoid problems with iters on python2.3 by
just stepping through arrays; also make this return a list rather than
being a generator.
Thanks very much to John for the report and help debugging.
modified:
bzrlib/merge3.py
-------------- next part --------------
=== modified file 'bzrlib/merge3.py'
--- a/bzrlib/merge3.py 2005-07-05 12:52:34 +0000
+++ b/bzrlib/merge3.py 2005-07-06 01:04:08 +0000
@@ -197,6 +197,8 @@
iz = ia = ib = 0
for zmatch, zend, amatch, aend, bmatch, bend in self.find_sync_regions():
+ #print 'match base [%d:%d]' % (zmatch, zend)
+
matchlen = zend - zmatch
assert matchlen >= 0
assert matchlen == (aend - amatch)
@@ -209,6 +211,8 @@
assert len_b >= 0
assert len_base >= 0
+ #print 'unmatched a=%d, b=%d' % (len_a, len_b)
+
if len_a or len_b:
lines_base = self.base[iz:zmatch]
lines_a = self.a[ia:amatch]
@@ -260,13 +264,19 @@
always a zero-length sync region at the end of all the files.
"""
from difflib import SequenceMatcher
- aiter = iter(SequenceMatcher(None, self.base, self.a).get_matching_blocks())
- biter = iter(SequenceMatcher(None, self.base, self.b).get_matching_blocks())
-
- abase, amatch, alen = aiter.next()
- bbase, bmatch, blen = biter.next()
-
- while aiter and biter:
+
+ ia = ib = 0
+ amatches = SequenceMatcher(None, self.base, self.a).get_matching_blocks()
+ bmatches = SequenceMatcher(None, self.base, self.b).get_matching_blocks()
+ len_a = len(amatches)
+ len_b = len(bmatches)
+
+ sl = []
+
+ while ia < len_a and ib < len_b:
+ abase, amatch, alen = amatches[ia]
+ bbase, bmatch, blen = bmatches[ib]
+
# there is an unconflicted block at i; how long does it
# extend? until whichever one ends earlier.
i = intersect((abase, abase+alen), (bbase, bbase+blen))
@@ -289,23 +299,25 @@
assert self.base[intbase:intend] == self.a[asub:aend], \
(self.base[intbase:intend], self.a[asub:aend])
-
+
assert self.base[intbase:intend] == self.b[bsub:bend]
- yield (intbase, intend,
- asub, aend,
- bsub, bend)
+ sl.append((intbase, intend,
+ asub, aend,
+ bsub, bend))
# advance whichever one ends first in the base text
if (abase + alen) < (bbase + blen):
- abase, amatch, alen = aiter.next()
+ ia += 1
else:
- bbase, bmatch, blen = biter.next()
-
+ ib += 1
+
intbase = len(self.base)
abase = len(self.a)
bbase = len(self.b)
- yield (intbase, intbase, abase, abase, bbase, bbase)
+ sl.append((intbase, intbase, abase, abase, bbase, bbase))
+
+ return sl
@@ -350,6 +362,9 @@
m3 = Merge3(base, a, b)
+ #for sr in m3.find_sync_regions():
+ # print sr
+
# sys.stdout.writelines(m3.merge_lines(name_a=argv[1], name_b=argv[3]))
sys.stdout.writelines(m3.merge_annotated())
More information about the Pkg-bazaar-commits
mailing list