/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/merge3.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-11-16 18:59:44 UTC
  • mfrom: (7143.15.15 more-cleanups)
  • Revision ID: breezy.the.bot@gmail.com-20181116185944-biefv1sub37qfybm
Sprinkle some PEP8iness.

Merged from https://code.launchpad.net/~jelmer/brz/more-cleanups/+merge/358611

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
class CantReprocessAndShowBase(errors.BzrError):
30
30
 
31
31
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
32
 
           "the relationship of conflicting lines to the base")
 
32
            "the relationship of conflicting lines to the base")
33
33
 
34
34
 
35
35
def intersect(ra, rb):
57
57
def compare_range(a, astart, aend, b, bstart, bend):
58
58
    """Compare a[astart:aend] == b[bstart:bend], without slicing.
59
59
    """
60
 
    if (aend-astart) != (bend-bstart):
 
60
    if (aend - astart) != (bend - bstart):
61
61
        return False
62
62
    for ia, ib in zip(range(astart, aend), range(bstart, bend)):
63
63
        if a[ia] != b[ib]:
248
248
            #   matchlen == (bend - bmatch)
249
249
            len_a = amatch - ia
250
250
            len_b = bmatch - ib
251
 
            len_base = zmatch - iz
252
251
            # invariants:
253
252
            # assert len_a >= 0
254
253
            # assert len_b >= 0
255
 
            # assert len_base >= 0
256
254
 
257
 
            #print 'unmatched a=%d, b=%d' % (len_a, len_b)
 
255
            # print 'unmatched a=%d, b=%d' % (len_a, len_b)
258
256
 
259
257
            if len_a or len_b:
260
258
                # try to avoid actually slicing the lists
275
273
                    elif not equal_a and not equal_b:
276
274
                        if self.is_cherrypick:
277
275
                            for node in self._refine_cherrypick_conflict(
278
 
                                                    iz, zmatch, ia, amatch,
279
 
                                                    ib, bmatch):
 
276
                                    iz, zmatch, ia, amatch,
 
277
                                    ib, bmatch):
280
278
                                yield node
281
279
                        else:
282
 
                            yield 'conflict', iz, zmatch, ia, amatch, ib, bmatch
 
280
                            yield ('conflict', iz, zmatch, ia, amatch, ib,
 
281
                                   bmatch)
283
282
                    else:
284
 
                        raise AssertionError("can't handle a=b=base but unmatched")
 
283
                        raise AssertionError(
 
284
                            "can't handle a=b=base but unmatched")
285
285
 
286
286
                ia = amatch
287
287
                ib = bmatch
301
301
                ia = aend
302
302
                ib = bend
303
303
 
304
 
    def _refine_cherrypick_conflict(self, zstart, zend, astart, aend, bstart, bend):
 
304
    def _refine_cherrypick_conflict(self, zstart, zend, astart, aend, bstart,
 
305
                                    bend):
305
306
        """When cherrypicking b => a, ignore matches with b and base."""
306
307
        # Do not emit regions which match, only regions which do not match
307
 
        matches = patiencediff.PatienceSequenceMatcher(None,
308
 
            self.base[zstart:zend], self.b[bstart:bend]).get_matching_blocks()
 
308
        matches = patiencediff.PatienceSequenceMatcher(
 
309
            None, self.base[zstart:zend], self.b[bstart:bend]
 
310
            ).get_matching_blocks()
309
311
        last_base_idx = 0
310
312
        last_b_idx = 0
311
313
        last_b_idx = 0
312
314
        yielded_a = False
313
315
        for base_idx, b_idx, match_len in matches:
314
 
            conflict_z_len = base_idx - last_base_idx
315
316
            conflict_b_len = b_idx - last_b_idx
316
 
            if conflict_b_len == 0: # There are no lines in b which conflict,
 
317
            if conflict_b_len == 0:  # There are no lines in b which conflict,
317
318
                                    # so skip it
318
319
                pass
319
320
            else:
325
326
                    # The first conflict gets the a-range
326
327
                    yielded_a = True
327
328
                    yield ('conflict', zstart + last_base_idx, zstart +
328
 
                    base_idx,
 
329
                           base_idx,
329
330
                           astart, aend, bstart + last_b_idx, bstart + b_idx)
330
331
            last_base_idx = base_idx + match_len
331
332
            last_b_idx = b_idx + match_len
355
356
            a_region = self.a[ia:amatch]
356
357
            b_region = self.b[ib:bmatch]
357
358
            matches = patiencediff.PatienceSequenceMatcher(
358
 
                    None, a_region, b_region).get_matching_blocks()
 
359
                None, a_region, b_region).get_matching_blocks()
359
360
            next_a = ia
360
361
            next_b = ib
361
362
            for region_ia, region_ib, region_len in matches[:-1]:
365
366
                                           region_ib)
366
367
                if reg is not None:
367
368
                    yield reg
368
 
                yield 'same', region_ia, region_len+region_ia
 
369
                yield 'same', region_ia, region_len + region_ia
369
370
                next_a = region_ia + region_len
370
371
                next_b = region_ib + region_len
371
372
            reg = self.mismatch_region(next_a, amatch, next_b, bmatch)
373
374
                yield reg
374
375
 
375
376
    @staticmethod
376
 
    def mismatch_region(next_a, region_ia,  next_b, region_ib):
 
377
    def mismatch_region(next_a, region_ia, next_b, region_ib):
377
378
        if next_a < region_ia or next_b < region_ib:
378
379
            return 'conflict', None, None, next_a, region_ia, next_b, region_ib
379
380
 
386
387
 
387
388
        ia = ib = 0
388
389
        amatches = patiencediff.PatienceSequenceMatcher(
389
 
                None, self.base, self.a).get_matching_blocks()
 
390
            None, self.base, self.a).get_matching_blocks()
390
391
        bmatches = patiencediff.PatienceSequenceMatcher(
391
 
                None, self.base, self.b).get_matching_blocks()
 
392
            None, self.base, self.b).get_matching_blocks()
392
393
        len_a = len(amatches)
393
394
        len_b = len(bmatches)
394
395
 
400
401
 
401
402
            # there is an unconflicted block at i; how long does it
402
403
            # extend?  until whichever one ends earlier.
403
 
            i = intersect((abase, abase+alen), (bbase, bbase+blen))
 
404
            i = intersect((abase, abase + alen), (bbase, bbase + blen))
404
405
            if i:
405
406
                intbase = i[0]
406
407
                intend = i[1]
441
442
    def find_unconflicted(self):
442
443
        """Return a list of ranges in base that are not conflicted."""
443
444
        am = patiencediff.PatienceSequenceMatcher(
444
 
                None, self.base, self.a).get_matching_blocks()
 
445
            None, self.base, self.a).get_matching_blocks()
445
446
        bm = patiencediff.PatienceSequenceMatcher(
446
 
                None, self.base, self.b).get_matching_blocks()
 
447
            None, self.base, self.b).get_matching_blocks()
447
448
 
448
449
        unc = []
449
450
 
477
478
 
478
479
    m3 = Merge3(base, a, b)
479
480
 
480
 
    #for sr in m3.find_sync_regions():
 
481
    # for sr in m3.find_sync_regions():
481
482
    #    print sr
482
483
 
483
484
    # sys.stdout.writelines(m3.merge_lines(name_a=argv[1], name_b=argv[3]))