/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 breezy/merge3.py

  • Committer: Martin
  • Date: 2018-11-16 16:38:22 UTC
  • mto: This revision was merged to the branch mainline in revision 7172.
  • Revision ID: gzlist@googlemail.com-20181116163822-yg1h1cdng6w7w9kn
Make --profile-imports work on Python 3

Also tweak heading to line up correctly.

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