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>
maint
Felipe Contreras 2013-05-24 21:24:25 -05:00 committed by Junio C Hamano
parent a8ffc3ade2
commit e56660a73f
1 changed files with 24 additions and 30 deletions

View File

@ -795,7 +795,7 @@ def get_remote_branch(name):


return branch return branch


def find_branches(repo, wanted): def find_branches(repo):
transport = repo.bzrdir.root_transport transport = repo.bzrdir.root_transport


for fn in transport.iter_files_recursive(): for fn in transport.iter_files_recursive():
@ -806,9 +806,6 @@ def find_branches(repo, wanted):
name = name if name != '' else 'master' name = name if name != '' else 'master'
name = name.replace('/', '+') name = name.replace('/', '+')


if wanted and not name in wanted:
continue

try: try:
cur = transport.clone(subdir) cur = transport.clone(subdir)
branch = bzrlib.branch.Branch.open_from_transport(cur) branch = bzrlib.branch.Branch.open_from_transport(cur)
@ -848,36 +845,33 @@ def get_repo(url, alias):
except bzrlib.errors.NoRepositoryPresent: except bzrlib.errors.NoRepositoryPresent:
pass pass


wanted = get_config('remote-bzr.branches').rstrip().split(', ')
# stupid python
wanted = [e for e in wanted if e]

if not wanted:
try: try:
repo = origin.open_repository() repo = origin.open_repository()
if not repo.user_transport.listable(): if not repo.user_transport.listable():
# this repository is not usable for us # this repository is not usable for us
raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir) raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
except bzrlib.errors.NoRepositoryPresent: except bzrlib.errors.NoRepositoryPresent:
# branch wanted = ['master']


name = 'master' if wanted:
branch = origin.open_branch().base def list_wanted(url, wanted):
for name in wanted:
subdir = name if name != 'master' else ''
yield name, bzrlib.urlutils.join(url, subdir)


if not is_local: branch_list = list_wanted(url, wanted)
peers[name] = branch

branches[name] = branch

return origin
else: else:
# repository branch_list = find_branches(repo)

wanted = get_config('remote-bzr.branches').rstrip().split(', ')
# stupid python
wanted = [e for e in wanted if e]

for name, branch in find_branches(repo, wanted):


for name, url in branch_list:
if not is_local: if not is_local:
peers[name] = branch peers[name] = url

branches[name] = url
branches[name] = branch


return origin return origin