/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

Clean up trailing whitespace.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    repository,
27
27
    revision,
28
28
    revisiontree,
29
 
    ui,
30
 
    urlutils,
31
29
    )
32
30
from bzrlib.foreign import (
33
31
    ForeignRepository,
34
32
    )
35
 
from bzrlib.trace import (
36
 
    mutter,
37
 
    )
38
 
from bzrlib.transport import (
39
 
    get_transport,
40
 
    )
41
33
 
42
34
from bzrlib.plugins.git.commit import (
43
35
    GitCommitBuilder,
44
36
    )
45
 
from bzrlib.plugins.git.inventory import (
46
 
    GitInventory,
47
 
    )
48
37
from bzrlib.plugins.git.mapping import (
49
38
    default_mapping,
50
39
    foreign_git,
51
40
    mapping_registry,
52
41
    )
 
42
from bzrlib.plugins.git.tree import (
 
43
    GitRevisionTree,
 
44
    InterGitRevisionTrees,
 
45
    )
53
46
from bzrlib.plugins.git.versionedfiles import (
54
47
    GitRevisions,
55
48
    GitTexts,
64
57
    vcs = foreign_git
65
58
 
66
59
    def __init__(self, gitdir, lockfiles):
67
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
 
60
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
68
61
            lockfiles)
69
62
        from bzrlib.plugins.git import fetch, push
70
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
 
63
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
71
64
                          fetch.InterLocalGitNonGitRepository,
72
65
                          fetch.InterGitGitRepository,
73
66
                          push.InterToLocalGitRepository,
106
99
    """Git repository on the file system."""
107
100
 
108
101
    def __init__(self, gitdir, lockfiles):
109
 
        # FIXME: This also caches negatives. Need to be more careful 
 
102
        # FIXME: This also caches negatives. Need to be more careful
110
103
        # about this once we start writing to git
111
104
        self._parents_provider = graph.CachingParentsProvider(self)
112
105
        GitRepository.__init__(self, gitdir, lockfiles)
113
106
        self.base = gitdir.root_transport.base
114
107
        self._git = gitdir._git
115
 
        self.texts = None
116
108
        self.signatures = None
117
 
        self.revisions = GitRevisions(self._git.object_store)
 
109
        self.revisions = GitRevisions(self, self._git.object_store)
118
110
        self.inventories = None
119
111
        self.texts = GitTexts(self)
120
112
 
141
133
            if revision_id == revision.NULL_REVISION:
142
134
                parent_map[revision_id] = ()
143
135
                continue
144
 
            hexsha, mapping = self.lookup_git_revid(revision_id)
145
 
            commit  = self._git.commit(hexsha)
 
136
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
 
137
            try:
 
138
                commit = self._git.commit(hexsha)
 
139
            except KeyError:
 
140
                continue
146
141
            if commit is None:
 
142
                # Older versions of Dulwich used to return None rather than
 
143
                # raise KeyError.
147
144
                continue
148
145
            else:
149
146
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
165
162
    def get_signature_text(self, revision_id):
166
163
        raise errors.NoSuchRevision(self, revision_id)
167
164
 
168
 
    def lookup_revision_id(self, revid):
 
165
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
169
166
        """Lookup a revision id.
170
 
        
 
167
 
171
168
        :param revid: Bazaar revision id.
172
169
        :return: Tuple with git revisionid and mapping.
173
170
        """
174
 
        # Yes, this doesn't really work, but good enough as a stub
175
 
        return osutils.sha(rev_id).hexdigest(), self.get_mapping()
 
171
        if mapping is None:
 
172
            mapping = self.get_mapping()
 
173
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
176
174
 
177
175
    def has_signature_for_revision_id(self, revision_id):
178
176
        return False
179
177
 
180
 
    def lookup_git_revid(self, bzr_revid):
 
178
    def lookup_bzr_revision_id(self, bzr_revid):
181
179
        try:
182
180
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
183
181
        except errors.InvalidRevisionId:
184
182
            raise errors.NoSuchRevision(self, bzr_revid)
185
183
 
186
184
    def get_revision(self, revision_id):
187
 
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
 
185
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
188
186
        try:
189
187
            commit = self._git.commit(git_commit_id)
190
188
        except KeyError:
229
227
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
230
228
 
231
229
 
232
 
class GitRevisionTree(revisiontree.RevisionTree):
233
 
 
234
 
    def __init__(self, repository, revision_id):
235
 
        self._revision_id = revision_id
236
 
        self._repository = repository
237
 
        store = repository._git.object_store
238
 
        assert isinstance(revision_id, str)
239
 
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
240
 
        try:
241
 
            commit = store[git_id]
242
 
        except KeyError, r:
243
 
            raise errors.NoSuchRevision(repository, revision_id)
244
 
        self.tree = commit.tree
245
 
        self._inventory = GitInventory(self.tree, self.mapping, store, 
246
 
                                       revision_id)
247
 
 
248
 
    def get_revision_id(self):
249
 
        return self._revision_id
250
 
 
251
 
    def get_file_text(self, file_id, path=None):
252
 
        if path is not None:
253
 
            entry = self._inventory._get_ie(path)
254
 
        else:
255
 
            entry = self._inventory[file_id]
256
 
        if entry.kind == 'directory': return ""
257
 
        return entry.object.data
258
 
 
259
 
 
260
230
class GitRepositoryFormat(repository.RepositoryFormat):
261
231
    """Git repository format."""
262
232
 
267
237
        return "Git Repository"
268
238
 
269
239
    def initialize(self, url, shared=False, _internal=False):
270
 
        raise bzr_errors.UninitializableFormat(self)
 
240
        raise errors.UninitializableFormat(self)
271
241
 
272
242
    def check_conversion_target(self, target_repo_format):
273
243
        return target_repo_format.rich_root_data
274
244
 
 
245
    def get_foreign_tests_repository_factory(self):
 
246
        from bzrlib.plugins.git.tests.test_repository import ForeignTestsRepositoryFactory
 
247
        return ForeignTestsRepositoryFactory()
 
248
 
275
249
    def network_name(self):
276
250
        return "git"