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

Partially fix pull.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007 Canonical Ltd
2
 
# Copyright (C) 2008-2009 Jelmer Vernooij <jelmer@samba.org>
3
 
# Copyright (C) 2008 John Carr
 
1
# Copyright (C) 2007-2008 Canonical Ltd
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
6
4
# it under the terms of the GNU General Public License as published by
18
16
 
19
17
"""Converters, etc for going between Bazaar and Git ids."""
20
18
 
21
 
from bzrlib import (
22
 
    errors,
23
 
    foreign,
24
 
    urlutils,
25
 
    )
26
 
from bzrlib.inventory import (
27
 
    ROOT_ID,
28
 
    )
 
19
from bzrlib import errors, foreign, urlutils
 
20
from bzrlib.inventory import ROOT_ID
29
21
from bzrlib.foreign import (
30
 
    ForeignVcs, 
31
 
    VcsMappingRegistry, 
32
 
    ForeignRevision,
33
 
    )
 
22
        ForeignVcs, 
 
23
        VcsMappingRegistry, 
 
24
        ForeignRevision,
 
25
        )
34
26
 
35
27
def escape_file_id(file_id):
36
28
    return file_id.replace('_', '__').replace(' ', '_s')
63
55
        return bzr_rev_id[len(cls.revid_prefix)+1:], cls()
64
56
 
65
57
    def generate_file_id(self, path):
66
 
        # Git paths are just bytestrings
67
 
        # We must just hope they are valid UTF-8..
68
 
        assert isinstance(path, str)
69
58
        if path == "":
70
59
            return ROOT_ID
71
 
        return escape_file_id(path)
72
 
 
73
 
    def parse_file_id(self, file_id):
74
 
        if file_id == ROOT_ID:
75
 
            return ""
76
 
        return unescape_file_id(file_id)
 
60
        return escape_file_id(path.encode('utf-8'))
77
61
 
78
62
    def import_commit(self, commit):
79
63
        """Convert a git commit to a bzr revision.
149
133
 
150
134
    # stack contains the set of trees that we haven't 
151
135
    # finished constructing
 
136
 
152
137
    for path, entry in inv.iter_entries():
153
138
        while stack and not path.startswith(cur):
154
139
            tree.serialize()
202
187
    for p in rev.parent_ids:
203
188
        git_p = parent_lookup(p)
204
189
        if git_p is not None:
205
 
            assert len(git_p) == 40, "unexpected length for %r" % git_p
206
190
            commit._parents.append(git_p)
207
191
    commit._message = rev.message.encode("utf-8")
208
192
    commit._committer = rev.committer.encode("utf-8")
209
 
    commit._author = rev.get_apparent_authors()[0].encode("utf-8")
 
193
    commit._author = rev.get_apparent_author().encode("utf-8")
210
194
    commit._commit_time = long(rev.timestamp)
211
195
    commit.serialize()
212
196
    return commit