remote-bzr: add custom method to find branches

The official method is incredibly inefficient and slow. 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 850dd25c9a245da0e6b23c36cf9f45d6ee08b237
1 file changed +20 -5
contrib/remote-helpers/git-remote-bzr
+20 -5
@@ -756,6 +756,25 @@ def get_remote_branch(origin, remote_branch, name):
756
757 return branch
758
759 +def find_branches(repo):
760 + transport = repo.user_transport
761 +
762 + for fn in transport.iter_files_recursive():
763 + if not fn.endswith('.bzr/branch-format'):
764 + continue
765 +
766 + name = subdir = fn[:-len('/.bzr/branch-format')]
767 + name = name if name != '' else 'master'
768 + name = name.replace('/', '+')
769 +
770 + try:
771 + cur = transport.clone(subdir)
772 + branch = bzrlib.branch.Branch.open_from_transport(cur)
773 + except bzrlib.errors.NotBranchError:
774 + continue
775 + else:
776 + yield name, branch
777 +
778 def get_repo(url, alias):
779 global dirname, peer, branches
780
@@ -796,11 +815,7 @@ def get_repo(url, alias):
815 else:
816 # repository
817
799 - for branch in repo.find_branches():
800 -
801 - name = repo.user_transport.relpath(branch.base)
802 - name = name if name != '' else 'master'
803 - name = name.replace('/', '+')
818 + for name, branch in find_branches(repo):
819
820 if not is_local:
821 peers[name] = branch