33
34
from bzrlib.plugins.git.commit import (
37
from bzrlib.plugins.git.inventory import (
36
40
from bzrlib.plugins.git.mapping import (
41
from bzrlib.plugins.git.tree import (
44
45
from bzrlib.plugins.git.versionedfiles import (
57
58
def __init__(self, gitdir, lockfiles):
58
ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
59
ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
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."""
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
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)
111
113
def all_revision_ids(self):
114
ret = set([revision.NULL_REVISION])
113
115
heads = self._git.refs.as_dict('refs/heads')
131
133
if revision_id == revision.NULL_REVISION:
132
134
parent_map[revision_id] = ()
134
hexsha, mapping = self.lookup_bzr_revision_id(revision_id)
136
commit = self._git.commit(hexsha)
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
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)
163
def lookup_foreign_revision_id(self, foreign_revid, mapping=None):
160
def lookup_revision_id(self, revid):
164
161
"""Lookup a revision id.
166
163
:param revid: Bazaar revision id.
167
164
:return: Tuple with git revisionid and mapping.
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()
173
169
def has_signature_for_revision_id(self, revision_id):
176
def lookup_bzr_revision_id(self, bzr_revid):
172
def lookup_git_revid(self, bzr_revid):
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)
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)
185
181
commit = self._git.commit(git_commit_id)
225
221
return self._git.fetch_objects(determine_wants, graph_walker, progress)
227
def _get_versioned_file_checker(self, text_key_references=None,
229
return GitVersionedFileChecker(self,
230
text_key_references=text_key_references, ancestors=ancestors)
233
class GitVersionedFileChecker(repository._VersionedFileChecker):
237
def _check_file_version_parents(self, texts, progress_bar):
224
class GitRevisionTree(revisiontree.RevisionTree):
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)
233
commit = store[git_id]
235
raise errors.NoSuchRevision(repository, revision_id)
236
self.tree = commit.tree
237
self._inventory = GitInventory(self.tree, self.mapping, store,
240
def get_revision_id(self):
241
return self._revision_id
243
def get_file_text(self, file_id, path=None):
245
entry = self._inventory._get_ie(path)
247
entry = self._inventory[file_id]
248
if entry.kind == 'directory': return ""
249
return entry.object.data
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
256
def get_foreign_tests_repository_factory(self):
257
from bzrlib.plugins.git.tests.test_repository import ForeignTestsRepositoryFactory
258
return ForeignTestsRepositoryFactory()
260
267
def network_name(self):