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
1=== modified file 'NEWS'
2--- NEWS 2009-10-01 14:44:43 +0000
3+++ NEWS 2009-10-01 18:05:19 +0000
4@@ -38,6 +38,11 @@
5 disable the user, site and core plugin directories.
6 (Vincent Ladeuil, #412930, #316192, #145612)
7
8+* ``bzr root`` now has a ``--branch-root`` option to display the root
9+ of the branch, which may be different from the root of the working
10+ tree.
11+ (Roland Mas)
12+
13 Bug Fixes
14 *********
15
16
17=== modified file 'bzrlib/builtins.py'
18--- bzrlib/builtins.py 2009-09-16 02:52:14 +0000
19+++ bzrlib/builtins.py 2009-10-01 18:05:19 +0000
20@@ -2020,11 +2020,54 @@
21 directory."""
22
23 takes_args = ['filename?']
24+ takes_options = [
25+ Option('branch-root',
26+ help='Print the branch root rather than the '
27+ 'working tree root.')
28+ ]
29 @display_command
30- def run(self, filename=None):
31+ def run(self, filename=None, branch_root=False):
32 """Print the branch root."""
33- tree = WorkingTree.open_containing(filename)[0]
34- self.outf.write(tree.basedir + '\n')
35+ if branch_root:
36+ from bzrlib.errors import (NoWorkingTree, NotBranchError,
37+ NoRepositoryPresent, NotLocalUrl)
38+ dir = bzrdir.BzrDir.open_containing(filename)[0]
39+ try:
40+ tree = dir.open_workingtree(
41+ recommend_upgrade=False)
42+ except (NoWorkingTree, NotLocalUrl):
43+ tree = None
44+ try:
45+ branch = dir.open_branch()
46+ except NotBranchError:
47+ branch = None
48+ try:
49+ repository = dir.open_repository()
50+ except NoRepositoryPresent:
51+ # Return silently; cmd_root already returned NotBranchError
52+ # if no bzrdir could be opened.
53+ return
54+ else:
55+ lockable = repository
56+ else:
57+ repository = branch.repository
58+ lockable = branch
59+ else:
60+ branch = tree.branch
61+ repository = branch.repository
62+ lockable = tree
63+
64+ from bzrlib.info import gather_location_info
65+ lockable.lock_read()
66+ locs = gather_location_info(repository, branch, tree)
67+ for loc in locs:
68+ if loc[0] in ('checkout of branch', 'branch root', 'repository branch'):
69+ path = urlutils.local_path_from_url(loc[1])
70+ self.outf.write(path + '\n')
71+ lockable.unlock()
72+ else:
73+ self.outf.write(tree.basedir + '\n')
74+
75
76
77 def _parse_limit(limitstring):