remote-bzr: add option to specify branches
We might not want all the branches. And branch handling in bazaar is rather tricky, so it's safer to simply specify them. 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
248663c4ff931f1f42fb7f8233d0ae23f80c7835
1 file changed
+18
-2
contrib/remote-helpers/git-remote-bzr
+18
-2
@@ -13,6 +13,9 @@
13
# or
14
# % git clone bzr::lp:myrepo
15
#
16
+# If you want to specify which branches you want track (per repo):
17
+# git config remote-bzr.branches 'trunk, devel, test'
18
+#
19
20
import sys
21
@@ -51,6 +54,12 @@ def warn(msg, *args):
54
def gittz(tz):
55
return '%+03d%02d' % (tz / 3600, tz % 3600 / 60)
56
57
+def get_config(config):
58
+ cmd = ['git', 'config', '--get', config]
59
+ process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
60
+ output, _ = process.communicate()
61
+ return output
62
+
63
class Marks:
64
65
def __init__(self, path):
@@ -756,7 +765,7 @@ def get_remote_branch(origin, remote_branch, name):
765
766
return branch
767
759
-def find_branches(repo):
768
+def find_branches(repo, wanted):
769
transport = repo.user_transport
770
771
for fn in transport.iter_files_recursive():
@@ -767,6 +776,9 @@ def find_branches(repo):
776
name = name if name != '' else 'master'
777
name = name.replace('/', '+')
778
779
+ if wanted and not name in wanted:
780
+ continue
781
+
782
try:
783
cur = transport.clone(subdir)
784
branch = bzrlib.branch.Branch.open_from_transport(cur)
@@ -815,7 +827,11 @@ def get_repo(url, alias):
827
else:
828
# repository
829
818
- for name, branch in find_branches(repo):
830
+ wanted = get_config('remote-bzr.branches').rstrip().split(', ')
831
+ # stupid python
832
+ wanted = [e for e in wanted if e]
833
+
834
+ for name, branch in find_branches(repo, wanted):
835
836
if not is_local:
837
peers[name] = branch