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

Fix imports of TestLoader on newer versions of bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
class BzrGitRevisionMetadata(object):
24
24
    """Metadata for a Bazaar revision roundtripped into Git.
25
 
    
 
25
 
26
26
    :ivar revision_id: Revision id, as string
27
27
    :ivar properties: Revision properties, as dictionary
28
28
    :ivar explicit_parent_ids: Parent ids (needed if there are ghosts)
 
29
    :ivar testament3_sha1: SHA1 of the testament.
29
30
    """
30
31
 
31
32
    revision_id = None
32
33
 
33
34
    explicit_parent_ids = None
34
35
 
 
36
    testament3_sha1 = None
 
37
 
35
38
    def __init__(self):
36
39
        self.properties = {}
37
40
 
49
52
            ret.revision_id = value.strip()
50
53
        elif key == "parent-ids":
51
54
            ret.explicit_parent_ids = tuple(value.strip().split(" "))
 
55
        elif key == "testament3-sha1":
 
56
            ret.testament3_sha1 = value.strip()
52
57
        elif key.startswith("property-"):
53
58
            ret.properties[key[len("property-"):]] = value[1:].rstrip("\n")
54
59
        else:
69
74
        lines.append("parent-ids: %s\n" % " ".join(metadata.explicit_parent_ids))
70
75
    for key in sorted(metadata.properties.keys()):
71
76
        lines.append("property-%s: %s\n" % (key.encode(encoding), metadata.properties[key].encode(encoding)))
 
77
    if metadata.testament3_sha1:
 
78
        lines.append("testament3-sha1: %s\n" % metadata.testament3_sha1)
72
79
    return "".join(lines)
73
80
 
74
81
 
88
95
    if not metadata:
89
96
        return message
90
97
    rt_data = generate_roundtripping_metadata(metadata, encoding)
 
98
    if not rt_data:
 
99
        return message
91
100
    assert type(rt_data) == str
92
101
    return message + "\n--BZR--\n" + rt_data
93
102
 
94
103
 
95
104
def serialize_fileid_map(file_ids):
 
105
    """Serialize a file id map."""
96
106
    lines = []
97
107
    for path in sorted(file_ids.keys()):
98
108
        lines.append("%s\0%s\n" % (path, file_ids[path]))
99
109
    return lines
100
110
 
101
111
 
102
 
def deserialize_fileid_map(file):
 
112
def deserialize_fileid_map(filetext):
 
113
    """Deserialize a file id map."""
103
114
    ret = {}
104
 
    f = StringIO(file)
 
115
    f = StringIO(filetext)
105
116
    lines = f.readlines()
106
117
    for l in lines:
107
118
        (path, file_id) = l.rstrip("\n").split("\0")