Merge lp:~jelmer/bzr/co-directory-service into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6516
Proposed branch: lp:~jelmer/bzr/co-directory-service
Merge into: lp:bzr
Diff against target: 140 lines (+48/-7)
4 files modified
bzrlib/directory_service.py (+19/-0)
bzrlib/tests/test_directory_service.py (+21/-0)
bzrlib/tests/test_mergetools.py (+5/-7)
doc/en/release-notes/bzr-2.6.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/co-directory-service
Reviewer Review Type Date Requested Status
Vincent Ladeuil Needs Fixing
Review via email: mp+98629@code.launchpad.net

Commit message

Add co: directory service.

Description of the change

Add the 'co:' directory service.

This allows addressing colocated branches with a somewhat easier syntax,
instead of the frustratingly long "file:.,branch=NAME".

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

What's new worthy !

Could you make 'co:' appear in some 'bzr help' output ?

review: Needs Fixing

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/directory_service.py'
2--- bzrlib/directory_service.py 2011-12-19 13:23:58 +0000
3+++ bzrlib/directory_service.py 2012-03-21 13:34:24 +0000
4@@ -30,6 +30,7 @@
5 lazy_import(globals(), """
6 from bzrlib import (
7 branch as _mod_branch,
8+ controldir as _mod_controldir,
9 urlutils,
10 )
11 """)
12@@ -131,3 +132,21 @@
13
14 directories.register(':', AliasDirectory,
15 'Easy access to remembered branch locations')
16+
17+
18+class ColocatedDirectory(object):
19+ """Directory lookup for colocated branches.
20+
21+ co:somename will resolve to the colocated branch with "somename" in
22+ the current directory.
23+ """
24+
25+ def look_up(self, name, url):
26+ dir = _mod_controldir.ControlDir.open_containing('.')[0]
27+ return urlutils.join_segment_parameters(dir.user_url,
28+ {"branch": urlutils.escape(name)})
29+
30+
31+directories.register('co:', ColocatedDirectory,
32+ 'Easy access to colocated branches')
33+
34
35=== modified file 'bzrlib/tests/test_directory_service.py'
36--- bzrlib/tests/test_directory_service.py 2012-01-18 14:09:19 +0000
37+++ bzrlib/tests/test_directory_service.py 2012-03-21 13:34:24 +0000
38@@ -116,3 +116,24 @@
39 AliasDirectory.branch_aliases.register("booga",
40 lambda b: "UHH?", help="Nobody knows")
41 self.assertEquals("UHH?", directories.dereference(":booga"))
42+
43+
44+class TestColocatedDirectory(TestCaseWithTransport):
45+
46+ def test_lookup_non_default(self):
47+ default = self.make_branch('.')
48+ non_default = default.bzrdir.create_branch(name='nondefault')
49+ self.assertEquals(non_default.base, directories.dereference('co:nondefault'))
50+
51+ def test_lookup_default(self):
52+ default = self.make_branch('.')
53+ non_default = default.bzrdir.create_branch(name='nondefault')
54+ self.assertEquals(urlutils.join_segment_parameters(default.bzrdir.user_url,
55+ {"branch": ""}), directories.dereference('co:'))
56+
57+ def test_no_such_branch(self):
58+ # No error is raised in this case, that is up to the code that actually
59+ # opens the branch.
60+ default = self.make_branch('.')
61+ self.assertEquals(urlutils.join_segment_parameters(default.bzrdir.user_url,
62+ {"branch": "foo"}), directories.dereference('co:foo'))
63
64=== modified file 'bzrlib/tests/test_mergetools.py'
65--- bzrlib/tests/test_mergetools.py 2012-02-28 04:58:14 +0000
66+++ bzrlib/tests/test_mergetools.py 2012-03-21 13:34:24 +0000
67@@ -15,7 +15,6 @@
68 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
69
70 import os
71-import re
72 import sys
73 import tempfile
74
75@@ -23,7 +22,6 @@
76 mergetools,
77 tests
78 )
79-from bzrlib.tests.features import backslashdir_feature
80
81
82 class TestFilenameSubstitution(tests.TestCaseInTempDir):
83@@ -39,7 +37,7 @@
84 '-o',
85 'test.txt'],
86 args)
87-
88+
89 def test_spaces(self):
90 cmd_list = ['kdiff3', '{base}', '{this}', '{other}', '-o', '{result}']
91 args, tmpfile = mergetools._subst_filename(cmd_list,
92@@ -107,7 +105,7 @@
93 ('test.txt.THIS', 'this stuff'),
94 ('test.txt.OTHER', 'other stuff'),
95 ))
96-
97+
98 def test_invoke_expands_exe_path(self):
99 self.overrideEnv('PATH', os.path.dirname(sys.executable))
100 def dummy_invoker(exe, args, cleanup):
101@@ -120,7 +118,7 @@
102 self.assertEqual(0, retcode)
103 self.assertEqual(sys.executable, self._exe)
104 self.assertEqual(['test.txt'], self._args)
105-
106+
107 def test_success(self):
108 def dummy_invoker(exe, args, cleanup):
109 self._exe = exe
110@@ -131,7 +129,7 @@
111 self.assertEqual(0, retcode)
112 self.assertEqual('tool', self._exe)
113 self.assertEqual(['test.txt'], self._args)
114-
115+
116 def test_failure(self):
117 def dummy_invoker(exe, args, cleanup):
118 self._exe = exe
119@@ -159,7 +157,7 @@
120 self.assertEqual('tool', self._exe)
121 self.assertPathDoesNotExist(self._args[0])
122 self.assertFileEqual('temp stuff', 'test.txt')
123-
124+
125 def test_failure_tempfile(self):
126 def dummy_invoker(exe, args, cleanup):
127 self._exe = exe
128
129=== modified file 'doc/en/release-notes/bzr-2.6.txt'
130--- doc/en/release-notes/bzr-2.6.txt 2012-03-16 15:05:05 +0000
131+++ doc/en/release-notes/bzr-2.6.txt 2012-03-21 13:34:24 +0000
132@@ -26,6 +26,9 @@
133 .. Improvements to existing commands, especially improved performance
134 or memory usage, or better results.
135
136+* Colocated branches can now be addressed using the 'co:NAME' rather than
137+ the more complex 'file://.,branch=NAME'. (Jelmer Vernooij, #833665)
138+
139 Bug Fixes
140 *********
141