~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

Moved plan_merge into Weave

Show diffs side-by-side

added added

removed removed

Lines of Context:
394
394
        """Walk the names list."""
395
395
        return iter(self.versions())
396
396
 
397
 
    def plan_merge(versionedfile, ver_a, ver_b):
398
 
        return PlanWeaveMerge.plan_merge(versionedfile, ver_a, ver_b)
399
 
 
 
397
    def plan_merge(self, ver_a, ver_b):
 
398
        raise NotImplementedError(VersionedFile.plan_merge)
 
399
        
400
400
    def weave_merge(self, plan, a_marker=TextMerge.A_MARKER, 
401
401
                    b_marker=TextMerge.B_MARKER):
402
402
        return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0]
413
413
        TextMerge.__init__(self, a_marker, b_marker)
414
414
        self.plan = plan
415
415
 
416
 
    @staticmethod
417
 
    def plan_merge(versionedfile, ver_a, ver_b):
418
 
        """Return pseudo-annotation indicating how the two versions merge.
419
 
 
420
 
        This is computed between versions a and b and their common
421
 
        base.
422
 
 
423
 
        Weave lines present in none of them are skipped entirely.
424
 
        """
425
 
        inc_a = set(versionedfile.get_ancestry([ver_a]))
426
 
        inc_b = set(versionedfile.get_ancestry([ver_b]))
427
 
        inc_c = inc_a & inc_b
428
 
 
429
 
        for lineno, insert, deleteset, line in\
430
 
            versionedfile.walk([ver_a, ver_b]):
431
 
            if deleteset & inc_c:
432
 
                # killed in parent; can't be in either a or b
433
 
                # not relevant to our work
434
 
                yield 'killed-base', line
435
 
            elif insert in inc_c:
436
 
                # was inserted in base
437
 
                killed_a = bool(deleteset & inc_a)
438
 
                killed_b = bool(deleteset & inc_b)
439
 
                if killed_a and killed_b:
440
 
                    yield 'killed-both', line
441
 
                elif killed_a:
442
 
                    yield 'killed-a', line
443
 
                elif killed_b:
444
 
                    yield 'killed-b', line
445
 
                else:
446
 
                    yield 'unchanged', line
447
 
            elif insert in inc_a:
448
 
                if deleteset & inc_a:
449
 
                    yield 'ghost-a', line
450
 
                else:
451
 
                    # new in A; not in B
452
 
                    yield 'new-a', line
453
 
            elif insert in inc_b:
454
 
                if deleteset & inc_b:
455
 
                    yield 'ghost-b', line
456
 
                else:
457
 
                    yield 'new-b', line
458
 
            else:
459
 
                # not in either revision
460
 
                yield 'irrelevant', line
461
 
 
462
 
        yield 'unchanged', ''           # terminator
463
416
 
464
417
    def _merge_struct(self):
465
418
        lines_a = []
513
466
 
514
467
    def __init__(self, versionedfile, ver_a, ver_b, 
515
468
        a_marker=PlanWeaveMerge.A_MARKER, b_marker=PlanWeaveMerge.B_MARKER):
516
 
        plan = self.plan_merge(versionedfile, ver_a, ver_b)
 
469
        plan = versionedfile.plan_merge(ver_a, ver_b)
517
470
        PlanWeaveMerge.__init__(self, plan, a_marker, b_marker)
518
471
 
519
472