~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-01-14 01:40:02 UTC
  • mfrom: (3177.1.1 ianc-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20080114014002-pz5tya37urp1n3fk
Fix typos of Firefox and OpenOffice.org in docs (Matt Nordhoff)

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
    Given BASE, OTHER, THIS, tries to produce a combined text
68
68
    incorporating the changes from both BASE->OTHER and BASE->THIS.
69
69
    All three will typically be sequences of lines."""
70
 
    def __init__(self, base, a, b, is_cherrypick=False):
 
70
    def __init__(self, base, a, b):
71
71
        check_text_lines(base)
72
72
        check_text_lines(a)
73
73
        check_text_lines(b)
74
74
        self.base = base
75
75
        self.a = a
76
76
        self.b = b
77
 
        self.is_cherrypick = is_cherrypick
 
77
 
 
78
 
78
79
 
79
80
    def merge_lines(self,
80
81
                    name_a=None,
129
130
                yield end_marker + newline
130
131
            else:
131
132
                raise ValueError(what)
 
133
        
 
134
        
 
135
 
 
136
 
132
137
 
133
138
    def merge_annotated(self):
134
139
        """Return merge with conflicts, showing origin of lines.
156
161
                yield '>>>>\n'
157
162
            else:
158
163
                raise ValueError(what)
 
164
        
 
165
        
 
166
 
 
167
 
159
168
 
160
169
    def merge_groups(self):
161
170
        """Yield sequence of line groups.  Each one is a tuple:
191
200
            else:
192
201
                raise ValueError(what)
193
202
 
 
203
 
194
204
    def merge_regions(self):
195
205
        """Return sequences of matching and conflicting regions.
196
206
 
240
250
 
241
251
            if len_a or len_b:
242
252
                # try to avoid actually slicing the lists
 
253
                equal_a = compare_range(self.a, ia, amatch,
 
254
                                        self.base, iz, zmatch)
 
255
                equal_b = compare_range(self.b, ib, bmatch,
 
256
                                        self.base, iz, zmatch)
243
257
                same = compare_range(self.a, ia, amatch,
244
258
                                     self.b, ib, bmatch)
245
259
 
246
260
                if same:
247
261
                    yield 'same', ia, amatch
 
262
                elif equal_a and not equal_b:
 
263
                    yield 'b', ib, bmatch
 
264
                elif equal_b and not equal_a:
 
265
                    yield 'a', ia, amatch
 
266
                elif not equal_a and not equal_b:
 
267
                    yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
248
268
                else:
249
 
                    equal_a = compare_range(self.a, ia, amatch,
250
 
                                            self.base, iz, zmatch)
251
 
                    equal_b = compare_range(self.b, ib, bmatch,
252
 
                                            self.base, iz, zmatch)
253
 
                    if equal_a and not equal_b:
254
 
                        yield 'b', ib, bmatch
255
 
                    elif equal_b and not equal_a:
256
 
                        yield 'a', ia, amatch
257
 
                    elif not equal_a and not equal_b:
258
 
                        if self.is_cherrypick:
259
 
                            for node in self._refine_cherrypick_conflict(
260
 
                                                    iz, zmatch, ia, amatch,
261
 
                                                    ib, bmatch):
262
 
                                yield node
263
 
                        else:
264
 
                            yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
265
 
                    else:
266
 
                        raise AssertionError("can't handle a=b=base but unmatched")
 
269
                    raise AssertionError("can't handle a=b=base but unmatched")
267
270
 
268
271
                ia = amatch
269
272
                ib = bmatch
272
275
            # if the same part of the base was deleted on both sides
273
276
            # that's OK, we can just skip it.
274
277
 
 
278
                
275
279
            if matchlen > 0:
276
280
                assert ia == amatch
277
281
                assert ib == bmatch
281
285
                iz = zend
282
286
                ia = aend
283
287
                ib = bend
284
 
 
285
 
    def _refine_cherrypick_conflict(self, zstart, zend, astart, aend, bstart, bend):
286
 
        """When cherrypicking b => a, ignore matches with b and base."""
287
 
        # Do not emit regions which match, only regions which do not match
288
 
        matches = bzrlib.patiencediff.PatienceSequenceMatcher(None,
289
 
            self.base[zstart:zend], self.b[bstart:bend]).get_matching_blocks()
290
 
        last_base_idx = 0
291
 
        last_b_idx = 0
292
 
        last_b_idx = 0
293
 
        yielded_a = False
294
 
        for base_idx, b_idx, match_len in matches:
295
 
            conflict_z_len = base_idx - last_base_idx
296
 
            conflict_b_len = b_idx - last_b_idx
297
 
            if conflict_b_len == 0: # There are no lines in b which conflict,
298
 
                                    # so skip it
299
 
                pass
300
 
            else:
301
 
                if yielded_a:
302
 
                    yield ('conflict',
303
 
                           zstart + last_base_idx, zstart + base_idx,
304
 
                           aend, aend, bstart + last_b_idx, bstart + b_idx)
305
 
                else:
306
 
                    # The first conflict gets the a-range
307
 
                    yielded_a = True
308
 
                    yield ('conflict', zstart + last_base_idx, zstart +
309
 
                    base_idx,
310
 
                           astart, aend, bstart + last_b_idx, bstart + b_idx)
311
 
            last_base_idx = base_idx + match_len
312
 
            last_b_idx = b_idx + match_len
313
 
        if last_base_idx != zend - zstart or last_b_idx != bend - bstart:
314
 
            if yielded_a:
315
 
                yield ('conflict', zstart + last_base_idx, zstart + base_idx,
316
 
                       aend, aend, bstart + last_b_idx, bstart + b_idx)
317
 
            else:
318
 
                # The first conflict gets the a-range
319
 
                yielded_a = True
320
 
                yield ('conflict', zstart + last_base_idx, zstart + base_idx,
321
 
                       astart, aend, bstart + last_b_idx, bstart + b_idx)
322
 
        if not yielded_a:
323
 
            yield ('conflict', zstart, zend, astart, aend, bstart, bend)
 
288
    
324
289
 
325
290
    def reprocess_merge_regions(self, merge_regions):
326
291
        """Where there are conflict regions, remove the agreed lines.
353
318
            if reg is not None:
354
319
                yield reg
355
320
 
 
321
 
356
322
    @staticmethod
357
323
    def mismatch_region(next_a, region_ia,  next_b, region_ib):
358
324
        if next_a < region_ia or next_b < region_ib:
359
325
            return 'conflict', None, None, next_a, region_ia, next_b, region_ib
 
326
            
360
327
 
361
328
    def find_sync_regions(self):
362
329
        """Return a list of sync regions, where both descendents match the base.
421
388
 
422
389
        return sl
423
390
 
 
391
 
 
392
 
424
393
    def find_unconflicted(self):
425
394
        """Return a list of ranges in base that are not conflicted."""
426
395
        am = bzrlib.patiencediff.PatienceSequenceMatcher(