Rev 6263: (jelmer) Support 'bzr info' on empty control directories and control in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Wed Nov 16 02:04:26 UTC 2011


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

------------------------------------------------------------
revno: 6263 [merge]
revision-id: pqm at pqm.ubuntu.com-20111116020425-w0dcxrz8os7akswd
parent: pqm at pqm.ubuntu.com-20111115180837-v38l0bf3uh02pe7p
parent: jelmer at samba.org-20111116005510-xocbirme8qozbodl
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2011-11-16 02:04:25 +0000
message:
  (jelmer) Support 'bzr info' on empty control directories and control
   directories with dangling branch references. (Jelmer Vernooij)
modified:
  bzrlib/info.py                 info.py-20050323235939-6bbfe7d9700b0b9b
  bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
  bzrlib/tests/blackbox/test_shared_repository.py test_shared_repository.py-20060317053531-ed30c0d79325e483
  bzrlib/tests/test_info.py      test_info.py-20070320150933-m0xxm1g7xi9v6noe-1
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py	2011-11-08 18:18:25 +0000
+++ b/bzrlib/info.py	2011-11-15 17:27:46 +0000
@@ -77,9 +77,9 @@
         return ["  %*s: %s\n" % (max_len, l, u) for l, u in self.locs ]
 
 
-def gather_location_info(repository, branch=None, working=None):
+def gather_location_info(repository=None, branch=None, working=None,
+        control=None):
     locs = {}
-    repository_path = repository.user_url
     if branch is not None:
         branch_path = branch.user_url
         master_path = branch.get_bound_location()
@@ -88,6 +88,11 @@
     else:
         branch_path = None
         master_path = None
+        try:
+            if control is not None and control.get_branch_reference():
+                locs['checkout of branch'] = control.get_branch_reference()
+        except NotBranchError:
+            pass
     if working:
         working_path = working.user_url
         if working_path != branch_path:
@@ -106,22 +111,29 @@
             locs['branch root'] = branch_path
     else:
         working_path = None
-        if repository.is_shared():
+        if repository is not None and repository.is_shared():
             # lightweight checkout of branch in shared repository
             if branch_path is not None:
                 locs['repository branch'] = branch_path
         elif branch_path is not None:
             # standalone
             locs['branch root'] = branch_path
+        elif repository is not None:
+            locs['repository'] = repository.user_url
+        elif control is not None:
+            locs['control directory'] = control.user_url
         else:
-            locs['repository'] = repository_path
+            # Really, at least a control directory should be
+            # passed in for this method to be useful.
+            pass
         if master_path != branch_path:
             locs['bound to branch'] = master_path
-    if repository.is_shared():
+    if repository is not None and repository.is_shared():
         # lightweight checkout of branch in shared repository
-        locs['shared repository'] = repository_path
-    order = ['light checkout root', 'repository checkout root',
-             'checkout root', 'checkout of branch', 'shared repository',
+        locs['shared repository'] = repository.user_url
+    order = ['control directory', 'light checkout root',
+             'repository checkout root', 'checkout root',
+             'checkout of branch', 'shared repository',
              'repository', 'repository branch', 'branch root',
              'bound to branch']
     return [(n, locs[n]) for n in order if n in locs]
@@ -335,7 +347,7 @@
     try:
         tree = a_bzrdir.open_workingtree(
             recommend_upgrade=False)
-    except (NoWorkingTree, NotLocalUrl):
+    except (NoWorkingTree, NotLocalUrl, NotBranchError):
         tree = None
         try:
             branch = a_bzrdir.open_branch()
@@ -344,9 +356,8 @@
             try:
                 repository = a_bzrdir.open_repository()
             except NoRepositoryPresent:
-                # Return silently; cmd_info already returned NotBranchError
-                # if no controldir could be opened.
-                return
+                lockable = None
+                repository = None
             else:
                 lockable = repository
         else:
@@ -357,12 +368,14 @@
         repository = branch.repository
         lockable = tree
 
-    lockable.lock_read()
+    if lockable is not None:
+        lockable.lock_read()
     try:
         show_component_info(a_bzrdir, repository, branch, tree, verbose,
                             outfile)
     finally:
-        lockable.unlock()
+        if lockable is not None:
+            lockable.unlock()
 
 
 def show_component_info(control, repository, branch=None, working=None,
@@ -374,11 +387,13 @@
         verbose = 1
     if verbose is True:
         verbose = 2
-    layout = describe_layout(repository, branch, working)
+    layout = describe_layout(repository, branch, working, control)
     format = describe_format(control, repository, branch, working)
     outfile.write("%s (format: %s)\n" % (layout, format))
-    _show_location_info(gather_location_info(repository, branch, working),
-                        outfile)
+    _show_location_info(
+        gather_location_info(control=control, repository=repository,
+            branch=branch, working=working),
+        outfile)
     if branch is not None:
         _show_related_info(branch, outfile)
     if verbose == 0:
@@ -403,13 +418,21 @@
     _show_repository_stats(repository, stats, outfile)
 
 
-def describe_layout(repository=None, branch=None, tree=None):
+def describe_layout(repository=None, branch=None, tree=None, control=None):
     """Convert a control directory layout into a user-understandable term
 
     Common outputs include "Standalone tree", "Repository branch" and
     "Checkout".  Uncommon outputs include "Unshared repository with trees"
     and "Empty control directory"
     """
+    if branch is None and control is not None:
+        try:
+            branch_reference = control.get_branch_reference()
+        except NotBranchError:
+            pass
+        else:
+            if branch_reference is not None:
+                return "Dangling branch reference"
     if repository is None:
         return 'Empty control directory'
     if branch is None and tree is None:

=== modified file 'bzrlib/tests/blackbox/test_info.py'
--- a/bzrlib/tests/blackbox/test_info.py	2011-11-07 10:42:00 +0000
+++ b/bzrlib/tests/blackbox/test_info.py	2011-11-15 17:27:46 +0000
@@ -17,6 +17,7 @@
 
 """Tests for the info command of bzr."""
 
+import shutil
 import sys
 
 from bzrlib import (
@@ -46,6 +47,27 @@
         self.assertEqual(out, '')
         self.assertEqual(err, 'bzr: ERROR: Not a branch: "%s".\n' % location)
 
+    def test_info_empty_controldir(self):
+        self.make_bzrdir('ctrl')
+        out, err = self.run_bzr('info ctrl')
+        self.assertEquals(out,
+            'Empty control directory (format: 1.14 or 1.14-rich-root or 2a or pack-0.92)\n'
+            'Location:\n'
+            '  control directory: ctrl\n')
+        self.assertEquals(err, '')
+
+    def test_info_dangling_branch_reference(self):
+        br = self.make_branch('target')
+        br.create_checkout('from', lightweight=True)
+        shutil.rmtree('target')
+        out, err = self.run_bzr('info from')
+        self.assertEquals(out,
+            'Dangling branch reference (format: 1.14 or 1.14-rich-root or 2a or pack-0.92)\n'
+            'Location:\n'
+            '   control directory: from\n'
+            '  checkout of branch: target\n')
+        self.assertEquals(err, '')
+
     def test_info_standalone(self):
         transport = self.get_transport()
 

=== modified file 'bzrlib/tests/blackbox/test_shared_repository.py'
--- a/bzrlib/tests/blackbox/test_shared_repository.py	2011-05-13 12:51:05 +0000
+++ b/bzrlib/tests/blackbox/test_shared_repository.py	2011-11-16 00:55:10 +0000
@@ -120,7 +120,7 @@
         # being too low. If rpc_count increases, more network roundtrips have
         # become necessary for this use case. Please do not adjust this number
         # upwards without agreement from bzr's network support maintainers.
-        self.assertLength(15, self.hpss_calls)
+        self.assertLength(17, self.hpss_calls)
 
     def test_notification_on_branch_from_repository(self):
         out, err = self.run_bzr("init-repository -q a")

=== modified file 'bzrlib/tests/test_info.py'
--- a/bzrlib/tests/test_info.py	2011-11-08 00:36:33 +0000
+++ b/bzrlib/tests/test_info.py	2011-11-15 17:27:46 +0000
@@ -192,35 +192,41 @@
         self.assertEqual('unnamed', info.describe_format(tree.bzrdir,
             tree.branch.repository, tree.branch, tree))
 
+    def test_gather_location_controldir_only(self):
+        bzrdir = self.make_bzrdir('.')
+        self.assertEqual([('control directory', bzrdir.user_url)],
+            info.gather_location_info(control=bzrdir))
+
     def test_gather_location_standalone(self):
         tree = self.make_branch_and_tree('tree')
         self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
-            info.gather_location_info(tree.branch.repository, tree.branch,
-                                      tree))
+            info.gather_location_info(
+                tree.branch.repository, tree.branch, tree, control=tree.bzrdir))
         self.assertEqual([('branch root', tree.bzrdir.root_transport.base)],
-            info.gather_location_info(tree.branch.repository, tree.branch))
+            info.gather_location_info(
+                tree.branch.repository, tree.branch, control=tree.bzrdir))
         return tree
 
     def test_gather_location_repo(self):
         srepo = self.make_repository('shared', shared=True)
