/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/textmerge.py

  • Committer: John Arbash Meinel
  • Date: 2006-04-25 15:05:42 UTC
  • mfrom: (1185.85.85 bzr-encoding)
  • mto: This revision was merged to the branch mainline in revision 1752.
  • Revision ID: john@arbash-meinel.com-20060425150542-c7b518dca9928691
[merge] the old bzr-encoding changes, reparenting them on bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
#
17
 
# Author: Martin Pool <mbp@canonical.com>
 
17
# Author: Martin Pool <mbp@canonical.com> 
18
18
#         Aaron Bentley <aaron.bentley@utoronto.ca>
19
19
 
20
 
from __future__ import absolute_import
21
20
 
22
 
from .lazy_import import lazy_import
23
 
lazy_import(globals(), """
24
 
import patiencediff
25
 
""")
 
21
from difflib import SequenceMatcher
26
22
 
27
23
 
28
24
class TextMerge(object):
33
29
    This is an iterable of tuples of lists of lines.
34
30
    Each tuple may have a length of 1 - 3, depending on whether the region it
35
31
    represents is conflicted.
36
 
 
 
32
    
37
33
    Unconflicted region tuples have length 1.
38
34
    Conflicted region tuples have length 2 or 3.  Index 1 is text_a, e.g. THIS.
39
35
    Index 1 is text_b, e.g. OTHER.  Index 2 is optional.  If present, it
41
37
    """
42
38
    # TODO: Show some version information (e.g. author, date) on conflicted
43
39
    # regions.
44
 
    A_MARKER = b'<<<<<<< \n'
45
 
    B_MARKER = b'>>>>>>> \n'
46
 
    SPLIT_MARKER = b'=======\n'
47
 
 
 
40
    A_MARKER = '<<<<<<< \n'
 
41
    B_MARKER = '>>>>>>> \n'
 
42
    SPLIT_MARKER = '=======\n'
48
43
    def __init__(self, a_marker=A_MARKER, b_marker=B_MARKER,
49
44
                 split_marker=SPLIT_MARKER):
50
45
        self.a_marker = a_marker
65
60
                    yield line
66
61
            else:
67
62
                yield self.a_marker
68
 
                for line in lines[0]:
 
63
                for line in lines[0]: 
69
64
                    yield line
70
65
                yield self.split_marker
71
 
                for line in lines[1]:
 
66
                for line in lines[1]: 
72
67
                    yield line
73
68
                yield self.b_marker
74
69
 
125
120
    regions produce conflicts.
126
121
    """
127
122
 
128
 
    def __init__(self, lines_a, lines_b, a_marker=TextMerge.A_MARKER,
129
 
                 b_marker=TextMerge.B_MARKER,
 
123
    def __init__(self, lines_a, lines_b, a_marker=TextMerge.A_MARKER, 
 
124
                 b_marker=TextMerge.B_MARKER, 
130
125
                 split_marker=TextMerge.SPLIT_MARKER):
131
126
        TextMerge.__init__(self, a_marker, b_marker, split_marker)
132
127
        self.lines_a = lines_a
133
128
        self.lines_b = lines_b
134
129
 
135
130
    def _merge_struct(self):
136
 
        """Return structured merge info.
 
131
        """Return structured merge info.  
137
132
        See TextMerge docstring.
138
133
        """
139
 
        sm = patiencediff.PatienceSequenceMatcher(
140
 
            None, self.lines_a, self.lines_b)
 
134
        sm = SequenceMatcher(None, self.lines_a, self.lines_b)
141
135
        pos_a = 0
142
136
        pos_b = 0
143
137
        for ai, bi, l in sm.get_matching_blocks():
144
138
            # non-matching lines
145
139
            yield(self.lines_a[pos_a:ai], self.lines_b[pos_b:bi])
146
140
            # matching lines
147
 
            yield(self.lines_a[ai:ai + l],)
148
 
            pos_a = ai + l
 
141
            yield(self.lines_a[ai:ai+l],)
 
142
            pos_a = ai + l 
149
143
            pos_b = bi + l
150
144
        # final non-matching lines
151
145
        yield(self.lines_a[pos_a:-1], self.lines_b[pos_b:-1])