/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

Make API resemble that of python-git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    urlutils,
33
33
    versionedfile,
34
34
    )
 
35
from bzrlib.foreign import (
 
36
        ForeignRevision,
 
37
        )
35
38
from bzrlib.transport import get_transport
36
39
 
37
40
from bzrlib.plugins.git.foreign import (
38
 
    versionedfiles
 
41
    ForeignRepository,
 
42
    versionedfiles,
39
43
    )
40
44
from bzrlib.plugins.git.mapping import default_mapping
41
45
 
42
46
 
43
 
class GitRepository(repository.Repository):
 
47
class GitRepository(ForeignRepository):
44
48
    """An adapter to git repositories for bzr."""
45
49
 
46
50
    _serializer = None
119
123
        git_commit_id = self.lookup_git_revid(revision_id, default_mapping)
120
124
        commit = self._git.commit(git_commit_id)
121
125
        # print "fetched revision:", git_commit_id
122
 
        revision = self._parse_rev(commit)
 
126
        revision = self._parse_rev(commit, default_mapping)
123
127
        return revision
124
128
 
125
129
    def has_revision(self, revision_id):
134
138
        return [self.get_revision(r) for r in revisions]
135
139
 
136
140
    @classmethod
137
 
    def _parse_rev(klass, commit):
 
141
    def _parse_rev(klass, commit, mapping):
138
142
        """Convert a git commit to a bzr revision.
139
143
 
140
144
        :return: a `bzrlib.revision.Revision` object.
141
145
        """
142
 
        rev = revision.Revision(default_mapping.revision_id_foreign_to_bzr(commit.id))
143
 
        rev.parent_ids = tuple([default_mapping.revision_id_foreign_to_bzr(p.id) for p in commit.parents])
144
 
        rev.inventory_sha1 = ""
 
146
        rev = ForeignRevision(commit.id, mapping, mapping.revision_id_foreign_to_bzr(commit.id))
 
147
        rev.parent_ids = tuple([mapping.revision_id_foreign_to_bzr(p.id) for p in commit.parents])
145
148
        rev.message = commit.message.decode("utf-8", "replace")
146
 
        rev.committer = str(commit.committer)
147
 
        rev.properties['author'] = str(commit.author)
 
149
        rev.committer = str(commit.committer).decode("utf-8", "replace")
 
150
        rev.properties['author'] = str(commit.author).decode("utf-8", "replace")
148
151
        rev.timestamp = time.mktime(commit.committed_date)
149
152
        rev.timezone = 0
150
153
        return rev