/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

Merge thin-pack work.

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
 
    )
34
 
from bzrlib.plugins.git.foreign import (
35
 
    escape_commit_message,
36
 
    )
37
 
 
 
22
        ForeignVcs, 
 
23
        VcsMappingRegistry, 
 
24
        ForeignRevision,
 
25
        )
38
26
 
39
27
def escape_file_id(file_id):
40
28
    return file_id.replace('_', '__').replace(' ', '_s')
67
55
        return bzr_rev_id[len(cls.revid_prefix)+1:], cls()
68
56
 
69
57
    def generate_file_id(self, path):
70
 
        # Git paths are just bytestrings
71
 
        # We must just hope they are valid UTF-8..
72
 
        assert isinstance(path, str)
73
58
        if path == "":
74
59
            return ROOT_ID
75
 
        return escape_file_id(path)
76
 
 
77
 
    def parse_file_id(self, file_id):
78
 
        if file_id == ROOT_ID:
79
 
            return ""
80
 
        return unescape_file_id(file_id)
 
60
        return escape_file_id(path.encode('utf-8'))
81
61
 
82
62
    def import_commit(self, commit):
83
63
        """Convert a git commit to a bzr revision.
88
68
            raise AssertionError("Commit object can't be None")
89
69
        rev = ForeignRevision(commit.id, self, self.revision_id_foreign_to_bzr(commit.id))
90
70
        rev.parent_ids = tuple([self.revision_id_foreign_to_bzr(p) for p in commit.parents])
91
 
        rev.message = escape_commit_message(commit.message.decode("utf-8", "replace"))
92
 
        rev.committer = escape_commit_message(str(commit.committer).decode("utf-8", "replace"))
 
71
        rev.message = commit.message.decode("utf-8", "replace")
 
72
        rev.committer = str(commit.committer).decode("utf-8", "replace")
93
73
        if commit.committer != commit.author:
94
 
            rev.properties['author'] = escape_commit_message(str(commit.author).decode("utf-8", "replace"))
 
74
            rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
95
75
        rev.timestamp = commit.commit_time
96
76
        rev.timezone = 0
97
77
        return rev
153
133
 
154
134
    # stack contains the set of trees that we haven't 
155
135
    # finished constructing
 
136
 
156
137
    for path, entry in inv.iter_entries():
157
138
        while stack and not path.startswith(cur):
158
139
            tree.serialize()
159
 
            sha = tree.id
 
140
            sha = tree.sha().hexdigest()
160
141
            yield sha, tree, cur
161
142
            t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
162
143
            cur, tree = stack.pop()
171
152
            #FIXME: We can make potentially make this Lazy to avoid shaing lots of stuff
172
153
            # and having all these objects in memory at once
173
154
            blob = Blob()
174
 
            blob._text = repo.texts.get_record_stream([(entry.file_id, entry.revision)], 'unordered', True).next().get_bytes_as('fulltext')
175
 
            sha = blob.id
 
155
            _, blob._text = repo.iter_files_bytes([(entry.file_id, entry.revision, path)]).next()
 
156
            sha = blob.sha().hexdigest()
176
157
            yield sha, blob, path
177
158
 
178
159
            name = urlutils.basename(path).encode("utf-8")
183
164
 
184
165
    while len(stack) > 1:
185
166
        tree.serialize()
186
 
        sha = tree.id
 
167
        sha = tree.sha().hexdigest()
187
168
        yield sha, tree, cur
188
169
        t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
189
170
        cur, tree = stack.pop()
190
171
        tree.add(*t)
191
172
 
192
173
    tree.serialize()
193
 
    yield tree.id, tree, cur
 
174
    yield tree.sha().hexdigest(), tree, cur
194
175
 
195
176
 
196
177
def revision_to_commit(rev, tree_sha, parent_lookup):
206
187
    for p in rev.parent_ids:
207
188
        git_p = parent_lookup(p)
208
189
        if git_p is not None:
209
 
            assert len(git_p) == 40, "unexpected length for %r" % git_p
210
190
            commit._parents.append(git_p)
211
 
    commit._message = rev.message.encode("utf-8")
212
 
    commit._committer = rev.committer.encode("utf-8")
213
 
    commit._author = rev.get_apparent_authors()[0].encode("utf-8")
 
191
    commit._message = rev.message
 
192
    commit._committer = rev.committer
 
193
    if 'author' in rev.properties:
 
194
        commit._author = rev.properties['author']
 
195
    else:
 
196
        commit._author = rev.committer
214
197
    commit._commit_time = long(rev.timestamp)
215
198
    commit.serialize()
216
199
    return commit