512
     ˆÆÅÄ571ÃÂÁ ;    ‹      Õ–]oÚ0†ïû+<_ìN¾VêdêH¥¡Q@”iš¦]˜Ø«‰�c¿~f*›@ƒ®ÍMŽ¿9çy�eÙäM<êM¿ŽïÐÇéý �?ô{× ¾4z ñ4vÍºçÜ1Â©1Ë.Àf³©ou¥0�@jò¬	…Ñ"1ufŽ®Hù-ºB$å”Ùˆˆ&ãQ_2þ©9µ2…`Üþ·-€ñµHxQŽÏ!ç¹ÒÛ}h\ƒTŒ{�,W-`Z¬¹&àÒÙ°¯@fŠmËÂþË±¹vèt¶«UuDLŠÖ4b£–8""_ B'!‘(YÀ,£ò±¾sŒhfBü­ß}·:0iùwD(J5Ÿ‡ø}/ÞŒÂGCšsô¸æÞjnq4 …A¹bb.8;)~pâñótÂØib^$Z,�PòI
Öâ¡ÕDeÅ’Z¯-ë Õ‡*'aÿêMþhÆøvr7œÆý‰k	+S<Ñ=wÉp4¦šKƒb¡ybìüÞ’ËÿVÎŠåÍïW´Öb‘!TCG•¸\ÉG©6òÐ¨mâQ‹3!í)Ÿ‡ˆ1^Ð®ù~-ðPt[ï:!´›óÓÿÂÏUÆ¸>d?µ<¶×žíõ.œAï_#¿ÓõÚ'é_¢õÑûŽÞ¯&}àèƒjÒ7}£šôMGß¬&}ËÑ·ªIßvôíjÒw}çÕÐ_pX­øÚžª8rñµX—�î¼uñlöù<g^�`©$°»·pæ_œ®ß“    A   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þB"¼³rˆ�†A„% ?ŸÀƒiæ�Å_ŠI|¥�+Wé3ž¯ÄÃ è    # Copyright (C) 2010-2018 Jelmer Vernooij <jelmer@jelmer.uk>
#
# 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

"""Roundtripping support.

Bazaar stores more data than Git, which means that in order to preserve
a commit when it is pushed from Bazaar into Git we have to stash
that extra metadata somewhere.

There are two kinds of metadata relevant here:
 * per-file metadata (stored by revision+path)
  - usually stored per tree
 * per-revision metadata (stored by git commit id)

Bazaar revisions have the following information that is not
present in Git commits:
 * revision ids
 * revision properties
 * ghost parents

Tree content:
 * empty directories
 * path file ids
 * path last changed revisions [1]

 [1] path last changed revision information can usually
     be induced from the existing history, unless
     ghost revisions are involved.

This extra metadata is stored in so-called "supplements":
  * CommitSupplement
  * TreeSupplement
"""

from .. import osutils

from io import BytesIO


class CommitSupplement:
    """Supplement for a Bazaar revision roundtripped into Git.

    :ivar revision_id: Revision id, as string
    :ivar properties: Revision properties, as dictionary
    :ivar explicit_parent_ids: Parent ids (needed if there are ghosts)
    :ivar verifiers: Verifier information
    """

    revision_id = None

    explicit_parent_ids = None

    def __init__(self):
        self.properties = {}
        self.verifiers = {}

    def __nonzero__(self):
        return bool(self.revision_id or self.properties or
                    self.explicit_parent_ids)


class TreeSupplement:
    """Supplement for a Bazaar tree roundtripped into Git.

    This provides file ids (if they are different from the mapping default)
    and can provide text revisions.
    """


def parse_roundtripping_metadata(text):
    """Parse Bazaar roundtripping metadata."""
    ret = CommitSupplement()
    f = BytesIO(text)
    for l in f.readlines():
        (key, value) = l.split(b":", 1)
        if key == b"revision-id":
            ret.revision_id = value.strip()
        elif key == b"parent-ids":
            ret.explicit_parent_ids = tuple(value.strip().split(b" "))
        elif key == b"testament3-sha1":
            ret.verifiers[b"testament3-sha1"] = value.strip()
        elif key.startswith(b"property-"):
            name = key[len(b"property-"):]
            if name not in ret.properties:
                ret.properties[name] = value[1:].rstrip(b"\n")
            else:
                ret.properties[name] += b"\n" + value[1:].rstrip(b"\n")
        else:
            raise ValueError
    return ret


def generate_roundtripping_metadata(metadata, encoding):
    """Serialize the roundtripping metadata.

    :param metadata: 