remote-bzr: add support for shared repo
This way all the remotes share the same data, so adding multiple remotes, or renaming them doesn't create extra overhead. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
Apr 30, 2013 at 20:10 UTC
c95c35f4b8908fcda713c09eba4e55aac2c39be6
1 file changed
+15
-7
contrib/remote-helpers/git-remote-bzr
+15
-7
@@ -752,7 +752,20 @@ def get_repo(url, alias):
752
origin = bzrlib.bzrdir.BzrDir.open(url)
753
is_local = isinstance(origin.transport, bzrlib.transport.local.LocalTransport)
754
755
- clone_path = os.path.join(dirname, 'clone')
755
+ shared_path = os.path.join(gitdir, 'bzr')
756
+ try:
757
+ shared_dir = bzrlib.bzrdir.BzrDir.open(shared_path)
758
+ except bzrlib.errors.NotBranchError:
759
+ shared_dir = bzrlib.bzrdir.BzrDir.create(shared_path)
760
+ try:
761
+ shared_repo = shared_dir.open_repository()
762
+ except bzrlib.errors.NoRepositoryPresent:
763
+ shared_repo = shared_dir.create_repository(shared=True)
764
+
765
+ if not is_local:
766
+ clone_path = os.path.join(dirname, 'clone')
767
+ if not os.path.exists(clone_path):
768
+ os.mkdir(clone_path)
769
770
try:
771
repo = origin.open_repository()
@@ -763,8 +776,6 @@ def get_repo(url, alias):
776
branch = origin.open_branch()
777
778
if not is_local:
766
- if not os.path.exists(clone_path):
767
- os.mkdir(clone_path)
779
peers[name] = branch
780
branches[name] = get_remote_branch(origin, branch, name)
781
else:
@@ -774,9 +785,6 @@ def get_repo(url, alias):
785
else:
786
# repository
787
777
- if not is_local and not os.path.exists(clone_path):
778
- clonedir = bzrlib.bzrdir.BzrDir.create(clone_path)
779
-
788
for branch in repo.find_branches():
789
790
name = repo.user_transport.relpath(branch.base)
@@ -800,7 +808,7 @@ def fix_path(alias, orig_url):
808
subprocess.call(cmd)
809
810
def main(args):
803
- global marks, prefix, dirname
811
+ global marks, prefix, gitdir, dirname
812
global tags, filenodes
813
global blob_marks
814
global parsed_refs