57
62
_commit_builder_class = GitCommitBuilder
60
66
def __init__(self, gitdir, lockfiles):
61
ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir,
67
ForeignRepository.__init__(self, GitRepositoryFormat(), gitdir, lockfiles)
63
68
from bzrlib.plugins.git import fetch, push
64
69
for optimiser in [fetch.InterRemoteGitNonGitRepository,
65
70
fetch.InterLocalGitNonGitRepository,
91
96
interrepo = repository.InterRepository.get(source, self)
92
97
return interrepo.dfetch(stop_revision)
99
def add_signature_text(self, revid, signature):
100
raise errors.UnsupportedOperation(self.add_signature_text, self)
95
103
class LocalGitRepository(GitRepository):
96
104
"""Git repository on the file system."""
111
119
if not isinstance(o, Commit):
113
121
rev, roundtrip_revid, verifiers = mapping.import_commit(o,
114
self.lookup_foreign_revision_id)
122
mapping.revision_id_foreign_to_bzr)
115
123
yield o.id, rev.revision_id, roundtrip_revid
117
125
def all_revision_ids(self):
134
142
commit = self._git[hexsha]
137
parent_map[revision_id] = [
138
146
self.lookup_foreign_revision_id(p, mapping)
139
147
for p in commit.parents]
149
parents = [revision.NULL_REVISION]
150
parent_map[revision_id] = tuple(parents)
140
151
return parent_map
142
153
def get_ancestry(self, revision_id, topo_sorted=True):
165
178
assert type(foreign_revid) is str
166
179
if mapping is None:
167
180
mapping = self.get_mapping()
168
from dulwich.protocol import (
171
181
if foreign_revid == ZERO_SHA:
172
182
return revision.NULL_REVISION
173
183
commit = self._git[foreign_revid]
184
while isinstance(commit, Tag):
185
commit = self._git[commit.object[1]]
174
186
rev, roundtrip_revid, verifiers = mapping.import_commit(commit,
187
mapping.revision_id_foreign_to_bzr)
176
188
# FIXME: check testament before doing this?
177
189
if roundtrip_revid:
178
190
return roundtrip_revid
189
201
if mapping is None:
190
202
mapping = self.get_mapping()
192
return (self._git.refs[mapping.revid_as_refname(bzr_revid)],
204
return (self._git.refs[mapping.revid_as_refname(bzr_revid)], mapping)
195
206
# Update refs from Git commit objects
196
207
# FIXME: Hitting this a lot will be very inefficient...
204
215
raise errors.NoSuchRevision(self, bzr_revid)
206
217
def get_revision(self, revision_id):
218
if not isinstance(revision_id, str):
219
raise errors.InvalidRevisionId(revision_id, self)
207
220
git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
209
222
commit = self._git[git_commit_id]
220
233
def has_revision(self, revision_id):
234
"""See Repository.has_revision."""
235
if revision_id == revision.NULL_REVISION:
222
238
git_commit_id, mapping = self.lookup_bzr_revision_id(revision_id)
223
239
except errors.NoSuchRevision:
225
241
return (git_commit_id in self._git)
227
243
def has_revisions(self, revision_ids):
244
"""See Repository.has_revisions."""
228
245
return set(filter(self.has_revision, revision_ids))
230
247
def get_revisions(self, revids):
248
"""See Repository.get_revisions."""
231
249
return [self.get_revision(r) for r in revids]
233
251
def revision_trees(self, revids):
252
"""See Repository.revision_trees."""
234
253
for revid in revids:
235
254
yield self.revision_tree(revid)
237
256
def revision_tree(self, revision_id):
257
"""See Repository.revision_tree."""
238
258
revision_id = revision.ensure_null(revision_id)
239
259
if revision_id == revision.NULL_REVISION:
240
260
inv = inventory.Inventory(root_id=None)
241
261
inv.revision_id = revision_id
242
return revisiontree.RevisionTree(self, inv, revision_id)
262
return InventoryRevisionTree(self, inv, revision_id)
243
263
return GitRevisionTree(self, revision_id)
245
265
def get_inventory(self, revision_id):
246
assert revision_id != None
247
return self.revision_tree(revision_id).inventory
266
raise NotImplementedError(self.get_inventory)
249
268
def set_make_working_trees(self, trees):
269
raise NotImplementedError(self.set_make_working_trees)
252
271
def fetch_objects(self, determine_wants, graph_walker, resolve_ext_ref,
254
273
return self._git.fetch_objects(determine_wants, graph_walker, progress)
256
def _get_versioned_file_checker(self, text_key_references=None,
275
def _get_versioned_file_checker(self, text_key_references=None, ancestors=None):
258
276
return GitVersionedFileChecker(self,
259
277
text_key_references=text_key_references, ancestors=ancestors)
273
291
supports_tree_reference = False
274
292
rich_root_data = True
293
supports_leaving_lock = False
295
supports_funky_characters = True
296
supports_external_lookups = False
297
supports_full_versioned_files = False
298
supports_revision_signatures = False
299
revision_graph_can_have_wrong_parents = False
302
def _matchingbzrdir(self):
303
from bzrlib.plugins.git.dir import LocalGitControlDirFormat
304
return LocalGitControlDirFormat()
276
306
def get_format_description(self):
277
307
return "Git Repository"
279
def initialize(self, url, shared=False, _internal=False):
280
raise errors.UninitializableFormat(self)
309
def initialize(self, controldir, shared=False, _internal=False):
310
from bzrlib.plugins.git.dir import GitDir
311
if not isinstance(controldir, GitDir):
312
raise errors.UninitializableFormat(self)
313
return controldir.open_repository()
282
315
def check_conversion_target(self, target_repo_format):
283
316
return target_repo_format.rich_root_data