[Pkg-bazaar-commits] ./bzr/unstable r826: - Actually merge unsynchronized regions. Woot!
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:13:41 UTC 2009
------------------------------------------------------------
revno: 826
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Tue 2005-07-05 18:20:41 +1000
message:
- Actually merge unsynchronized regions. Woot!
modified:
bzrlib/merge3.py
bzrlib/selftest/testmerge3.py
-------------- next part --------------
=== modified file 'bzrlib/merge3.py'
--- a/bzrlib/merge3.py 2005-07-05 08:09:30 +0000
+++ b/bzrlib/merge3.py 2005-07-05 08:20:41 +0000
@@ -101,13 +101,37 @@
assert matchlen == (aend - amatch)
assert matchlen == (bend - bmatch)
- if amatch > ia: # or bmatch > ib:
- # got an unmatched region; work out if either
- # alternative is the same as the base
-
- # kludge: return the whole thing as inserted into A
- yield 'a', ia, amatch
+ len_a = amatch - ia
+ len_b = bmatch - ib
+ len_base = zmatch - iz
+ assert len_a >= 0
+ assert len_b >= 0
+ assert len_base >= 0
+
+ if len_a or len_b:
+ lines_base = self.base[iz:zmatch]
+ lines_a = self.a[ia:amatch]
+ lines_b = self.b[ib:bmatch]
+
+ # TODO: check the len just as a shortcut
+ equal_a = (lines_a == lines_base)
+ equal_b = (lines_b == lines_base)
+
+ if equal_a and not equal_b:
+ yield 'b', ib, bmatch
+ elif equal_b and not equal_a:
+ yield 'a', ia, amatch
+ elif not equal_a and not equal_b:
+ yield 'conflict', ia, amatch, ib, bmatch
+ else:
+ assert 0
+
ia = amatch
+ ib = bmatch
+ iz = zmatch
+
+ # if the same part of the base was deleted on both sides
+ # that's OK, we can just skip it.
if matchlen > 0:
=== modified file 'bzrlib/selftest/testmerge3.py'
--- a/bzrlib/selftest/testmerge3.py 2005-07-05 08:09:30 +0000
+++ b/bzrlib/selftest/testmerge3.py 2005-07-05 08:20:41 +0000
@@ -87,6 +87,11 @@
(1,2, 2,3, 1,2),
(2,2, 3,3, 2,2),])
+ self.assertEquals(list(m3.merge_regions()),
+ [('unchanged', 0, 1),
+ ('a', 1, 2),
+ ('unchanged', 1, 2),])
+
@@ -105,6 +110,11 @@
(1,2, 2,3, 2,3),
(2,2, 3,3, 3,3),])
+ self.assertEquals(list(m3.merge_regions()),
+ [('unchanged', 0,1),
+ ('conflict', 1,2, 1,2),
+ ('unchanged', 1,2)])
+
class ReplaceClash(TestBase):
More information about the Pkg-bazaar-commits
mailing list