~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weave.py

  • Committer: Martin Pool
  • Date: 2005-07-14 08:29:35 UTC
  • Revision ID: mbp@sourcefrog.net-20050714082935-d088387c29e5776d
- more development of weave-merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
587
587
                killed_a = bool(deleteset & inc_a)
588
588
                killed_b = bool(deleteset & inc_b)
589
589
                if killed_a and killed_b:
590
 
                    # killed in both
591
590
                    yield 'killed-both', line
592
591
                elif killed_a:
593
592
                    yield 'killed-a', line
610
609
                # not in either revision
611
610
                yield 'irrelevant', line
612
611
 
 
612
        yield 'unchanged', ''           # terminator
 
613
 
 
614
 
 
615
 
 
616
    def weave_merge(self, plan):
 
617
        lines_a = []
 
618
        lines_b = []
 
619
        ch_a = ch_b = False
 
620
 
 
621
        for state, line in plan:
 
622
            if state == 'unchanged' or state == 'killed-both':
 
623
                # resync and flush queued conflicts changes if any
 
624
                if not lines_a and not lines_b:
 
625
                    pass
 
626
                elif ch_a and not ch_b:
 
627
                    # one-sided change:                    
 
628
                    for l in lines_a: yield l
 
629
                elif ch_b and not ch_a:
 
630
                    for l in lines_b: yield l
 
631
                elif lines_a == lines_b:
 
632
                    for l in lines_a: yield l
 
633
                else:
 
634
                    yield '<<<<\n'
 
635
                    for l in lines_a: yield l
 
636
                    yield '====\n'
 
637
                    for l in lines_b: yield l
 
638
                    yield '>>>>\n'
 
639
 
 
640
                del lines_a[:]
 
641
                del lines_b[:]
 
642
                ch_a = ch_b = False
 
643
                
 
644
            if state == 'unchanged':
 
645
                if line:
 
646
                    yield line
 
647
            elif state == 'killed-a':
 
648
                ch_a = True
 
649
                lines_b.append(line)
 
650
            elif state == 'killed-b':
 
651
                ch_b = True
 
652
                lines_a.append(line)
 
653
            elif state == 'new-a':
 
654
                ch_a = True
 
655
                lines_a.append(line)
 
656
            elif state == 'new-b':
 
657
                ch_b = True
 
658
                lines_b.append(line)
 
659
            else:
 
660
                assert state in ('irrelevant', 'ghost-a', 'ghost-b', 'killed-base'), \
 
661
                       state
 
662
 
 
663
                
 
664
 
 
665
 
613
666
 
614
667
 
615
668
 
763
816
    elif cmd == 'plan-merge':
764
817
        w = readit()
765
818
        for state, line in w.plan_merge(int(argv[3]), int(argv[4])):
766
 
            print '%14s | %s' % (state, line),
 
819
            if line:
 
820
                print '%14s | %s' % (state, line),
767
821
 
768
822
    elif cmd == 'merge':
 
823
        w = readit()
 
824
        p = w.plan_merge(int(argv[3]), int(argv[4]))
 
825
        sys.stdout.writelines(w.weave_merge(p))
 
826
            
 
827
    elif cmd == 'mash-merge':
769
828
        if len(argv) != 5:
770
829
            usage()
771
830
            return 1