~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Martin Pool
  • Date: 2005-07-06 04:09:02 UTC
  • Revision ID: mbp@sourcefrog.net-20050706040902-5b98f739e5ee1841
- avoid copying string lists when handling unmatched regions

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
        return None
44
44
 
45
45
 
 
46
def compare_range(a, astart, aend, b, bstart, bend):
 
47
    """Compare a[astart:aend] == b[bstart:bend], without slicing.
 
48
    """
 
49
    if (aend-astart) != (bend-bstart):
 
50
        return False
 
51
    for ia, ib in zip(xrange(astart, aend), xrange(bstart, bend)):
 
52
        if a[ia] != b[ib]:
 
53
            return False
 
54
    else:
 
55
        return True
 
56
        
 
57
 
 
58
 
46
59
 
47
60
class Merge3(object):
48
61
    """3-way merge of texts.
214
227
            #print 'unmatched a=%d, b=%d' % (len_a, len_b)
215
228
 
216
229
            if len_a or len_b:
217
 
                lines_base = self.base[iz:zmatch]
218
 
                lines_a = self.a[ia:amatch]
219
 
                lines_b = self.b[ib:bmatch]
220
 
 
221
 
                # we check the len just as a shortcut
222
 
                equal_a = (len_a == len_base
223
 
                           and lines_a == lines_base)
224
 
                equal_b = (len_b == len_base
225
 
                           and lines_b == lines_base)
226
 
                same = (len_a == len_b
227
 
                        and lines_a == lines_b)
 
230
                # try to avoid actually slicing the lists
 
231
                equal_a = compare_range(self.a, ia, amatch,
 
232
                                        self.base, iz, zmatch)
 
233
                equal_b = compare_range(self.b, ib, bmatch,
 
234
                                        self.base, iz, zmatch)
 
235
                same = compare_range(self.a, ia, amatch,
 
236
                                     self.b, ib, bmatch)
228
237
 
229
238
                if same:
230
239
                    yield 'same', ia, amatch
235
244
                elif not equal_a and not equal_b:
236
245
                    yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
237
246
                else:
238
 
                    assert 0
 
247
                    raise AssertionError("can't handle a=b=base but unmatched")
239
248
 
240
249
                ia = amatch
241
250
                ib = bmatch