~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: John Arbash Meinel
  • Date: 2009-06-12 18:05:15 UTC
  • mto: (4371.4.5 vila-better-heads)
  • mto: This revision was merged to the branch mainline in revision 4449.
  • Revision ID: john@arbash-meinel.com-20090612180515-t0cwbjsnve094oik
Add a failing test for handling nodes that are in the same linear chain.

It fails because the ancestry skipping causes us to miss the fact that the two nodes
are actually directly related. We could check at the beginning, as the 
code used to do, but I think that will be incomplete for the more-than-two
heads cases.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2004, 2005 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
18
18
# mbp: "you know that thing where cvs gives you conflict markers?"
19
19
# s: "i hate that."
20
20
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    patiencediff,
24
 
    textfile,
25
 
    )
 
21
 
 
22
from bzrlib.errors import CantReprocessAndShowBase
 
23
import bzrlib.patiencediff
 
24
from bzrlib.textfile import check_text_lines
26
25
 
27
26
 
28
27
def intersect(ra, rb):
67
66
    Given BASE, OTHER, THIS, tries to produce a combined text
68
67
    incorporating the changes from both BASE->OTHER and BASE->THIS.
69
68
    All three will typically be sequences of lines."""
70
 
 
71
 
    def __init__(self, base, a, b, is_cherrypick=False, allow_objects=False):
72
 
        """Constructor.
73
 
 
74
 
        :param base: lines in BASE
75
 
        :param a: lines in A
76
 
        :param b: lines in B
77
 
        :param is_cherrypick: flag indicating if this merge is a cherrypick.
78
 
            When cherrypicking b => a, matches with b and base do not conflict.
79
 
        :param allow_objects: if True, do not require that base, a and b are
80
 
            plain Python strs.  Also prevents BinaryFile from being raised.
81
 
            Lines can be any sequence of comparable and hashable Python
82
 
            objects.
83
 
        """
84
 
        if not allow_objects:
85
 
            textfile.check_text_lines(base)
86
 
            textfile.check_text_lines(a)
87
 
            textfile.check_text_lines(b)
 
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)
88
73
        self.base = base
89
74
        self.a = a
90
75
        self.b = b
108
93
            elif self.a[0].endswith('\r'):
109
94
                newline = '\r'
110
95
        if base_marker and reprocess:
111
 
            raise errors.CantReprocessAndShowBase()
 
96
            raise CantReprocessAndShowBase()
112
97
        if name_a:
113
98
            start_marker = start_marker + ' ' + name_a
114
99
        if name_b:
299
284
    def _refine_cherrypick_conflict(self, zstart, zend, astart, aend, bstart, bend):
300
285
        """When cherrypicking b => a, ignore matches with b and base."""
301
286
        # Do not emit regions which match, only regions which do not match
302
 
        matches = patiencediff.PatienceSequenceMatcher(None,
 
287
        matches = bzrlib.patiencediff.PatienceSequenceMatcher(None,
303
288
            self.base[zstart:zend], self.b[bstart:bend]).get_matching_blocks()
304
289
        last_base_idx = 0
305
290
        last_b_idx = 0
349
334
            type, iz, zmatch, ia, amatch, ib, bmatch = region
350
335
            a_region = self.a[ia:amatch]
351
336
            b_region = self.b[ib:bmatch]
352
 
            matches = patiencediff.PatienceSequenceMatcher(
 
337
            matches = bzrlib.patiencediff.PatienceSequenceMatcher(
353
338
                    None, a_region, b_region).get_matching_blocks()
354
339
            next_a = ia
355
340
            next_b = ib
380
365
        """
381
366
 
382
367
        ia = ib = 0
383
 
        amatches = patiencediff.PatienceSequenceMatcher(
 
368
        amatches = bzrlib.patiencediff.PatienceSequenceMatcher(
384
369
                None, self.base, self.a).get_matching_blocks()
385
 
        bmatches = patiencediff.PatienceSequenceMatcher(
 
370
        bmatches = bzrlib.patiencediff.PatienceSequenceMatcher(
386
371
                None, self.base, self.b).get_matching_blocks()
387
372
        len_a = len(amatches)
388
373
        len_b = len(bmatches)
435
420
 
436
421
    def find_unconflicted(self):
437
422
        """Return a list of ranges in base that are not conflicted."""
438
 
        am = patiencediff.PatienceSequenceMatcher(
 
423
        am = bzrlib.patiencediff.PatienceSequenceMatcher(
439
424
                None, self.base, self.a).get_matching_blocks()
440
 
        bm = patiencediff.PatienceSequenceMatcher(
 
425
        bm = bzrlib.patiencediff.PatienceSequenceMatcher(
441
426
                None, self.base, self.b).get_matching_blocks()
442
427
 
443
428
        unc = []