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

Share more infrastructure between LocalGitDir and RemoteGitDir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    )
35
35
from bzrlib.foreign import (
36
36
        ForeignRepository,
 
37
        ForeignRevision,
37
38
        )
38
39
from bzrlib.trace import mutter
39
40
from bzrlib.transport import get_transport
175
176
        except KeyError:
176
177
            raise errors.NoSuchRevision(self, revision_id)
177
178
        # print "fetched revision:", git_commit_id
178
 
        revision = self.get_mapping().import_commit(commit)
 
179
        revision = self._parse_rev(commit, self.get_mapping())
179
180
        assert revision is not None
180
181
        return revision
181
182
 
190
191
    def get_revisions(self, revids):
191
192
        return [self.get_revision(r) for r in revids]
192
193
 
 
194
    @classmethod
 
195
    def _parse_rev(klass, commit, mapping):
 
196
        """Convert a git commit to a bzr revision.
 
197
 
 
198
        :return: a `bzrlib.revision.Revision` object.
 
199
        """
 
200
        if commit is None:
 
201
            raise AssertionError("Commit object can't be None")
 
202
        rev = ForeignRevision(commit.id, mapping, mapping.revision_id_foreign_to_bzr(commit.id))
 
203
        rev.parent_ids = tuple([mapping.revision_id_foreign_to_bzr(p) for p in commit.parents])
 
204
        rev.message = commit.message.decode("utf-8", "replace")
 
205
        rev.committer = str(commit.committer).decode("utf-8", "replace")
 
206
        if commit.committer != commit.author:
 
207
            rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
 
208
        rev.timestamp = commit.commit_time
 
209
        rev.timezone = 0
 
210
        return rev
 
211
 
193
212
    def revision_trees(self, revids):
194
213
        for revid in revids:
195
214
            yield self.revision_tree(revid)
202
221
            inv.revision_id = revision_id
203
222
            return revisiontree.RevisionTree(self, inv, revision_id)
204
223
 
205
 
        return GitRevisionTree(self, self.get_mapping(), revision_id)
 
224
        return GitRevisionTree(self, revision_id)
206
225
 
207
226
    def get_inventory(self, revision_id):
208
227
        assert revision_id != None
215
234
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
216
235
 
217
236
 
 
237
def escape_file_id(file_id):
 
238
    return file_id.replace('_', '__').replace(' ', '_s')
 
239
 
 
240
 
 
241
def unescape_file_id(file_id):
 
242
    return file_id.replace("_s", " ").replace("__", "_")
 
243
 
 
244
 
218
245
class GitRevisionTree(revisiontree.RevisionTree):
219
246
 
220
 
    def __init__(self, repository, mapping, revision_id):
 
247
    def __init__(self, repository, revision_id):
221
248
        self._repository = repository
222
249
        self.revision_id = revision_id
223
 
        assert isinstance(revision_id, str)
224
 
        self.mapping = mapping
225
 
        git_id = repository.lookup_git_revid(revision_id, self.mapping)
226
 
        try:
227
 
            commit = repository._git.commit(git_id)
228
 
        except KeyError, r:
229
 
            raise errors.NoSuchRevision(repository, revision_id)
230
 
        self.tree = commit.tree
 
250
        git_id = repository.lookup_git_revid(revision_id, repository.get_mapping())
 
251
        self.tree = repository._git.commit(git_id).tree
231
252
        self._inventory = inventory.Inventory(revision_id=revision_id)
232
253
        self._inventory.root.revision = revision_id
233
254
        self._build_inventory(self.tree, self._inventory.root, "")
249
270
                child_path = name
250
271
            else:
251
272
                child_path = urlutils.join(path, name)
252
 
            file_id = self.mapping.generate_file_id(child_path)
 
273
            file_id = escape_file_id(child_path.encode('utf-8'))
253
274
            entry_kind = (mode & 0700000) / 0100000
254
275
            if entry_kind == 0:
255
276
                child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)