/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

Move conversion functions to mapping, use fetch_objects() from repository if present.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Converters, etc for going between Bazaar and Git ids."""
18
18
 
19
 
from bzrlib import errors, foreign, urlutils
 
19
from bzrlib import errors, foreign
20
20
from bzrlib.inventory import ROOT_ID
21
21
from bzrlib.foreign import (
22
22
        ForeignVcs, 
122
122
 
123
123
 
124
124
def inventory_to_tree_and_blobs(repo, mapping, revision_id):
125
 
    from dulwich.objects import Tree, Blob
126
 
    from bzrlib.inventory import InventoryDirectory, InventoryFile
127
 
    import stat
128
125
    stack = []
129
126
    cur = ""
130
127
    tree = Tree()
131
128
 
132
129
    inv = repo.get_inventory(revision_id)
133
130
 
134
 
    # stack contains the set of trees that we haven't 
135
 
    # finished constructing
136
 
 
137
131
    for path, entry in inv.iter_entries():
138
132
        while stack and not path.startswith(cur):
139
133
            tree.serialize()
140
134
            sha = tree.sha().hexdigest()
141
 
            yield sha, tree, cur
142
 
            t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
 
135
            yield sha, tree, path
 
136
            t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
143
137
            cur, tree = stack.pop()
144
138
            tree.add(*t)
145
139
 
152
146
            #FIXME: We can make potentially make this Lazy to avoid shaing lots of stuff
153
147
            # and having all these objects in memory at once
154
148
            blob = Blob()
155
 
            _, blob._text = repo.iter_files_bytes([(entry.file_id, entry.revision, path)]).next()
 
149
            _, blob._text = repo.iter_files_bytes([(entry.file_id, revision_id, path)]).next()
156
150
            sha = blob.sha().hexdigest()
157
151
            yield sha, blob, path
158
152
 
159
 
            name = urlutils.basename(path).encode("utf-8")
 
153
            name = splitpath(path)[-1:][0].encode('UTF-8')
160
154
            mode = stat.S_IFREG | 0644
161
155
            if entry.executable:
162
156
                mode |= 0111
165
159
    while len(stack) > 1:
166
160
        tree.serialize()
167
161
        sha = tree.sha().hexdigest()
168
 
        yield sha, tree, cur
169
 
        t = (stat.S_IFDIR, urlutils.basename(cur).encode('UTF-8'), sha)
 
162
        yield sha, tree, path
 
163
        t = (stat.S_IFDIR, splitpath(cur)[-1:][0].encode('UTF-8'), sha)
170
164
        cur, tree = stack.pop()
171
165
        tree.add(*t)
172
166
 
173
167
    tree.serialize()
174
 
    yield tree.sha().hexdigest(), tree, cur
 
168
    yield tree.sha().hexdigest(), tree, path
175
169
 
176
170
 
177
171
def revision_to_commit(rev, tree_sha, parent_lookup):
185
179
    commit = Commit()
186
180
    commit._tree = tree_sha
187
181
    for p in rev.parent_ids:
188
 
        git_p = parent_lookup(p)
189
 
        if git_p is not None:
190
 
            commit._parents.append(git_p)
191
 
    commit._message = rev.message.encode("utf-8")
192
 
    commit._committer = rev.committer.encode("utf-8")
193
 
    commit._author = rev.get_apparent_author().encode("utf-8")
 
182
        commit._parents.append(parent_lookup(p))
 
183
    commit._message = rev.message
 
184
    commit._committer = rev.committer
 
185
    if 'author' in rev.properties:
 
186
        commit._author = rev.properties['author']
 
187
    else:
 
188
        commit._author = rev.committer
194
189
    commit._commit_time = long(rev.timestamp)
195
190
    commit.serialize()
196
191
    return commit