/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

  • Committer: Jelmer Vernooij
  • Date: 2009-09-10 13:13:15 UTC
  • mto: (0.200.602 trunk)
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@samba.org-20090910131315-6890xg58pl2jseml
Allow serving remote URLs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    errors,
23
23
    graph,
24
24
    inventory,
 
25
    osutils,
25
26
    repository,
26
27
    revision,
27
28
    revisiontree,
33
34
from bzrlib.plugins.git.commit import (
34
35
    GitCommitBuilder,
35
36
    )
 
37
from bzrlib.plugins.git.inventory import (
 
38
    GitInventory,
 
39
    )
36
40
from bzrlib.plugins.git.mapping import (
37
41
    default_mapping,
38
42
    foreign_git,
39
43
    mapping_registry,
40
44
    )
41
 
from bzrlib.plugins.git.tree import (
42
 
    GitRevisionTree,
43
 
    )
44
45
from bzrlib.plugins.git.versionedfiles import (
45
46
    GitRevisions,
46
47
    GitTexts,
55
56
    vcs = foreign_git
56
57
 
57
58
    def __init__(self, gitdir, lockfiles):
58
 
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
 
59
        ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, 
59
60
            lockfiles)
60
61
        from bzrlib.plugins.git import fetch, push
61
 
        for optimiser in [fetch.InterRemoteGitNonGitRepository,
 
62
        for optimiser in [fetch.InterRemoteGitNonGitRepository, 
62
63
                          fetch.InterLocalGitNonGitRepository,
63
64
                          fetch.InterGitGitRepository,
64
65
                          push.InterToLocalGitRepository,
97
98
    """Git repository on the file system."""
98
99
 
99
100
    def __init__(self, gitdir, lockfiles):
100
 
        # FIXME: This also caches negatives. Need to be more careful
 
101
        # FIXME: This also caches negatives. Need to be more careful 
101
102
        # about this once we start writing to git
102
103
        self._parents_provider = graph.CachingParentsProvider(self)
103
104
        GitRepository.__init__(self, gitdir, lockfiles)
104
105
        self.base = gitdir.root_transport.base
105
106
        self._git = gitdir._git
 
107
        self.texts = None
106
108
        self.signatures = None
107
 
        self.revisions = GitRevisions(self, self._git.object_store)
 
109
        self.revisions = GitRevisions(self._git.object_store)
108
110
        self.inventories = None
109
111
        self.texts = GitTexts(self)
110
112
 
111
113
    def all_revision_ids(self):
112
 
        ret = set([])
 
114
        ret = set([revision.NULL_REVISION])
113
115
        heads = self._git.refs.as_dict('refs/heads')
114
116
        if heads == {}:
115
117
            return ret
131
133
            if revision_id == revision.NULL_REVISION:
132
134
                parent_map[revision_id] = ()
133
135
                continue
134
 
            hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
135
 
            try:
136
 
                commit = self._git.commit(hexsha)
137
 
            except KeyError:
138
 
                continue
 
136
            hexsha, mapping = self.lookup_git_revid(revision_id)
 
137
            commit  = self._git.commit(hexsha)
139
138
            if commit is None:
140
 
                # Older versions of Dulwich used to return None rather than
141
 
                # raise KeyError.
142
139
                continue
143
140
            else:
144
141
                parent_map[revision_id] = [mapping.revision_id_foreign_to_bzr(p) for p in commit.parents]
160
157
    def get_signature_text(self, revision_id):
161
158
        raise errors.NoSuchRevision(self, revision_id)
162
159
 
163
 
    def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
 
160
    def lookup_revision_id(self, revid):
164
161
        """Lookup a revision id.
165
 
 
 
162
        
166
163
        :param revid: Bazaar revision id.
167
164
        :return: Tuple with git revisionid and mapping.
168
165
        """
169
 
        if mapping is None:
170
 
            mapping = self.get_mapping()
171
 
        return mapping.revision_id_foreign_to_bzr(foreign_revid)
 
166
        # Yes, this doesn't really work, but good enough as a stub
 
167
        return osutils.sha(revid).hexdigest(), self.get_mapping()
172
168
 
173
169
    def has_signature_for_revision_id(self, revision_id):
174
170
        return False
175
171
 
176
 
    def lookup_bzr_revision_id(self, bzr_revid):
 
172
    def lookup_git_revid(self, bzr_revid):
177
173
        try:
178
174
            return mapping_registry.revision_id_bzr_to_foreign(bzr_revid)
179
175
        except errors.InvalidRevisionId:
180
176
            raise errors.NoSuchRevision(self, bzr_revid)
181
177
 
182
178
    def get_revision(self, revision_id):
183
 
        git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
 
179
        git_commit_id, mapping = self.lookup_git_revid(revision_id)
184
180
        try:
185
181
            commit = self._git.commit(git_commit_id)
186
182
        except KeyError:
224
220
        progress=None):
225
221
        return self._git.fetch_objects(determine_wants, graph_walker, progress)
226
222
 
227
 
    def _get_versioned_file_checker(self, text_key_references=None,
228
 
                        ancestors=None):
229
 
        return GitVersionedFileChecker(self,
230
 
            text_key_references=text_key_references, ancestors=ancestors)
231
 
    
232
 
 
233
 
class GitVersionedFileChecker(repository._VersionedFileChecker):
234
 
 
235
 
    file_ids = []
236
 
 
237
 
    def _check_file_version_parents(self, texts, progress_bar):
238
 
        return {}, []
 
223
 
 
224
class GitRevisionTree(revisiontree.RevisionTree):
 
225
 
 
226
    def __init__(self, repository, revision_id):
 
227
        self._revision_id = revision_id
 
228
        self._repository = repository
 
229
        store = repository._git.object_store
 
230
        assert isinstance(revision_id, str)
 
231
        git_id, self.mapping = repository.lookup_git_revid(revision_id)
 
232
        try:
 
233
            commit = store[git_id]
 
234
        except KeyError, r:
 
235
            raise errors.NoSuchRevision(repository, revision_id)
 
236
        self.tree = commit.tree
 
237
        self._inventory = GitInventory(self.tree, self.mapping, store, 
 
238
                                       revision_id)
 
239
 
 
240
    def get_revision_id(self):
 
241
        return self._revision_id
 
242
 
 
243
    def get_file_text(self, file_id, path=None):
 
244
        if path is not None:
 
245
            entry = self._inventory._get_ie(path)
 
246
        else:
 
247
            entry = self._inventory[file_id]
 
248
        if entry.kind == 'directory': return ""
 
249
        return entry.object.data
239
250
 
240
251
 
241
252
class GitRepositoryFormat(repository.RepositoryFormat):
253
264
    def check_conversion_target(self, target_repo_format):
254
265
        return target_repo_format.rich_root_data
255
266
 
256
 
    def get_foreign_tests_repository_factory(self):
257
 
        from bzrlib.plugins.git.tests.test_repository import ForeignTestsRepositoryFactory
258
 
        return ForeignTestsRepositoryFactory()
259
 
 
260
267
    def network_name(self):
261
268
        return "git"