-        self.assertEqual([('shared repository',
-                          srepo.bzrdir.root_transport.base)],
-                          info.gather_location_info(srepo))
+        self.assertEqual(
+            [('shared repository', srepo.bzrdir.root_transport.base)],
+            info.gather_location_info(srepo, control=srepo.bzrdir))
         urepo = self.make_repository('unshared')
-        self.assertEqual([('repository',
-                          urepo.bzrdir.root_transport.base)],
-                          info.gather_location_info(urepo))
+        self.assertEqual(
+            [('repository', urepo.bzrdir.root_transport.base)],
+            info.gather_location_info(urepo, control=urepo.bzrdir))
 
     def test_gather_location_repo_branch(self):
         srepo = self.make_repository('shared', shared=True)
-        self.assertEqual([('shared repository',
-                          srepo.bzrdir.root_transport.base)],
-                          info.gather_location_info(srepo))
+        self.assertEqual(
+            [('shared repository', srepo.bzrdir.root_transport.base)],
+            info.gather_location_info(srepo, control=srepo.bzrdir))
         tree = self.make_branch_and_tree('shared/tree')
-        self.assertEqual([('shared repository',
-                          srepo.bzrdir.root_transport.base),
-                          ('repository branch', tree.branch.base)],
-                          info.gather_location_info(srepo, tree.branch, tree))
+        self.assertEqual(
+            [('shared repository', srepo.bzrdir.root_transport.base),
+             ('repository branch', tree.branch.base)],
+            info.gather_location_info(srepo, tree.branch, tree, srepo.bzrdir))
 
     def test_gather_location_light_checkout(self):
         tree = self.make_branch_and_tree('tree')
@@ -259,8 +265,8 @@
              self.gather_tree_location_info(shared_checkout))
 
     def gather_tree_location_info(self, tree):
-        return info.gather_location_info(tree.branch.repository, tree.branch,
-                                         tree)
+        return info.gather_location_info(
+            tree.branch.repository, tree.branch, tree, tree.bzrdir)
 
     def test_gather_location_bound(self):
         branch = self.make_branch('branch')
@@ -269,7 +275,8 @@
         self.assertEqual(
             [('branch root', bound_branch.bzrdir.root_transport.base),
              ('bound to branch', branch.bzrdir.root_transport.base)],
-            info.gather_location_info(bound_branch.repository, bound_branch)
+            info.gather_location_info(
+                bound_branch.repository, bound_branch, control=bound_branch.bzrdir)
         )
 
     def test_gather_location_bound_in_repository(self):

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-15 17:22:02 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-16 02:04:25 +0000
@@ -126,6 +126,9 @@
 * ``bzr info`` now shows the master branch location too for
   treeless local branches. (Jelmer Vernooij, #258355)
 
+* ``bzr info`` no longer shows empty output if only a control
+  directory is present. (Jelmer Vernooij, #159098)
+
 * ``bzr mkdir --quiet`` now does not print a line for every created
   directory. (Martin von Gagern, #869915)
 




More information about the bazaar-commits mailing list