399
406
if roundtrip and self.mapping.BZR_FILE_IDS_FILE is not None:
400
407
b = self._create_fileid_map_blob(tree.inventory)
401
408
if b is not None:
402
root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
409
root_tree[self.mapping.BZR_FILE_IDS_FILE] = (
410
(stat.S_IFREG | 0644), b.id)
403
411
yield self.mapping.BZR_FILE_IDS_FILE, b, None
404
412
yield "", root_tree, root_ie
406
testament3 = StrictTestament3(rev, tree.inventory)
414
if getattr(StrictTestament3, "from_revision_tree", None):
415
testament3 = StrictTestament3(rev, tree)
417
testament3 = StrictTestament3(rev, tree.inventory)
407
418
verifiers = { "testament3-sha1": testament3.as_sha1() }
428
439
for path, obj, ie in self._revision_to_objects(rev, tree,
430
441
if isinstance(obj, Commit):
431
testament3 = StrictTestament3(rev, tree.inventory)
442
if getattr(StrictTestament3, "from_revision_tree", None):
443
testament3 = StrictTestament3(rev, tree)
445
testament3 = StrictTestament3(rev, tree.inventory)
432
446
ie = { "testament3-sha1": testament3.as_sha1() }
433
447
updater.add_object(obj, ie, path)
434
448
commit_obj = updater.finish()
487
501
self.mapping.BZR_DUMMY_FILE)
488
502
if (inv.root.file_id == fileid and
489
503
self.mapping.BZR_FILE_IDS_FILE is not None):
490
506
b = self._create_fileid_map_blob(inv)
491
507
# If this is the root tree, add the file ids
492
tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
493
_check_expected_sha(expected_sha, tree)
508
tree[self.mapping.BZR_FILE_IDS_FILE] = (
509
(stat.S_IFREG | 0644), b.id)
511
_check_expected_sha(expected_sha, tree)
496
514
def get_parents(self, sha):
530
543
def __contains__(self, sha):
531
544
# 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])
546
for (type, type_data) in self.lookup_git_sha(sha):
548
if self.repository.has_revision(type_data[0]):
551
if self.repository.texts.has_key(type_data):
554
if self.repository.has_revision(type_data[1]):
557
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
565
self._map_updated = False
566
self.repository.lock_read()
567
return LogicalLockResult(self.unlock)
569
def lock_write(self):
571
self._map_updated = False
572
self.repository.lock_write()
573
return LogicalLockResult(self.unlock)
576
return (self._locked is not None)
580
self._map_updated = False
581
self.repository.unlock()
583
def lookup_git_shas(self, shas):
549
586
if sha == ZERO_SHA:
550
ret[sha] = ("commit", (NULL_REVISION, None, {}))
587
ret[sha] = [("commit", (NULL_REVISION, None, {}))]
553
ret[sha] = self._cache.idmap.lookup_git_sha(sha)
590
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)
592
# if not, see if there are any unconverted revisions and
593
# add them to the map, search for sha in map again
594
self._update_sha_map()
596
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]
601
def lookup_git_sha(self, sha):
602
return self.lookup_git_shas([sha])[sha]
569
604
def __getitem__(self, sha):
570
605
if self._cache.content_cache is not None:
572
607
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:
610
for (kind, type_data) in self.lookup_git_sha(sha):
611
# convert object to git object
613
(revid, tree_sha, verifiers) = type_data
615
rev = self.repository.get_revision(revid)
616
except errors.NoSuchRevision:
617
trace.mutter('entry for %s %s in shamap: %r, but not '
618
'found in repository', kind, sha, type_data)
620
commit = self._reconstruct_commit(rev, tree_sha,
621
roundtrip=True, verifiers=verifiers)
622
_check_expected_sha(sha, commit)
625
(fileid, revision) = type_data
626
blobs = self._reconstruct_blobs([(fileid, revision, sha)])
629
(fileid, revid) = type_data
631
tree = self.tree_cache.revision_tree(revid)
632
rev = self.repository.get_revision(revid)
633
except errors.NoSuchRevision:
634
trace.mutter('entry for %s %s in shamap: %r, but not found in repository', kind, sha, type_data)
636
unusual_modes = extract_unusual_modes(rev)
638
return self._reconstruct_tree(fileid, revid,
639
tree.inventory, unusual_modes, expected_sha=sha)
640
except errors.NoSuchRevision:
643
raise AssertionError("Unknown object type '%s'" % kind)
607
raise AssertionError("Unknown object type '%s'" % type)
609
647
def generate_lossy_pack_contents(self, have, want, progress=None,
610
648
get_tagged=None):
622
660
ret = self.lookup_git_shas(have + want)
623
661
for commit_sha in have:
625
(type, (revid, tree_sha)) = ret[commit_sha]
663
for (type, type_data) in ret[commit_sha]:
664
assert type == "commit"
665
processed.add(type_data[0])
629
assert type == "commit"
632
669
for commit_sha in want:
633
670
if commit_sha in have:
636
(type, (revid, tree_sha)) = ret[commit_sha]
673
for (type, type_data) in ret[commit_sha]:
674
assert type == "commit"
675
pending.add(type_data[0])
640
assert type == "commit"
643
todo = _find_missing_bzr_revids(self.repository.get_parent_map,
679
graph = self.repository.get_graph()
680
todo = _find_missing_bzr_revids(graph, pending, processed)
645
681
trace.mutter('sending revisions %r', todo)
647
683
pb = ui.ui_factory.nested_progress_bar()
649
685
for i, revid in enumerate(todo):
650
686
pb.update("generating git objects", i, len(todo))
651
rev = self.repository.get_revision(revid)
688
rev = self.repository.get_revision(revid)
689
except errors.NoSuchRevision:
652
691
tree = self.tree_cache.revision_tree(revid)
653
692
for path, obj, ie in self._revision_to_objects(rev, tree,
654
693
roundtrip=not lossy):