~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 01:04:08 UTC
  • Revision ID: mbp@sourcefrog.net-20050706010408-6a5f429ee8eb3824
- 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.

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
 
 
59
46
 
60
47
class Merge3(object):
61
48
    """3-way merge of texts.
76
63
    def merge_lines(self,
77
64
                    name_a=None,
78
65
                    name_b=None,
79
 
                    start_marker='<<<<<<<',
80
 
                    mid_marker='=======',
81
 
                    end_marker='>>>>>>>',
 
66
                    start_marker='<<<<<<<<',
 
67
                    mid_marker='========',
 
68
                    end_marker='>>>>>>>>',
82
69
                    show_base=False):
83
70
        """Return merge in cvs-like form.
84
71
        """
227
214
            #print 'unmatched a=%d, b=%d' % (len_a, len_b)
228
215
 
229
216
            if len_a or len_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)
 
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)
237
228
 
238
229
                if same:
239
230
                    yield 'same', ia, amatch
244
235
                elif not equal_a and not equal_b:
245
236
                    yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
246
237
                else:
247
 
                    raise AssertionError("can't handle a=b=base but unmatched")
 
238
                    assert 0
248
239
 
249
240
                ia = amatch
250
241
                ib = bmatch