1
  5   ˆl–ß=¿J	Å4Ÿº‚ œP ¸n¥1hß�þB g…òŒ´ÿóÂƒh¹ÁÀ¿      00000051
  .   ˆ{‹„„-i[D<†ªoZƒ›Ù«Ã‚l"_‘I|¥‰ÓMdœv ©ƒ†ü+=ÃÂ      ‹      µTÁŽÚ0½ïWL}è† Ëî²Ž«-A**ˆMUUU&6ÄÚGŽ!¥__C¨H+hÙ–^2Žóæå½ñxè«`Ü?Múð.|ÂäÃÛá ¤†ø±ÕCÂ üÐ®7<Äþˆ ‰­ÍºˆEQÔ‹V]›†SŒí2icn�Šl]XAØÝî±+ ±äÂE VÙD²A*äWÐs@½²¹Òåmrr�QÌ¶»×·˜¯fnÓÊ%Z»ñZË\Ç†{::Ób³ý‹÷—Œ.q'ŠÏvÄÛ¥aÔÆ°æ‰Z¤>±:#ŒªårùU¤Óg	OŸë5'Àë“ÏƒÞø‹Ã¡�·ÙŒrˆ�œûäMÏÝ�ý€°_JŠü8æÑaòÜÂR5WRœ?•à'õí4aPb™GFeVéô Eg±j5ÒIžqçõÚ9ˆMUBÄŸªÁ£ŸŠ1y˜öGa0˜–%[ŠƒºóÎ‡°	72µ(##«Ífo d{�ÎòìþÇ+ìåµˆ-a 58Š|�§Uúœê"­Úr%;jÈY Ì=ªQÔl4;5Ï«5;Ððº�€@wÅÞÿ«ô¹N„4Uå§Ž"Ó…4®Ôe¼„þK”þ|ýÕv9¬ÏðáÝ�wÓmtþ«�´ÐJ®]¯VÆKø}#�yûq?)îæ,ÅršÃ90    7   ˆl–ß=¿J	Å4Ÿº‚ œP ¸®Å1hß‘äÇò 8àD(ÈQ²ÓÒÿ?Æƒh¹ÅÄÃ      0000003a
  A   	ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þBÓäY¹DGÃ Â�ÏÇƒlN¹Æ_ŠI|¥�+Wé3ž¯ÆÅ œ    	# Copyright (C) 2006, 2009, 2010 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Author: Martin Pool <mbp@canonical.com>
#         Aaron Bentley <aaron.bentley@utoronto.ca>


class TextMerge:
    """Base class for text-mergers
    Subclasses must implement _merge_struct.

    Many methods produce or consume structured merge information.
    This is an iterable of tuples of lists of lines.
    Each tuple may have a length of 1 - 3, depending on whether the region it
    represents is conflicted.

    Unconflicted region tuples have length 1.
    Conflicted region tuples have length 2 or 3.  Index 1 is text_a, e.g. THIS.
    Index 1 is text_b, e.g. OTHER.  Index 2 is optional.  If present, it
    represents BASE.
    """
    # TODO: Show some version information (e.g. author, date) on conflicted
    # regions.
    A_MARKER = b'<<<<<<< \n'
    B_MARKER = b'>>>>>>> \n'
    SPLIT_MARKER = b'=======\n'

    def __init__(self, a_marker=A_MARKER, b_marker=B_MARKER,
                 split_marker=SPLIT_MARKER):
        self.a_marker = a_marker
        self.b_marker = b_marker
        self.split_marker = split_marker

    def _merge_struct(self):
        """Return structured merge info.  Must be implemented by subclasses.
        See TextMerge docstring for details on the format.
        """
        raise NotImplementedError('_merge_struct is abstract')

    def struct_to_lines(self, struct_iter):
        """Convert merge result tuples to lines"""
        for lines in struct_iter:
            if len(lines) == 1:
                yield from lines[0]
            else:
                yield self.a_marker
                yield from lines[0]
                yield self.split_marker
                yield from lines[1]
                yield self.b_marker

    def iter_useful(self, struct_iter):
        """Iterate through input tuples, skipping empty ones."""
        for group in struct_iter:
            if len(group[0]) > 0:
                yield group
            elif len(group) > 1 and len(group[1]) > 0:
                yield group

    def merge_lines(self, reprocess=False):
        """Produce an iterable of lines, suitable for writing to a file
        Returns a tuple of (line iterable, conflict indicator)
        If reprocess is True, a two-way merge will be performed on the
        intermediate structure, to reduce conflict regions.
        """
        struct = []
        conflicts = False
        for group in self.merge_struct(reprocess):
            struct.append(group)
            if len(group) > 1:
                conflicts = True
        return self.struct_to_l