~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-19 08:36:50 UTC
  • mfrom: (1664.2.14 bzr.knitplanmerge)
  • Revision ID: pqm@pqm.ubuntu.com-20060419083650-f26d296f90d75d88
Implement plan_merge for knits

Show diffs side-by-side

added added

removed removed

Lines of Context:
395
395
        return iter(self.versions())
396
396
 
397
397
    def plan_merge(self, ver_a, ver_b):
 
398
        """Return pseudo-annotation indicating how the two versions merge.
 
399
 
 
400
        This is computed between versions a and b and their common
 
401
        base.
 
402
 
 
403
        Weave lines present in none of them are skipped entirely.
 
404
 
 
405
        Legend:
 
406
        killed-base Dead in base revision
 
407
        killed-both Killed in each revision
 
408
        killed-a    Killed in a
 
409
        killed-b    Killed in b
 
410
        unchanged   Alive in both a and b (possibly created in both)
 
411
        new-a       Created in a
 
412
        new-b       Created in b
 
413
        ghost-a     Killed in a, unborn in b    
 
414
        ghost-b     Killed in b, unborn in a
 
415
        irrelevant  Not in either revision
 
416
        """
398
417
        raise NotImplementedError(VersionedFile.plan_merge)
399
418
        
400
419
    def weave_merge(self, plan, a_marker=TextMerge.A_MARKER, 
401
420
                    b_marker=TextMerge.B_MARKER):
402
421
        return PlanWeaveMerge(plan, a_marker, b_marker).merge_lines()[0]
403
422
 
 
423
 
404
424
class PlanWeaveMerge(TextMerge):
405
425
    """Weave merge that takes a plan as its input.
406
426
    
413
433
        TextMerge.__init__(self, a_marker, b_marker)
414
434
        self.plan = plan
415
435
 
416
 
 
417
436
    def _merge_struct(self):
418
437
        lines_a = []
419
438
        lines_b = []
420
439
        ch_a = ch_b = False
 
440
 
 
441
        def outstanding_struct():
 
442
            if not lines_a and not lines_b:
 
443
                return
 
444
            elif ch_a and not ch_b:
 
445
                # one-sided change:
 
446
                yield(lines_a,)
 
447
            elif ch_b and not ch_a:
 
448
                yield (lines_b,)
 
449
            elif lines_a == lines_b:
 
450
                yield(lines_a,)
 
451
            else:
 
452
                yield (lines_a, lines_b)
421
453
       
422
454
        # We previously considered either 'unchanged' or 'killed-both' lines
423
455
        # to be possible places to resynchronize.  However, assuming agreement
425
457
        for state, line in self.plan:
426
458
            if state == 'unchanged':
427
459
                # resync and flush queued conflicts changes if any
428
 
                if not lines_a and not lines_b:
429
 
                    pass
430
 
                elif ch_a and not ch_b:
431
 
                    # one-sided change:
432
 
                    yield(lines_a,)
433
 
                elif ch_b and not ch_a:
434
 
                    yield (lines_b,)
435
 
                elif lines_a == lines_b:
436
 
                    yield(lines_a,)
437
 
                else:
438
 
                    yield (lines_a, lines_b)
439
 
 
 
460
                for struct in outstanding_struct():
 
461
                    yield struct
440
462
                lines_a = []
441
463
                lines_b = []
442
464
                ch_a = ch_b = False
459
481
            else:
460
482
                assert state in ('irrelevant', 'ghost-a', 'ghost-b', 
461
483
                                 'killed-base', 'killed-both'), state
 
484
        for struct in outstanding_struct():
 
485
            yield struct
462
486
 
463
487
 
464
488
class WeaveMerge(PlanWeaveMerge):