/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/merge3.py

  • Committer: Robert Collins
  • Date: 2010-05-06 11:08:10 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506110810-h3j07fh5gmw54s25
Cleaner matcher matching revised unlocking protocol.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
18
17
 
19
18
# mbp: "you know that thing where cvs gives you conflict markers?"
20
19
# s: "i hate that."
21
20
 
22
 
from . import (
 
21
from bzrlib import (
23
22
    errors,
24
23
    patiencediff,
25
24
    textfile,
26
25
    )
27
26
 
28
27
 
29
 
class CantReprocessAndShowBase(errors.BzrError):
30
 
 
31
 
    _fmt = ("Can't reprocess and show base, because reprocessing obscures "
32
 
           "the relationship of conflicting lines to the base")
33
 
 
34
 
 
35
28
def intersect(ra, rb):
36
29
    """Given two ranges return the range where they intersect or None.
37
30
 
59
52
    """
60
53
    if (aend-astart) != (bend-bstart):
61
54
        return False
62
 
    for ia, ib in zip(range(astart, aend), range(bstart, bend)):
 
55
    for ia, ib in zip(xrange(astart, aend), xrange(bstart, bend)):
63
56
        if a[ia] != b[ib]:
64
57
            return False
65
58
    else:
66
59
        return True
67
60
 
68
61
 
 
62
 
 
63
 
69
64
class Merge3(object):
70
65
    """3-way merge of texts.
71
66
 
99
94
                    name_a=None,
100
95
                    name_b=None,
101
96
                    name_base=None,
102
 
                    start_marker=b'<<<<<<<',
103
 
                    mid_marker=b'=======',
104
 
                    end_marker=b'>>>>>>>',
 
97
                    start_marker='<<<<<<<',
 
98
                    mid_marker='=======',
 
99
                    end_marker='>>>>>>>',
105
100
                    base_marker=None,
106
101
                    reprocess=False):
107
102
        """Return merge in cvs-like form.
108
103
        """
109
 
        newline = b'\n'
 
104
        newline = '\n'
110
105
        if len(self.a) > 0:
111
 
            if self.a[0].endswith(b'\r\n'):
112
 
                newline = b'\r\n'
113
 
            elif self.a[0].endswith(b'\r'):
114
 
                newline = b'\r'
 
106
            if self.a[0].endswith('\r\n'):
 
107
                newline = '\r\n'
 
108
            elif self.a[0].endswith('\r'):
 
109
                newline = '\r'
115
110
        if base_marker and reprocess:
116
 
            raise CantReprocessAndShowBase()
 
111
            raise errors.CantReprocessAndShowBase()
117
112
        if name_a:
118
 
            start_marker = start_marker + b' ' + name_a
 
113
            start_marker = start_marker + ' ' + name_a
119
114
        if name_b:
120
 
            end_marker = end_marker + b' ' + name_b
 
115
            end_marker = end_marker + ' ' + name_b
121
116
        if name_base and base_marker:
122
 
            base_marker = base_marker + b' ' + name_base
 
117
            base_marker = base_marker + ' ' + name_base
123
118
        merge_regions = self.merge_regions()
124
119
        if reprocess is True:
125
120
            merge_regions = self.reprocess_merge_regions(merge_regions)
468
463
 
469
464
def main(argv):
470
465
    # as for diff3 and meld the syntax is "MINE BASE OTHER"
471
 
    with open(argv[1], 'rt') as f:
472
 
        a = f.readlines()
473
 
    with open(argv[2], 'rt') as f:
474
 
        base = f.readlines()
475
 
    with open(argv[3], 'rt') as f:
476
 
        b = f.readlines()
 
466
    a = file(argv[1], 'rt').readlines()
 
467
    base = file(argv[2], 'rt').readlines()
 
468
    b = file(argv[3], 'rt').readlines()
477
469
 
478
470
    m3 = Merge3(base, a, b)
479
471