60
60
takes_args = ["src_location", "dest_location?"]
62
62
def run(self, src_location, dest_location=None):
63
from bzrlib.bzrdir import BzrDir, format_registry
68
from bzrlib.bzrdir import (
64
72
from bzrlib.errors import (
66
74
NoRepositoryPresent,
69
77
from bzrlib.repository import Repository
78
from bzrlib.plugins.git.fetch import InterGitNonGitRepository
71
79
from bzrlib.plugins.git.repository import GitRepository
73
81
if dest_location is None:
86
94
except NoRepositoryPresent:
87
95
target_repo = target_bzrdir.create_repository(shared=True)
89
target_repo.fetch(source_repo)
90
for name, ref in source_repo._git.heads().iteritems():
91
head_loc = os.path.join(dest_location, name)
93
head_bzrdir = BzrDir.open(head_loc)
94
except NotBranchError:
95
head_bzrdir = BzrDir.create(head_loc, format=format)
97
head_branch = head_bzrdir.open_branch()
98
except NotBranchError:
99
head_branch = head_bzrdir.create_branch()
100
head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
97
interrepo = InterGitNonGitRepository(source_repo, target_repo)
98
mapping = source_repo.get_mapping()
99
refs = interrepo.fetch_refs()
100
pb = ui.ui_factory.nested_progress_bar()
102
for i, (name, ref) in enumerate(refs.iteritems()):
103
pb.update("creating branches", i, len(refs))
104
if name.endswith("^{}"):
106
head_loc = os.path.join(dest_location, name)
108
head_bzrdir = BzrDir.open(head_loc)
109
except NotBranchError:
110
parent_path = urlutils.dirname(head_loc)
111
if not os.path.isdir(parent_path):
112
os.makedirs(parent_path)
113
head_bzrdir = BzrDir.create(head_loc, format=format)
115
head_branch = head_bzrdir.open_branch()
116
except NotBranchError:
117
head_branch = head_bzrdir.create_branch()
118
if ("%s^{}" % name) in refs:
119
revid = mapping.revision_id_foreign_to_bzr(refs["%s^{}" % name])
121
revid = mapping.revision_id_foreign_to_bzr(ref)
122
head_branch.generate_revision_history(revid)