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

[PATCH v2 7/8] remote-bzr: reorganize the way 'wanted' works

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
May 25, 2013, 02:24 UTC
Message-ID
<1369448666-17515-8-git-send-email-felipe.contreras@gmail.com>
In-Reply-To
<1369448666-17515-1-git-send-email-felipe.contreras@gmail.com>

If the user specified a list of branches, we ignore what the remote repository lists, and simply use the branches directly. Since some remotes don't report the branches correctly, this is useful.

Otherwise either fetch the repo, or the branch.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 contrib/remote-helpers/git-remote-bzr | 58 ++++++++++++++++-------------------
 1 file changed, 26 insertions(+), 32 deletions(-)
diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr
index 34025c3..3248586 100755
--- a/contrib/remote-helpers/git-remote-bzr
+++ b/contrib/remote-helpers/git-remote-bzr
@@ -795,7 +795,7 @@ def get_remote_branch(name):
 
     return branch
 
-def find_branches(repo, wanted):
+def find_branches(repo):
     transport = repo.bzrdir.root_transport
 
     for fn in transport.iter_files_recursive():
@@ -806,9 +806,6 @@ def find_branches(repo, wanted):
         name = name if name != '' else 'master'
         name = name.replace('/', '+')
 
-        if wanted and not name in wanted:
-            continue
-
         try:
             cur = transport.clone(subdir)
             branch = bzrlib.branch.Branch.open_from_transport(cur)
@@ -848,38 +845,35 @@ def get_repo(url, alias):
             except bzrlib.errors.NoRepositoryPresent:
                 pass
 
-    try:
-        repo = origin.open_repository()
-        if not repo.user_transport.listable():
-            # this repository is not usable for us
-            raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
-    except bzrlib.errors.NoRepositoryPresent:
-        # branch
-
-        name = 'master'
-        branch = origin.open_branch().base
-
-        if not is_local:
-            peers[name] = branch
+    wanted = get_config('remote-bzr.branches').rstrip().split(', ')
+    # stupid python
+    wanted = [e for e in wanted if e]
 
-        branches[name] = branch
-
-        return origin
+    if not wanted:
+        try:
+            repo = origin.open_repository()
+            if not repo.user_transport.listable():
+                # this repository is not usable for us
+                raise bzrlib.errors.NoRepositoryPresent(repo.bzrdir)
+        except bzrlib.errors.NoRepositoryPresent:
+            wanted = ['master']
+
+    if wanted:
+        def list_wanted(url, wanted):
+            for name in wanted:
+                subdir = name if name != 'master' else ''
+                yield name, bzrlib.urlutils.join(url, subdir)
+
+        branch_list = list_wanted(url, wanted)
     else:
-        # repository
-
-        wanted = get_config('remote-bzr.branches').rstrip().split(', ')
-        # stupid python
-        wanted = [e for e in wanted if e]
+        branch_list = find_branches(repo)
 
-        for name, branch in find_branches(repo, wanted):
-
-            if not is_local:
-                peers[name] = branch
-
-            branches[name] = branch
+    for name, url in branch_list:
+        if not is_local:
+            peers[name] = url
+        branches[name] = url
 
-        return origin
+    return origin
 
 def fix_path(alias, orig_url):
     url = urlparse.urlparse(orig_url, 'file')
-- 
1.8.3.rc3.312.g47657de
Previous: Felipe ContrerasNext: Junio C Hamano
Message 8 of 13 in “remote-bzr: patches for next”
  1. 0/8 remote-bzr: patches for nextFelipe Contreras, May 25, 2013
  2. 1/8 remote-bzr: recover from failed clonesFelipe Contreras, May 25, 2013
  3. 2/8 remote-bzr: fix for files with spacesFelipe Contreras, May 25, 2013
  4. 3/8 remote-bzr: simplify get_remote_branch()Felipe Contreras, May 25, 2013
  5. 4/8 remote-bzr: delay cloning/pullingFelipe Contreras, May 25, 2013
  6. 5/8 remote-bzr: change global repoFelipe Contreras, May 25, 2013
  7. 6/8 remote-bzr: trivial cleanupsFelipe Contreras, May 25, 2013
  8. 7/8 remote-bzr: reorganize the way 'wanted' worksFelipe Contreras, May 25, 2013
  9. Junio C HamanoMay 28, 2013
  10. Felipe ContrerasMay 29, 2013
  11. Junio C HamanoMay 29, 2013
  12. Felipe ContrerasMay 29, 2013
  13. 8/8 remote-bzr: add fallback check for a partial cloneFelipe Contreras, May 25, 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.