git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 19/20] remote-bzr: access branches only when needed

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Apr 26, 2013, 01:08 UTC
Message-ID
<1366938488-25425-20-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1366938488-25425-1-git-send-email-felipe.contreras@gmail.com>

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>
---
 contrib/remote-helpers/git-remote-bzr | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 7517645..3c59a18 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -300,7 +300,7 @@ def export_branch(repo, name):
     ref = '%s/heads/%s' % (prefix, name)
     tip = marks.get_tip(name)
 
-    branch = branches[name]
+    branch = bzrlib.branch.Branch.open(branches[name])
     repo = branch.repository
 
     branch.lock_read()
@@ -605,7 +605,7 @@ def parse_commit(parser):
 
     if ref.startswith('refs/heads/'):
         name = ref[len('refs/heads/'):]
-        branch = branches[name]
+        branch = bzrlib.branch.Branch.open(branches[name])
     else:
         die('unknown ref')
 
@@ -706,7 +706,7 @@ def do_export(parser):
 
     for ref, revid in parsed_refs.iteritems():
         name = ref[len('refs/heads/'):]
-        branch = branches[name]
+        branch = bzrlib.branch.Branch.open(branches[name])
         branch.generate_revision_history(revid, marks.get_tip(name))
 
         if name in peers:
@@ -756,7 +756,7 @@ def do_list(parser):
             master_branch = name
         print "? refs/heads/%s" % name
 
-    branch = branches[master_branch]
+    branch = bzrlib.branch.Branch.open(branches[master_branch])
     branch.lock_read()
     for tag, revid in branch.tags.get_tag_dict().items():
         try:
@@ -845,13 +845,15 @@ def get_repo(url, alias):
         # branch
 
         name = 'master'
-        branch = origin.open_branch()
+        remote_branch = origin.open_branch()
 
         if not is_local:
-            peers[name] = branch.base
-            branches[name] = get_remote_branch(origin, branch, name)
+            peers[name] = remote_branch.base
+            branch = get_remote_branch(origin, remote_branch, name)
         else:
-            branches[name] = branch
+            branch = remote_branch
+
+        branches[name] = branch.base
 
         return branch.repository
     else:
@@ -861,13 +863,15 @@ def get_repo(url, alias):
         # stupid python
         wanted = [e for e in wanted if e]
 
-        for name, branch in find_branches(repo, wanted):
+        for name, remote_branch in find_branches(repo, wanted):
 
             if not is_local:
-                peers[name] = branch.base
-                branches[name] = get_remote_branch(origin, branch, name)
+                peers[name] = remote_branch.base
+                branch = get_remote_branch(origin, remote_branch, name)
             else:
-                branches[name] = branch
+                branch = remote_branch
+
+            branches[name] = branch.base
 
         return repo
 
-- 
1.8.2.1.884.g3532a8d
Previous: Felipe ContrerasNext: Felipe Contreras
Message 25 of 29 in “remote-bzr: massive changes”
  1. 00/20 remote-bzr: massive changesFelipe Contreras, Apr 26, 2013
  2. 01/20 remote-bzr: cleanup CustomTreeFelipe Contreras, Apr 26, 2013
  3. 02/20 remote-bzr: delay blob fetching until the very endFelipe Contreras, Apr 26, 2013
  4. 03/20 remote-bzr: fix order of locking in CustomTreeFelipe Contreras, Apr 26, 2013
  5. 04/20 remote-bzr: always try to update the worktreeFelipe Contreras, Apr 26, 2013
  6. 05/20 remote-bzr: add support to push mergesFelipe Contreras, Apr 26, 2013
  7. 06/20 remote-bzr: fixes for branch divergeFelipe Contreras, Apr 26, 2013
  8. 07/20 remote-bzr: fix partially pushed mergeFelipe Contreras, Apr 26, 2013
  9. 08/20 remote-bzr: use branch variable when appropriateFelipe Contreras, Apr 26, 2013
  10. 09/20 remote-bzr: add support for bzr reposFelipe Contreras, Apr 26, 2013
  11. 10/20 remote-bzr: fix branch namesFelipe Contreras, Apr 26, 2013
  12. 11/20 remote-bzr: add support for shared repoFelipe Contreras, Apr 26, 2013
  13. 12/20 remote-bzr: split marks fileFelipe Contreras, Apr 26, 2013
  14. Felipe ContrerasApr 26, 2013
  15. Junio C HamanoApr 27, 2013
  16. Felipe ContrerasApr 27, 2013
  17. Junio C HamanoApr 28, 2013
  18. Felipe ContrerasApr 29, 2013
  19. 13/20 remote-bzr: improve author sanitazionFelipe Contreras, Apr 26, 2013
  20. 14/20 remote-bzr: add custom method to find branchesFelipe Contreras, Apr 26, 2013
  21. 15/20 remote-bzr: add option to specify branchesFelipe Contreras, Apr 26, 2013
  22. 16/20 remote-bzr: improve progress reportingFelipe Contreras, Apr 26, 2013
  23. 17/20 remote-bzr: iterate revisions properlyFelipe Contreras, Apr 26, 2013
  24. 18/20 remote-bzr: delay peer branch usageFelipe Contreras, Apr 26, 2013
  25. 19/20 remote-bzr: access branches only when neededFelipe Contreras, Apr 26, 2013
  26. 20/20 remote-bzr: export HEADFelipe Contreras, Apr 26, 2013
  27. Felipe ContrerasApr 26, 2013
  28. Junio C HamanoApr 26, 2013
  29. Felipe ContrerasApr 26, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.