399
401
if roundtrip and self.mapping.BZR_FILE_IDS_FILE is not None:
400
402
b = self._create_fileid_map_blob(tree.inventory)
401
403
if b is not None:
402
root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
404
root_tree[self.mapping.BZR_FILE_IDS_FILE] = (
405
(stat.S_IFREG | 0644), b.id)
403
406
yield self.mapping.BZR_FILE_IDS_FILE, b, None
404
407
yield "", root_tree, root_ie
406
testament3 = StrictTestament3(rev, tree.inventory)
409
if getattr(StrictTestament3, "from_revision_tree", None):
410
testament3 = StrictTestament3(rev, tree)
412
testament3 = StrictTestament3(rev, tree.inventory)
407
413
verifiers = { "testament3-sha1": testament3.as_sha1() }
428
434
for path, obj, ie in self._revision_to_objects(rev, tree,
430
436
if isinstance(obj, Commit):
431
testament3 = StrictTestament3(rev, tree.inventory)
437
if getattr(StrictTestament3, "from_revision_tree", None):
438
testament3 = StrictTestament3(rev, tree)
440
testament3 = StrictTestament3(rev, tree.inventory)
432
441
ie = { "testament3-sha1": testament3.as_sha1() }
433
442
updater.add_object(obj, ie, path)
434
443
commit_obj = updater.finish()
530
539
def __contains__(self, sha):
531
540
# See if sha is in map
533
(type, type_data) = self.lookup_git_sha(sha)
535
return self.repository.has_revision(type_data[0])
537
return self.repository.texts.has_key(type_data)
539
return self.repository.has_revision(type_data[1])
542
for (type, type_data) in self.lookup_git_sha(sha):
544
if self.repository.has_revision(type_data[0]):
547
if self.repository.texts.has_key(type_data):
550
if self.repository.has_revision(type_data[1]):
553
raise AssertionError("Unknown object type '%s'" % type)
541
raise AssertionError("Unknown object type '%s'" % type)
545
def lookup_git_shas(self, shas, update_map=True):
546
from dulwich.protocol import ZERO_SHA
561
self._map_updated = False
562
self.repository.lock_read()
563
return LogicalLockResult(self.unlock)
565
def lock_write(self):
567
self._map_updated = False
568
self.repository.lock_write()
569
return LogicalLockResult(self.unlock)
572
return (self._locked is not None)
576
self._map_updated = False
577
self.repository.unlock()
579
def lookup_git_shas(self, shas):
549
582
if sha == ZERO_SHA:
550
ret[sha] = ("commit", (NULL_REVISION, None, {}))
583
ret[sha] = [("commit", (NULL_REVISION, None, {}))]
553
ret[sha] = self._cache.idmap.lookup_git_sha(sha)
586
ret[sha] = list(self._cache.idmap.lookup_git_sha(sha))
556
# if not, see if there are any unconverted revisions and add
557
# them to the map, search for sha in map again
558
self._update_sha_map()
561
ret[sha] = self._cache.idmap.lookup_git_sha(sha)
588
# if not, see if there are any unconverted revisions and
589
# add them to the map, search for sha in map again
590
self._update_sha_map()
592
ret[sha] = list(self._cache.idmap.lookup_git_sha(sha))
566
def lookup_git_sha(self, sha, update_map=True):
567
return self.lookup_git_shas([sha], update_map=update_map)[sha]
597
def lookup_git_sha(self, sha):
598
return self.lookup_git_shas([sha])[sha]
569
600
def __getitem__(self, sha):
570
601
if self._cache.content_cache is not None:
572
603
return self._cache.content_cache[sha]
575
(type, type_data) = self.lookup_git_sha(sha)
576
# convert object to git object
578
(revid, tree_sha, verifiers) = type_data
580
rev = self.repository.get_revision(revid)
581
except errors.NoSuchRevision:
582
trace.mutter('entry for %s %s in shamap: %r, but not found in '
583
'repository', type, sha, type_data)
585
commit = self._reconstruct_commit(rev, tree_sha, roundtrip=True,
587
_check_expected_sha(sha, commit)
590
(fileid, revision) = type_data
591
return self._reconstruct_blobs([(fileid, revision, sha)]).next()
593
(fileid, revid) = type_data
595
tree = self.tree_cache.revision_tree(revid)
596
rev = self.repository.get_revision(revid)
597
except errors.NoSuchRevision:
598
trace.mutter('entry for %s %s in shamap: %r, but not found in repository', type, sha, type_data)
600
unusual_modes = extract_unusual_modes(rev)
602
return self._reconstruct_tree(fileid, revid, tree.inventory,
603
unusual_modes, expected_sha=sha)
604
except errors.NoSuchRevision:
606
for (kind, type_data) in self.lookup_git_sha(sha):
607
# convert object to git object
609
(revid, tree_sha, verifiers) = type_data
611
rev = self.repository.get_revision(revid)
612
except errors.NoSuchRevision:
613
trace.mutter('entry for %s %s in shamap: %r, but not '
614
'found in repository', kind, sha, type_data)
616
commit = self._reconstruct_commit(rev, tree_sha,
617
roundtrip=True, verifiers=verifiers)
618
_check_expected_sha(sha, commit)
621
(fileid, revision) = type_data
622
blobs = self._reconstruct_blobs([(fileid, revision, sha)])
625
(fileid, revid) = type_data
627
tree = self.tree_cache.revision_tree(revid)
628
rev = self.repository.get_revision(revid)
629
except errors.NoSuchRevision:
630
trace.mutter('entry for %s %s in shamap: %r, but not found in repository', kind, sha, type_data)
632
unusual_modes = extract_unusual_modes(rev)
634
return self._reconstruct_tree(fileid, revid,
635
tree.inventory, unusual_modes, expected_sha=sha)
636
except errors.NoSuchRevision:
639
raise AssertionError("Unknown object type '%s'" % kind)
607
raise AssertionError("Unknown object type '%s'" % type)
609
643
def generate_lossy_pack_contents(self, have, want, progress=None,
610
644
get_tagged=None):
622
656
ret = self.lookup_git_shas(have + want)
623
657
for commit_sha in have:
625
(type, (revid, tree_sha)) = ret[commit_sha]
659
for (type, type_data) in ret[commit_sha]:
660
assert type == "commit"
661
processed.add(type_data[0])
629
assert type == "commit"
632
665
for commit_sha in want:
633
666
if commit_sha in have:
636
(type, (revid, tree_sha)) = ret[commit_sha]
669
for (type, type_data) in ret[commit_sha]:
670
assert type == "commit"
671
pending.add(type_data[0])
640
assert type == "commit"
643
todo = _find_missing_bzr_revids(self.repository.get_parent_map,
675
graph = self.repository.get_graph()
676
todo = _find_missing_bzr_revids(graph, pending, processed)
645
677
trace.mutter('sending revisions %r', todo)
647
679
pb = ui.ui_factory.nested_progress_bar()
649
681
for i, revid in enumerate(todo):
650
682
pb.update("generating git objects", i, len(todo))
651
rev = self.repository.get_revision(revid)
684
rev = self.repository.get_revision(revid)
685
except errors.NoSuchRevision:
652
687
tree = self.tree_cache.revision_tree(revid)
653
688
for path, obj, ie in self._revision_to_objects(rev, tree,
654
689
roundtrip=not lossy):