~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/versionedfile.py

Implemented two-way merge, refactored weave merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
import bzrlib.errors as errors
32
32
from bzrlib.inter import InterObject
33
33
from bzrlib.symbol_versioning import *
 
34
from bzrlib.textmerge import TextMerge
34
35
from bzrlib.transport.memory import MemoryTransport
35
36
from bzrlib.tsort import topo_sort
36
37
from bzrlib import ui
440
441
        yield 'unchanged', ''           # terminator
441
442
 
442
443
    def weave_merge(self, plan, a_marker='<<<<<<< \n', b_marker='>>>>>>> \n'):
443
 
        return self.struct_to_lines(self.weave_merge_struct(plan), a_marker,
444
 
                                    b_marker)
445
 
 
446
 
    def struct_to_lines(self, struct_iter, a_marker, b_marker):
447
 
        for lines in struct_iter:
448
 
            if len(lines) == 1:
449
 
                for line in lines[0]:
450
 
                    yield line
451
 
            else:
452
 
                    yield a_marker
453
 
                    for l in lines[0]: yield l
454
 
                    yield '=======\n'
455
 
                    for l in lines[1]: yield l
456
 
                    yield b_marker
457
 
                    
458
 
 
459
 
    def weave_merge_struct(self, plan):
 
444
        return WeaveMerge(plan, a_marker, b_marker).merge_lines()
 
445
 
 
446
class WeaveMerge(TextMerge):
 
447
    def __init__(self, plan, a_marker='<<<<<<< \n', b_marker='>>>>>>> \n'):
 
448
        TextMerge.__init__(self, a_marker, b_marker)
 
449
        self.plan = plan
 
450
 
 
451
    def _merge_struct(self):
460
452
        lines_a = []
461
453
        lines_b = []
462
454
        ch_a = ch_b = False
466
458
        # We previously considered either 'unchanged' or 'killed-both' lines
467
459
        # to be possible places to resynchronize.  However, assuming agreement
468
460
        # on killed-both lines may be too agressive. -- mbp 20060324
469
 
        for state, line in plan:
 
461
        for state, line in self.plan:
470
462
            if state == 'unchanged':
471
463
                # resync and flush queued conflicts changes if any
472
464
                if not lines_a and not lines_b: