Rev 6483: (jelmer) Make "bzr branches" support our shared-repo style of "sibling in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Tue Mar 6 18:11:06 UTC 2012


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6483 [merge]
revision-id: pqm at pqm.ubuntu.com-20120306181105-7kx1cqp074erle3b
parent: pqm at pqm.ubuntu.com-20120306174302-b6y3hyh1yfnutk9o
parent: jelmer at samba.org-20120306173244-ghpd1vudohp6gujr
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2012-03-06 18:11:05 +0000
message:
  (jelmer) Make "bzr branches" support our shared-repo style of "sibling
   branches" too. (Jelmer Vernooij)
modified:
  bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
  bzrlib/tests/blackbox/test_branches.py test_branches.py-20110815154803-0t6tna5x9ud2osj3-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py	2012-03-06 17:43:02 +0000
+++ b/bzrlib/builtins.py	2012-03-06 18:11:05 +0000
@@ -86,27 +86,27 @@
 def _get_branch_location(control_dir, possible_transports=None):
     """Return location of branch for this control dir."""
     try:
-        this_branch = control_dir.open_branch(
-            possible_transports=possible_transports)
-        # This may be a heavy checkout, where we want the master branch
-        master_location = this_branch.get_bound_location()
-        if master_location is not None:
-            return master_location
-        # If not, use a local sibling
-        return this_branch.base
+        target = control_dir.get_branch_reference()
     except errors.NotBranchError:
-        format = control_dir.find_branch_format()
-        if getattr(format, 'get_reference', None) is not None:
-            return format.get_reference(control_dir)
-        else:
-            return control_dir.root_transport.base
+        return control_dir.root_transport.base
+    if target is not None:
+        return target
+    this_branch = control_dir.open_branch(
+        possible_transports=possible_transports)
+    # This may be a heavy checkout, where we want the master branch
+    master_location = this_branch.get_bound_location()
+    if master_location is not None:
+        return master_location
+    # If not, use a local sibling
+    return this_branch.base
 
 
 def _is_colocated(control_dir, possible_transports=None):
     """Check if the branch in control_dir is colocated.
 
     :param control_dir: Control directory
-    :return: Boolean indicating whether 
+    :return: Tuple with boolean indicating whether the branch is colocated
+        and the full URL to the actual branch
     """
     # This path is meant to be relative to the existing branch
     this_url = _get_branch_location(control_dir,
@@ -132,8 +132,7 @@
 def lookup_new_sibling_branch(control_dir, location, possible_transports=None):
     """Lookup the location for a new sibling branch.
 
-    :param control_dir: Control directory relative to which to look up
-        the name.
+    :param control_dir: Control directory to find sibling branches from
     :param location: Name of the new branch
     :return: Full location to the new branch
     """
@@ -150,7 +149,7 @@
 
 
 def open_sibling_branch(control_dir, location, possible_transports=None):
-    """Open a branch, possibly a sibling.
+    """Open a branch, possibly a sibling of another.
 
     :param control_dir: Control directory relative to which to lookup the
         location.
@@ -189,11 +188,36 @@
         possible_transports=possible_transports)
 
 
- at symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
-def tree_files(file_list, default_branch=u'.', canonicalize=True,
-    apply_view=True):
-    return internal_tree_files(file_list, default_branch, canonicalize,
-        apply_view)
+def iter_sibling_branches(control_dir, possible_transports=None):
+    """Iterate over the siblings of a branch.
+
+    :param control_dir: Control directory for which to look up the siblings
+    :return: Iterator over tuples with branch name and branch object
+    """
+    seen_urls = set()
+    try:
+        reference = control_dir.get_branch_reference()
+    except errors.NotBranchError:
+        # There is no active branch, just return the colocated branches.
+        for name, branch in control_dir.get_branches().iteritems():
+            yield name, branch
+        return
+    if reference is not None:
+        ref_branch = Branch.open(reference,
+            possible_transports=possible_transports)
+    else:
+        ref_branch = None
+    if ref_branch is None or ref_branch.name:
+        if ref_branch is not None:
+            control_dir = ref_branch.bzrdir
+        for name, branch in control_dir.get_branches().iteritems():
+            yield name, branch
+    else:
+        repo = ref_branch.bzrdir.find_repository()
+        for branch in repo.find_branches(using=True):
+            name = urlutils.relative_url(repo.user_url,
+                branch.user_url).rstrip("/")
+            yield name, branch
 
 
 def tree_files_for_add(file_list):
@@ -261,36 +285,6 @@
     return rev_tree
 
 
-# XXX: Bad function name; should possibly also be a class method of
-# WorkingTree rather than a function.
- at symbol_versioning.deprecated_function(symbol_versioning.deprecated_in((2, 3, 0)))
-def internal_tree_files(file_list, default_branch=u'.', canonicalize=True,
-    apply_view=True):
-    """Convert command-line paths to a WorkingTree and relative paths.
-
-    Deprecated: use WorkingTree.open_containing_paths instead.
-
-    This is typically used for command-line processors that take one or
-    more filenames, and infer the workingtree that contains them.
-
-    The filenames given are not required to exist.
-
-    :param file_list: Filenames to convert.
-
-    :param default_branch: Fallback tree path to use if file_list is empty or
-        None.
-
-    :param apply_view: if True and a view is set, apply it or check that
-        specified files are within it
-
-    :return: workingtree, [relative_paths]
-    """
-    return WorkingTree.open_containing_paths(
-        file_list, default_directory='.',
-        canonicalize=True,
-        apply_view=True)
-
-
 def _get_view_info_for_change_reporter(tree):
     """Get the view information from a tree for change reporting."""
     view_info = None
@@ -1559,9 +1553,8 @@
                 active_branch = dir.open_branch(name="")
             except errors.NotBranchError:
                 active_branch = None
-            branches = dir.get_branches()
             names = {}
-            for name, branch in branches.iteritems():
+            for name, branch in iter_sibling_branches(dir):
                 if name == "":
                     continue
                 active = (active_branch is not None and

=== modified file 'bzrlib/tests/blackbox/test_branches.py'
--- a/bzrlib/tests/blackbox/test_branches.py	2012-01-18 17:47:06 +0000
+++ b/bzrlib/tests/blackbox/test_branches.py	2012-02-13 17:34:46 +0000
@@ -17,6 +17,7 @@
 
 """Black-box tests for bzr branches."""
 
+from bzrlib.bzrdir import BzrDir
 from bzrlib.tests import TestCaseWithTransport
 
 
@@ -76,3 +77,17 @@
         out, err = self.run_bzr('branches a')
         self.assertEquals(out, "  another\n"
                                "* colocated\n")
+
+    def test_shared_repos(self):
+        self.make_repository('a', shared=True)
+        BzrDir.create_branch_convenience('a/branch1')
+        b = BzrDir.create_branch_convenience('a/branch2')
+        b.create_checkout(lightweight=True, to_location='b')
+        out, err = self.run_bzr('branches b')
+        self.assertEquals(out, "  branch1\n"
+                               "* branch2\n")
+
+    def test_standalone_branch(self):
+        self.make_branch('a')
+        out, err = self.run_bzr('branches a')
+        self.assertEquals(out, "* (default)\n")

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2012-02-28 10:06:39 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2012-03-06 18:11:05 +0000
@@ -26,6 +26,10 @@
 .. Improvements to existing commands, especially improved performance 
    or memory usage, or better results.
 
+* ``bzr branches`` will now also list sibling branches when
+  the current location is a lightweight checkout of a branch in
+  a shared repository. (Jelmer Vernooij)
+
 Bug Fixes
 *********
 




More information about the bazaar-commits mailing list