~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

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
14
14
# along with this program; if not, write to the Free Software
15
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):
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:
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
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)
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 = []