~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: abentley
  • Date: 2005-10-14 03:50:50 UTC
  • mto: (1185.25.1)
  • mto: This revision was merged to the branch mainline in revision 1460.
  • Revision ID: abentley@lappy-20051014035050-d779472ccb599a51
semi-broke merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# s: "i hate that."
20
20
 
21
21
 
22
 
from difflib import SequenceMatcher
23
 
from bzrlib.errors import CantReprocessAndShowBase
24
22
 
25
23
def intersect(ra, rb):
26
24
    """Given two ranges return the range where they intersect or None.
69
67
        self.base = base
70
68
        self.a = a
71
69
        self.b = b
 
70
        from difflib import SequenceMatcher
 
71
        self.a_ops = SequenceMatcher(None, base, a).get_opcodes()
 
72
        self.b_ops = SequenceMatcher(None, base, b).get_opcodes()
72
73
 
73
74
 
74
75
 
75
76
    def merge_lines(self,
76
77
                    name_a=None,
77
78
                    name_b=None,
78
 
                    name_base=None,
79
79
                    start_marker='<<<<<<<',
80
80
                    mid_marker='=======',
81
81
                    end_marker='>>>>>>>',
82
 
                    base_marker=None,
83
 
                    reprocess=False):
 
82
                    show_base=False):
84
83
        """Return merge in cvs-like form.
85
84
        """
86
 
        if base_marker and reprocess:
87
 
            raise CantReprocessAndShowBase()
88
85
        if name_a:
89
86
            start_marker = start_marker + ' ' + name_a
90
87
        if name_b:
91
88
            end_marker = end_marker + ' ' + name_b
92
 
        if name_base and base_marker:
93
 
            base_marker = base_marker + ' ' + name_base
94
 
        merge_regions = self.merge_regions()
95
 
        if reprocess is True:
96
 
            merge_regions = self.reprocess_merge_regions(merge_regions)
97
 
        for t in merge_regions:
 
89
            
 
90
        for t in self.merge_regions():
98
91
            what = t[0]
99
92
            if what == 'unchanged':
100
93
                for i in range(t[1], t[2]):
109
102
                yield start_marker + '\n'
110
103
                for i in range(t[3], t[4]):
111
104
                    yield self.a[i]
112
 
                if base_marker is not None:
113
 
                    yield base_marker + '\n'
114
 
                    for i in range(t[1], t[2]):
115
 
                        yield self.base[i]
116
105
                yield mid_marker + '\n'
117
106
                for i in range(t[5], t[6]):
118
107
                    yield self.b[i]
274
263
                iz = zend
275
264
                ia = aend
276
265
                ib = bend
277
 
    
278
 
 
279
 
    def reprocess_merge_regions(self, merge_regions):
280
 
        for region in merge_regions:
281
 
            if region[0] != "conflict":
282
 
                yield region
283
 
                continue
284
 
            type, iz, zmatch, ia, amatch, ib, bmatch = region
285
 
            a_region = self.a[ia:amatch]
286
 
            b_region = self.b[ib:bmatch]
287
 
            matches = SequenceMatcher(None, a_region, 
288
 
                                      b_region).get_matching_blocks()
289
 
            next_a = ia
290
 
            next_b = ib
291
 
            for region_ia, region_ib, region_len in matches[:-1]:
292
 
                region_ia += ia
293
 
                region_ib += ib
294
 
                reg = self.mismatch_region(next_a, region_ia, next_b,
295
 
                                           region_ib)
296
 
                if reg is not None:
297
 
                    yield reg
298
 
                yield 'same', region_ia, region_len+region_ia
299
 
                next_a = region_ia + region_len
300
 
                next_b = region_ib + region_len
301
 
            reg = self.mismatch_region(next_a, amatch, next_b, bmatch)
302
 
            if reg is not None:
303
 
                yield reg
304
 
 
305
 
 
306
 
    @staticmethod
307
 
    def mismatch_region(next_a, region_ia,  next_b, region_ib):
308
 
        if next_a < region_ia or next_b < region_ib:
309
 
            return 'conflict', None, None, next_a, region_ia, next_b, region_ib
310
 
            
311
 
 
 
266
        
 
267
 
 
268
        
312
269
    def find_sync_regions(self):
313
270
        """Return a list of sync regions, where both descendents match the base.
314
271
 
315
272
        Generates a list of (base1, base2, a1, a2, b1, b2).  There is
316
273
        always a zero-length sync region at the end of all the files.
317
274
        """
 
275
        from difflib import SequenceMatcher
318
276
 
319
277
        ia = ib = 0
320
278
        amatches = SequenceMatcher(None, self.base, self.a).get_matching_blocks()
374
332
 
375
333
    def find_unconflicted(self):
376
334
        """Return a list of ranges in base that are not conflicted."""
 
335
        from difflib import SequenceMatcher
377
336
 
378
337
        import re
379
338