~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
from __future__ import absolute_import
17
18
 
18
19
# mbp: "you know that thing where cvs gives you conflict markers?"
19
20
# s: "i hate that."
20
21
 
21
 
 
22
 
from bzrlib.errors import CantReprocessAndShowBase
23
 
import bzrlib.patiencediff
24
 
from bzrlib.textfile import check_text_lines
 
22
from bzrlib import (
 
23
    errors,
 
24
    patiencediff,
 
25
    textfile,
 
26
    )
25
27
 
26
28
 
27
29
def intersect(ra, rb):
37
39
    (7, 9)
38
40
    """
39
41
    # preconditions: (ra[0] <= ra[1]) and (rb[0] <= rb[1])
40
 
    
 
42
 
41
43
    sa = max(ra[0], rb[0])
42
44
    sb = min(ra[1], rb[1])
43
45
    if sa < sb:
56
58
            return False
57
59
    else:
58
60
        return True
59
 
        
 
61
 
60
62
 
61
63
 
62
64
 
66
68
    Given BASE, OTHER, THIS, tries to produce a combined text
67
69
    incorporating the changes from both BASE->OTHER and BASE->THIS.
68
70
    All three will typically be sequences of lines."""
69
 
    def __init__(self, base, a, b, is_cherrypick=False):
70
 
        check_text_lines(base)
71
 
        check_text_lines(a)
72
 
        check_text_lines(b)
 
71
 
 
72
    def __init__(self, base, a, b, is_cherrypick=False, allow_objects=False):
 
73
        """Constructor.
 
74
 
 
75
        :param base: lines in BASE
 
76
        :param a: lines in A
 
77
        :param b: lines in B
 
78
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
 
79
            When cherrypicking b => a, matches with b and base do not conflict.
 
80
        :param allow_objects: if True, do not require that base, a and b are
 
81
            plain Python strs.  Also prevents BinaryFile from being raised.
 
82
            Lines can be any sequence of comparable and hashable Python
 
83
            objects.
 
84
        """
 
85
        if not allow_objects:
 
86
            textfile.check_text_lines(base)
 
87
            textfile.check_text_lines(a)
 
88
            textfile.check_text_lines(b)
73
89
        self.base = base
74
90
        self.a = a
75
91
        self.b = b
93
109
            elif self.a[0].endswith('\r'):
94
110
                newline = '\r'
95
111
        if base_marker and reprocess:
96
 
            raise CantReprocessAndShowBase()
 
112
            raise errors.CantReprocessAndShowBase()
97
113
        if name_a:
98
114
            start_marker = start_marker + ' ' + name_a
99
115
        if name_b:
132
148
    def merge_annotated(self):
133
149
        """Return merge with conflicts, showing origin of lines.
134
150
 
135
 
        Most useful for debugging merge.        
 
151
        Most useful for debugging merge.
136
152
        """
137
153
        for t in self.merge_regions():
138
154
            what = t[0]
219
235
 
220
236
        # section a[0:ia] has been disposed of, etc
221
237
        iz = ia = ib = 0
222
 
        
 
238
 
223
239
        for zmatch, zend, amatch, aend, bmatch, bend in self.find_sync_regions():
224
240
            matchlen = zend - zmatch
225
241
            # invariants:
275
291
                # assert ia == amatch
276
292
                # assert ib == bmatch
277
293
                # assert iz == zmatch
278
 
                
 
294
 
279
295
                yield 'unchanged', zmatch, zend
280
296
                iz = zend
281
297
                ia = aend
284
300
    def _refine_cherrypick_conflict(self, zstart, zend, astart, aend, bstart, bend):
285
301
        """When cherrypicking b => a, ignore matches with b and base."""
286
302
        # Do not emit regions which match, only regions which do not match
287
 
        matches = bzrlib.patiencediff.PatienceSequenceMatcher(None,
 
303
        matches = patiencediff.PatienceSequenceMatcher(None,
288
304
            self.base[zstart:zend], self.b[bstart:bend]).get_matching_blocks()
289
305
        last_base_idx = 0
290
306
        last_b_idx = 0
324
340
    def reprocess_merge_regions(self, merge_regions):
325
341
        """Where there are conflict regions, remove the agreed lines.
326
342
 
327
 
        Lines where both A and B have made the same changes are 
 
343
        Lines where both A and B have made the same changes are
328
344
        eliminated.
329
345
        """
330
346
        for region in merge_regions:
334
350
            type, iz, zmatch, ia, amatch, ib, bmatch = region
335
351
            a_region = self.a[ia:amatch]
336
352
            b_region = self.b[ib:bmatch]
337
 
            matches = bzrlib.patiencediff.PatienceSequenceMatcher(
 
353
            matches = patiencediff.PatienceSequenceMatcher(
338
354
                    None, a_region, b_region).get_matching_blocks()
339
355
            next_a = ia
340
356
            next_b = ib
365
381
        """
366
382
 
367
383
        ia = ib = 0
368
 
        amatches = bzrlib.patiencediff.PatienceSequenceMatcher(
 
384
        amatches = patiencediff.PatienceSequenceMatcher(
369
385
                None, self.base, self.a).get_matching_blocks()
370
 
        bmatches = bzrlib.patiencediff.PatienceSequenceMatcher(
 
386
        bmatches = patiencediff.PatienceSequenceMatcher(
371
387
                None, self.base, self.b).get_matching_blocks()
372
388
        len_a = len(amatches)
373
389
        len_b = len(bmatches)
410
426
                ia += 1
411
427
            else:
412
428
                ib += 1
413
 
            
 
429
 
414
430
        intbase = len(self.base)
415
431
        abase = len(self.a)
416
432
        bbase = len(self.b)
420
436
 
421
437
    def find_unconflicted(self):
422
438
        """Return a list of ranges in base that are not conflicted."""
423
 
        am = bzrlib.patiencediff.PatienceSequenceMatcher(
 
439
        am = patiencediff.PatienceSequenceMatcher(
424
440
                None, self.base, self.a).get_matching_blocks()
425
 
        bm = bzrlib.patiencediff.PatienceSequenceMatcher(
 
441
        bm = patiencediff.PatienceSequenceMatcher(
426
442
                None, self.base, self.b).get_matching_blocks()
427
443
 
428
444
        unc = []
442
458
                del am[0]
443
459
            else:
444
460
                del bm[0]
445
 
                
 
461
 
446
462
        return unc
447
463
 
448
464