/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/git/roundtrip.py

  • Committer: Jelmer Vernooij
  • Date: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
  * TreeSupplement
46
46
"""
47
47
 
 
48
from __future__ import absolute_import
 
49
 
48
50
from .. import osutils
49
51
 
50
52
from io import BytesIO
68
70
        self.verifiers = {}
69
71
 
70
72
    def __nonzero__(self):
71
 
        return bool(self.revision_id or self.properties or
72
 
                    self.explicit_parent_ids)
 
73
        return bool(self.revision_id or self.properties or self.explicit_parent_ids)
73
74
 
74
75
 
75
76
class TreeSupplement(object):
80
81
    """
81
82
 
82
83
 
 
84
 
83
85
def parse_roundtripping_metadata(text):
84
86
    """Parse Bazaar roundtripping metadata."""
85
87
    ret = CommitSupplement()
94
96
            ret.verifiers[b"testament3-sha1"] = value.strip()
95
97
        elif key.startswith(b"property-"):
96
98
            name = key[len(b"property-"):]
97
 
            if name not in ret.properties:
 
99
            if not name in ret.properties:
98
100
                ret.properties[name] = value[1:].rstrip(b"\n")
99
101
            else:
100
102
                ret.properties[name] += b"\n" + value[1:].rstrip(b"\n")
113
115
    if metadata.revision_id:
114
116
        lines.append(b"revision-id: %s\n" % metadata.revision_id)
115
117
    if metadata.explicit_parent_ids:
116
 
        lines.append(b"parent-ids: %s\n" %
117
 
                     b" ".join(metadata.explicit_parent_ids))
 
118
        lines.append(b"parent-ids: %s\n" % b" ".join(metadata.explicit_parent_ids))
118
119
    for key in sorted(metadata.properties.keys()):
119
120
        for l in metadata.properties[key].split(b"\n"):
120
121
            lines.append(b"property-%s: %s\n" % (key, osutils.safe_utf8(l)))
145
146
    if not isinstance(rt_data, bytes):
146
147
        raise TypeError(rt_data)
147
148
    return message + b"\n--BZR--\n" + rt_data
 
149
 
 
150
 
 
151
def serialize_fileid_map(file_ids):
 
152
    """Serialize a fileid map.
 
153
 
 
154
    :param file_ids: Path -> fileid map
 
155
    :return: Serialized fileid map, as sequence of chunks
 
156
    """
 
157
    lines = []
 
158
    for path in sorted(file_ids.keys()):
 
159
        lines.append(b"%s\0%s\n" % (path, file_ids[path]))
 
160
    return lines
 
161
 
 
162
 
 
163
def deserialize_fileid_map(filetext):
 
164
    """Deserialize a file id map.
 
165
 
 
166
    :param file: File
 
167
    :return: Fileid map (path -> fileid)
 
168
    """
 
169
    ret = {}
 
170
    f = BytesIO(filetext)
 
171
    lines = f.readlines()
 
172
    for l in lines:
 
173
        (path, file_id) = l.rstrip(b"\n").split(b"\0")
 
174
        ret[path] = file_id
 
175
    return ret