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

[PATCH 3/8] remote-bzr: simplify get_remote_branch()

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 16, 2013, 08:36 UTC
Message-ID
<1368693407-21267-4-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1368693407-21267-1-git-send-email-felipe.contreras@gmail.com>

No need for 'origin', it's only needed for the bzrdir 'sprout' method, which can be greatly simplified.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index b849336..b7656df 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -764,25 +764,26 @@ def do_list(parser):
     print "@refs/heads/%s HEAD" % master_branch
     print
 
-def get_remote_branch(origin, remote_branch, name):
+def clone(path, remote_branch):
+    bdir = bzrlib.bzrdir.BzrDir.create(path)
+    repo = bdir.find_repository()
+    repo.fetch(remote_branch.repository)
+    return remote_branch.sprout(bdir, repository=repo)
+
+def get_remote_branch(remote_branch, name):
     global dirname, peers
 
     branch_path = os.path.join(dirname, 'clone', name)
 
     try:
-        d = bzrlib.bzrdir.BzrDir.open(branch_path)
-        branch = d.open_branch()
+        branch = bzrlib.branch.Branch.open(branch_path)
     except bzrlib.errors.NotBranchError:
         # clone
-        d = origin.sprout(branch_path, None,
-                hardlink=True, create_tree_if_local=False,
-                force_new_repo=False,
-                source_branch=remote_branch)
-        branch = d.open_branch()
+        branch = clone(branch_path, remote_branch)
     else:
         # pull
         try:
-            branch.pull(remote_branch, [], None, False)
+            branch.pull(remote_branch, overwrite=True)
         except bzrlib.errors.DivergedBranches:
             # use remote branch for now
             return remote_branch
@@ -850,7 +851,7 @@ def get_repo(url, alias):
 
         if not is_local:
             peers[name] = remote_branch.base
-            branch = get_remote_branch(origin, remote_branch, name)
+            branch = get_remote_branch(remote_branch, name)
         else:
             branch = remote_branch
 
@@ -868,7 +869,7 @@ def get_repo(url, alias):
 
             if not is_local:
                 peers[name] = remote_branch.base
-                branch = get_remote_branch(origin, remote_branch, name)
+                branch = get_remote_branch(remote_branch, name)
             else:
                 branch = remote_branch
 
-- 
1.8.3.rc2.542.g24820ba
Previous: Felipe ContrerasNext: Felipe Contreras
Message 4 of 12 in “remote-bzr: patches for next”
  1. 0/8 remote-bzr: patches for nextFelipe Contreras, May 16, 2013
  2. 1/8 remote-bzr: recover from failed clonesFelipe Contreras, May 16, 2013
  3. 2/8 remote-bzr: fix for files with spacesFelipe Contreras, May 16, 2013
  4. 3/8 remote-bzr: simplify get_remote_branch()Felipe Contreras, May 16, 2013
  5. 4/8 remote-bzr: delay cloning/pullingFelipe Contreras, May 16, 2013
  6. 5/8 remote-bzr: change global repoFelipe Contreras, May 16, 2013
  7. 6/8 remote-bzr: trivial cleanupsFelipe Contreras, May 16, 2013
  8. 7/8 remote-bzr: reorganize the way 'wanted' worksFelipe Contreras, May 16, 2013
  9. Junio C HamanoMay 16, 2013
  10. Felipe ContrerasMay 16, 2013
  11. Junio C HamanoMay 16, 2013
  12. 8/8 remote-bzr: add fallback check for a partial cloneFelipe Contreras, May 16, 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.