remote-bzr: reorganize the way 'wanted' works

If the user specified a list of branches, we ignore what the remote repository lists, and simply use the branches directly. Since some remotes don't report the branches correctly, this is useful. Otherwise either fetch the repo, or the branch. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Felipe Contreras committed May 24, 2013 at 21:24 UTC e56660a73f778546f7c40989d982ac2f21462975
1 file changed +26 -32
contrib/remote-helpers/git-remote-bzr
+26 -32
@@ -795,7 +795,7 @@ def get_remote_branch(name):
795
796 return branch
797
798 -def find_branches(repo, wanted):
798 +def find_branches(repo):
799 transport = repo.bzrdir.root_transport
800
801 for fn in transport.iter_files_recursive():
@@ -806,9 +806,6 @@ def find_branches(repo, wanted):
806 name = name if name != '' else 'master'
807 name = name.replace('/', '+')
808
809 - if wanted and not name in wanted:
810 - continue
811 -
809 try:
810 cur = transport.clone(subdir)
811 branch = bzrlib.branch.Branch.open_from_transport(cur)
@@ -848,38 +845,35 @@ def get_repo(url, alias):
845 except bzrlib.errors.NoRepositoryPresent:
846 pass
847
851 - try:
852 - repo = origin.open_repository()
853 - if not repo.user_transport.listable():
854 - # this repository is not usable for us
855 - raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
856 - except bzrlib.errors.NoRepositoryPresent:
857 - # branch
858 -
859 - name = 'master'
860 - branch = origin.open_branch().base
861 -
862 - if not is_local:
863 - peers[name] = branch
848 + wanted = get_config('remote-bzr.branches').rstrip().split(', ')
849 + # stupid python
850 + wanted = [e for e in wanted if e]
851
865 - branches[name] = branch
866 -
867 - return origin
852 + if not wanted:
853 + try:
854 + repo = origin.open_repository()
855 + if not repo.user_transport.listable():
856 + # this repository is not usable for us
857 + raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
858 + except bzrlib.errors.NoRepositoryPresent:
859 + wanted = ['master']
860 +
861 + if wanted:
862 + def list_wanted(url, wanted):
863 + for name in wanted:
864 + subdir = name if name != 'master' else ''
865 + yield name, bzrlib.urlutils.join(url, subdir)
866 +
867 + branch_list = list_wanted(url, wanted)
868 else:
869 - # repository
870 -
871 - wanted = get_config('remote-bzr.branches').rstrip().split(', ')
872 - # stupid python
873 - wanted = [e for e in wanted if e]
869 + branch_list = find_branches(repo)
870
875 - for name, branch in find_branches(repo, wanted):
876 -
877 - if not is_local:
878 - peers[name] = branch
879 -
880 - branches[name] = branch
871 + for name, url in branch_list:
872 + if not is_local:
873 + peers[name] = url
874 + branches[name] = url
875
882 - return origin
876 + return origin
877
878 def fix_path(alias, orig_url):
879 url = urlparse.urlparse(orig_url, 'file')