~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/textmerge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-03-28 06:58:22 UTC
  • mfrom: (2379.2.3 hpss-chroot)
  • Revision ID: pqm@pqm.ubuntu.com-20070328065822-999550a858a3ced3
(robertc) Fix chroot urls to not expose the url of the transport they are protecting, allowing regular url operations to work on them. (Robert Collins, Andrew Bennetts)

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 bzrlib.lazy_import import lazy_import
23
 
lazy_import(globals(), """
24
 
from bzrlib import patiencediff
25
 
""")
 
21
import bzrlib.patiencediff
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
64
60
                    yield line
65
61
            else:
66
62
                yield self.a_marker
67
 
                for line in lines[0]:
 
63
                for line in lines[0]: 
68
64
                    yield line
69
65
                yield self.split_marker
70
 
                for line in lines[1]:
 
66
                for line in lines[1]: 
71
67
                    yield line
72
68
                yield self.b_marker
73
69
 
124
120
    regions produce conflicts.
125
121
    """
126
122
 
127
 
    def __init__(self, lines_a, lines_b, a_marker=TextMerge.A_MARKER,
128
 
                 b_marker=TextMerge.B_MARKER,
 
123
    def __init__(self, lines_a, lines_b, a_marker=TextMerge.A_MARKER, 
 
124
                 b_marker=TextMerge.B_MARKER, 
129
125
                 split_marker=TextMerge.SPLIT_MARKER):
130
126
        TextMerge.__init__(self, a_marker, b_marker, split_marker)
131
127
        self.lines_a = lines_a
132
128
        self.lines_b = lines_b
133
129
 
134
130
    def _merge_struct(self):
135
 
        """Return structured merge info.
 
131
        """Return structured merge info.  
136
132
        See TextMerge docstring.
137
133
        """
138
 
        sm = patiencediff.PatienceSequenceMatcher(
139
 
            None, self.lines_a, self.lines_b)
 
134
        sm = bzrlib.patiencediff.PatienceSequenceMatcher(None, self.lines_a, self.lines_b)
140
135
        pos_a = 0
141
136
        pos_b = 0
142
137
        for ai, bi, l in sm.get_matching_blocks():
144
139
            yield(self.lines_a[pos_a:ai], self.lines_b[pos_b:bi])
145
140
            # matching lines
146
141
            yield(self.lines_a[ai:ai+l],)
147
 
            pos_a = ai + l
 
142
            pos_a = ai + l 
148
143
            pos_b = bi + l
149
144
        # final non-matching lines
150
145
        yield(self.lines_a[pos_a:-1], self.lines_b[pos_b:-1])