Skip to content

Commit d421c02

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 747c9a3 commit d421c02

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

contrib/remote-helpers/git-remote-bzr

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def export_branch(repo, name):
277277
ref = '%s/heads/%s' % (prefix, name)
278278
tip = marks.get_tip(name)
279279

280-
branch = branches[name]
280+
branch = bzrlib.branch.Branch.open(branches[name])
281281
repo = branch.repository
282282

283283
branch.lock_read()
@@ -582,7 +582,7 @@ def parse_commit(parser):
582582

583583
if ref.startswith('refs/heads/'):
584584
name = ref[len('refs/heads/'):]
585-
branch = branches[name]
585+
branch = bzrlib.branch.Branch.open(branches[name])
586586
else:
587587
die('unknown ref')
588588

@@ -683,7 +683,7 @@ def do_export(parser):
683683

684684
for ref, revid in parsed_refs.iteritems():
685685
name = ref[len('refs/heads/'):]
686-
branch = branches[name]
686+
branch = bzrlib.branch.Branch.open(branches[name])
687687
branch.generate_revision_history(revid, marks.get_tip(name))
688688

689689
if name in peers:
@@ -733,7 +733,7 @@ def do_list(parser):
733733
master_branch = name
734734
print "? refs/heads/%s" % name
735735

736-
branch = branches[master_branch]
736+
branch = bzrlib.branch.Branch.open(branches[master_branch])
737737
branch.lock_read()
738738
for tag, revid in branch.tags.get_tag_dict().items():
739739
try:
@@ -822,13 +822,15 @@ def get_repo(url, alias):
822822
# branch
823823

824824
name = 'master'
825-
branch = origin.open_branch()
825+
remote_branch = origin.open_branch()
826826

827827
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)
830830
else:
831-
branches[name] = branch
831+
branch = remote_branch
832+
833+
branches[name] = branch.base
832834

833835
return branch.repository
834836
else:
@@ -838,13 +840,15 @@ def get_repo(url, alias):
838840
# stupid python
839841
wanted = [e for e in wanted if e]
840842

841-
for name, branch in find_branches(repo, wanted):
843+
for name, remote_branch in find_branches(repo, wanted):
842844

843845
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)
846848
else:
847-
branches[name] = branch
849+
branch = remote_branch
850+
851+
branches[name] = branch.base
848852

849853
return repo
850854

0 commit comments

Comments
 (0)