Merge lp:~jameinel/bzr/lolando-branch-root into lp:bzr

Proposed by John A Meinel
Status: Work in progress
Proposed branch: lp:~jameinel/bzr/lolando-branch-root
Merge into: lp:bzr
Diff against target: 77 lines
2 files modified
NEWS (+5/-0)
bzrlib/builtins.py (+46/-3)
To merge this branch: bzr merge lp:~jameinel/bzr/lolando-branch-root
Reviewer Review Type Date Requested Status
John A Meinel Needs Fixing
Review via email: mp+12740@code.launchpad.net
To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

I'm submitting this on behalf of Lo-lan-do who doesn't seem to have an LP account, and thus cannot request a merge. (Limitation of our current scheme?)

,----
| Hi all,
|
| Resubmitting a merge request that apparently got lost when Bundle
| Buggy was abandoned. This patch adds a --branch-root option to bzr
| root, which can be used to find the location of a branch even from
| within a lightweight checkout.
`----

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John A Meinel wrote:
> John A Meinel has proposed merging lp:~jameinel/bzr/lolando-branch-root into lp:bzr.
>
> Requested reviews:
> bzr-core (bzr-core)
>
>
> I'm submitting this on behalf of Lo-lan-do who doesn't seem to have an LP account, and thus cannot request a merge. (Limitation of our current scheme?)
>
> ,----
> | Hi all,
> |
> | Resubmitting a merge request that apparently got lost when Bundle
> | Buggy was abandoned. This patch adds a --branch-root option to bzr
> | root, which can be used to find the location of a branch even from
> | within a lightweight checkout.
> `----
>

Note that AFAIK, Lo-lan-do has not yet signed the
http://www.canonical.com/contributors
agreement. Also I haven't formally reviewed this, so there shouldn't be
an implicit +1 from myself.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrE8NgACgkQJdeBCYSNAANZKwCgpg2/cEVX8Bpbu9lbQNE9EwRW
yGwAoLGDJ7cYDKYWOp7j7VguGgACwrgM
=ABjE
-----END PGP SIGNATURE-----

Revision history for this message
Martin Pool (mbp) wrote :

It's not super elegant and I'd like to see at least a smoke test, but it otherwise seems ok.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin Pool wrote:
> It's not super elegant and I'd like to see at least a smoke test, but it otherwise seems ok.

Actually if I'm reading the diff correctly it seems quite broken when
you *don't* supply the option.

specifically:

+ def run(self, filename=None, branch_root=False):
         """Print the branch root."""
- - tree = WorkingTree.open_containing(filename)[0]
- - self.outf.write(tree.basedir + '\n')
+ if branch_root:

^- This seems to remove the code that opens the tree
...

+ else:
+ self.outf.write(tree.basedir + '\n')
+

^- This directly accesses 'tree.basedir' in the else clause, but the
tree hasn't been opened.

 review: needs_fixing

I also don't understand why it goes through
'info.gather_location_info()' and then sort of parses the text there.
Maybe to handle stuff like heavyweight checkouts?

I think the direct way is:

a_bzrdir = bzrdir.BzrDir.open_containing(...)
reference = a_bzrdir.get_branch_reference()
if reference is not None:
  # This is a lightweight checkout of some other location
else:
  branch = a_bzrdir.open_branch()

However, open_branch() will open the referenced branch, so it may just be:

tree = WorkingTree.open_containing('.')[0]
if branch_root:
  self.outf.write(tree.branch.base)
else:
  self.outf.write(tree.basedir)

I agree with Martin that we should have at least a smoke test of this in
bzrlib/tests/blackbox/test_root.py

Though it is possible we don't have direct tests of "bzr root" yet.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrE9P8ACgkQJdeBCYSNAAPu/ACfW3usaFT49dWK409uxqI/CkdI
ZcwAn0aFdLWkUL1IcGrdgsHD8zeE7Ry6
=Kavs
-----END PGP SIGNATURE-----

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2009-10-01 14:44:43 +0000
+++ NEWS 2009-10-01 18:05:19 +0000
@@ -38,6 +38,11 @@
38 disable the user, site and core plugin directories.38 disable the user, site and core plugin directories.
39 (Vincent Ladeuil, #412930, #316192, #145612)39 (Vincent Ladeuil, #412930, #316192, #145612)
4040
41* ``bzr root`` now has a ``--branch-root`` option to display the root
42 of the branch, which may be different from the root of the working
43 tree.
44 (Roland Mas)
45
41Bug Fixes46Bug Fixes
42*********47*********
4348
4449
=== modified file 'bzrlib/builtins.py'
--- bzrlib/builtins.py 2009-09-16 02:52:14 +0000
+++ bzrlib/builtins.py 2009-10-01 18:05:19 +0000
@@ -2020,11 +2020,54 @@
2020 directory."""2020 directory."""
20212021
2022 takes_args = ['filename?']2022 takes_args = ['filename?']
2023 takes_options = [
2024 Option('branch-root',
2025 help='Print the branch root rather than the '
2026 'working tree root.')
2027 ]
2023 @display_command2028 @display_command
2024 def run(self, filename=None):2029 def run(self, filename=None, branch_root=False):
2025 """Print the branch root."""2030 """Print the branch root."""
2026 tree = WorkingTree.open_containing(filename)[0]2031 if branch_root:
2027 self.outf.write(tree.basedir + '\n')2032 from bzrlib.errors import (NoWorkingTree, NotBranchError,
2033 NoRepositoryPresent, NotLocalUrl)
2034 dir = bzrdir.BzrDir.open_containing(filename)[0]
2035 try:
2036 tree = dir.open_workingtree(
2037 recommend_upgrade=False)
2038 except (NoWorkingTree, NotLocalUrl):
2039 tree = None
2040 try:
2041 branch = dir.open_branch()
2042 except NotBranchError:
2043 branch = None
2044 try:
2045 repository = dir.open_repository()
2046 except NoRepositoryPresent:
2047 # Return silently; cmd_root already returned NotBranchError
2048 # if no bzrdir could be opened.
2049 return
2050 else:
2051 lockable = repository
2052 else:
2053 repository = branch.repository
2054 lockable = branch
2055 else:
2056 branch = tree.branch
2057 repository = branch.repository
2058 lockable = tree
2059
2060 from bzrlib.info import gather_location_info
2061 lockable.lock_read()
2062 locs = gather_location_info(repository, branch, tree)
2063 for loc in locs:
2064 if loc[0] in ('checkout of branch', 'branch root', 'repository branch'):
2065 path = urlutils.local_path_from_url(loc[1])
2066 self.outf.write(path + '\n')
2067 lockable.unlock()
2068 else:
2069 self.outf.write(tree.basedir + '\n')
2070
20282071
20292072
2030def _parse_limit(limitstring):2073def _parse_limit(limitstring):