remote-bzr: access branches only when needed
Bazaar doesn't seem to be tested for multiple usage of branches, so resources seem to be leaked all over. Let's try to minimize this by accessing the Branch objects only when needed. 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
d421c02b4144df9b0448e321930ee6a604cdd3fc
1 file changed
+16
-12
contrib/remote-helpers/git-remote-bzr
+16
-12
@@ -277,7 +277,7 @@ def export_branch(repo, name):
277
ref = '%s/heads/%s' % (prefix, name)
278
tip = marks.get_tip(name)
279
280
- branch = branches[name]
280
+ branch = bzrlib.branch.Branch.open(branches[name])
281
repo = branch.repository
282
283
branch.lock_read()
@@ -582,7 +582,7 @@ def parse_commit(parser):
582
583
if ref.startswith('refs/heads/'):
584
name = ref[len('refs/heads/'):]
585
- branch = branches[name]
585
+ branch = bzrlib.branch.Branch.open(branches[name])
586
else:
587
die('unknown ref')
588
@@ -683,7 +683,7 @@ def do_export(parser):
683
684
for ref, revid in parsed_refs.iteritems():
685
name = ref[len('refs/heads/'):]
686
- branch = branches[name]
686
+ branch = bzrlib.branch.Branch.open(branches[name])
687
branch.generate_revision_history(revid, marks.get_tip(name))
688
689
if name in peers:
@@ -733,7 +733,7 @@ def do_list(parser):
733
master_branch = name
734
print "? refs/heads/%s" % name
735
736
- branch = branches[master_branch]
736
+ branch = bzrlib.branch.Branch.open(branches[master_branch])
737
branch.lock_read()
738
for tag, revid in branch.tags.get_tag_dict().items():
739
try:
@@ -822,13 +822,15 @@ def get_repo(url, alias):
822
# branch
823
824
name = 'master'
825
- branch = origin.open_branch()
825
+ remote_branch = origin.open_branch()
826
827
if not is_local:
828
- peers[name] = branch.base
829
- branches[name] = get_remote_branch(origin, branch, name)
828
+ peers[name] = remote_branch.base
829
+ branch = get_remote_branch(origin, remote_branch, name)
830
else:
831
- branches[name] = branch
831
+ branch = remote_branch
832
+
833
+ branches[name] = branch.base
834
835
return branch.repository
836
else:
@@ -838,13 +840,15 @@ def get_repo(url, alias):
840
# stupid python
841
wanted = [e for e in wanted if e]
842
841
- for name, branch in find_branches(repo, wanted):
843
+ for name, remote_branch in find_branches(repo, wanted):
844
845
if not is_local:
844
- peers[name] = branch.base
845
- branches[name] = get_remote_branch(origin, branch, name)
846
+ peers[name] = remote_branch.base
847
+ branch = get_remote_branch(origin, remote_branch, name)
848
else:
847
- branches[name] = branch
849
+ branch = remote_branch
850
+
851
+ branches[name] = branch.base
852
853
return repo
854