401
399
if roundtrip and self.mapping.BZR_FILE_IDS_FILE is not None:
402
400
b = self._create_fileid_map_blob(tree.inventory)
403
401
if b is not None:
404
root_tree[self.mapping.BZR_FILE_IDS_FILE] = (
405
(stat.S_IFREG | 0644), b.id)
402
root_tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
406
403
yield self.mapping.BZR_FILE_IDS_FILE, b, None
407
404
yield "", root_tree, root_ie
409
if getattr(StrictTestament3, "from_revision_tree", None):
410
testament3 = StrictTestament3(rev, tree)
412
testament3 = StrictTestament3(rev, tree.inventory)
406
testament3 = StrictTestament3(rev, tree.inventory)
413
407
verifiers = { "testament3-sha1": testament3.as_sha1() }
434
428
for path, obj, ie in self._revision_to_objects(rev, tree,
436
430
if isinstance(obj, Commit):
437
if getattr(StrictTestament3, "from_revision_tree", None):
438
testament3 = StrictTestament3(rev, tree)
440
testament3 = StrictTestament3(rev, tree.inventory)
431
testament3 = StrictTestament3(rev, tree.inventory)
441
432
ie = { "testament3-sha1": testament3.as_sha1() }
442
433
updater.add_object(obj, ie, path)
443
434
commit_obj = updater.finish()
496
487
self.mapping.BZR_DUMMY_FILE)
497
488
if (inv.root.file_id == fileid and
498
489
self.mapping.BZR_FILE_IDS_FILE is not None):
501
490
b = self._create_fileid_map_blob(inv)
502
491
# If this is the root tree, add the file ids
503
tree[self.mapping.BZR_FILE_IDS_FILE] = (
504
(stat.S_IFREG | 0644), b.id)
506
_check_expected_sha(expected_sha, tree)
492
tree[self.mapping.BZR_FILE_IDS_FILE] = ((stat.S_IFREG | 0644), b.id)
493
_check_expected_sha(expected_sha, tree)
509
496
def get_parents(self, sha):
542
530
def __contains__(self, sha):
543
531
# See if sha is in map
545
for (type, type_data) in self.lookup_git_sha(sha):
547
if self.repository.has_revision(type_data[0]):
550
if self.repository.texts.has_key(type_data):
553
if self.repository.has_revision(type_data[1]):
556
raise AssertionError("Unknown object type '%s'" % type)
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])
541
raise AssertionError("Unknown object type '%s'" % type)
564
self._map_updated = False
565
self.repository.lock_read()
566
return LogicalLockResult(self.unlock)
568
def lock_write(self):
570
self._map_updated = False
571
self.repository.lock_write()
572
return LogicalLockResult(self.unlock)
575
return (self._locked is not None)
579
self._map_updated = False
580
self.repository.unlock()
582
def lookup_git_shas(self, shas):
545
def lookup_git_shas(self, shas, update_map=True):
546
from dulwich.protocol import ZERO_SHA
585
549
if sha == ZERO_SHA:
586
ret[sha] = [("commit", (NULL_REVISION, None, {}))]
550
ret[sha] = ("commit", (NULL_REVISION, None, {}))
589
ret[sha] = list(self._cache.idmap.lookup_git_sha(sha))
553
ret[sha] = self._cache.idmap.lookup_git_sha(sha)
591
# if not, see if there are any unconverted revisions and
592
# add them to the map, search for sha in map again
593
self._update_sha_map()
595
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)
600
def lookup_git_sha(self, sha):
601
return self.lookup_git_shas([sha])[sha]
566
def lookup_git_sha(self, sha, update_map=True):
567
return self.lookup_git_shas([sha], update_map=update_map)[sha]
603
569
def __getitem__(self, sha):
604
570
if self._cache.content_cache is not None:
606
572
return self._cache.content_cache[sha]
609
for (kind, type_data) in self.lookup_git_sha(sha):
610
# convert object to git object
612
(revid, tree_sha, verifiers) = type_data
614
rev = self.repository.get_revision(revid)
615
except errors.NoSuchRevision:
616
trace.mutter('entry for %s %s in shamap: %r, but not '
617
'found in repository', kind, sha, type_data)
619
commit = self._reconstruct_commit(rev, tree_sha,
620
roundtrip=True, verifiers=verifiers)
621
_check_expected_sha(sha, commit)
624
(fileid, revision) = type_data
625
blobs = self._reconstruct_blobs([(fileid, revision, sha)])
628
(fileid, revid) = type_data
630
tree = self.tree_cache.revision_tree(revid)
631
rev = self.repository.get_revision(revid)
632
except errors.NoSuchRevision:
633
trace.mutter('entry for %s %s in shamap: %r, but not found in repository', kind, sha, type_data)
635
unusual_modes = extract_unusual_modes(rev)
637
return self._reconstruct_tree(fileid, revid,
638
tree.inventory, unusual_modes, expected_sha=sha)
639
except errors.NoSuchRevision:
642
raise AssertionError("Unknown object type '%s'" % kind)
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:
607
raise AssertionError("Unknown object type '%s'" % type)
646
609
def generate_lossy_pack_contents(self, have, want, progress=None,
647
610
get_tagged=None):
659
622
ret = self.lookup_git_shas(have + want)
660
623
for commit_sha in have:
662
for (type, type_data) in ret[commit_sha]:
663
assert type == "commit"
664
processed.add(type_data[0])
625
(type, (revid, tree_sha)) = ret[commit_sha]
629
assert type == "commit"
668
632
for commit_sha in want:
669
633
if commit_sha in have:
672
for (type, type_data) in ret[commit_sha]:
673
assert type == "commit"
674
pending.add(type_data[0])
636
(type, (revid, tree_sha)) = ret[commit_sha]
640
assert type == "commit"
678
graph = self.repository.get_graph()
679
todo = _find_missing_bzr_revids(graph, pending, processed)
643
todo = _find_missing_bzr_revids(self.repository.get_parent_map,
680
645
trace.mutter('sending revisions %r', todo)
682
647
pb = ui.ui_factory.nested_progress_bar()
684
649
for i, revid in enumerate(todo):
685
650
pb.update("generating git objects", i, len(todo))
687
rev = self.repository.get_revision(revid)
688
except errors.NoSuchRevision:
651
rev = self.repository.get_revision(revid)
690
652
tree = self.tree_cache.revision_tree(revid)
691
653
for path, obj, ie in self._revision_to_objects(rev, tree,
692
654
roundtrip=not lossy):