Merge lp:~jelmer/brz/reference-info-file-id into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/reference-info-file-id
Merge into: lp:brz
Prerequisite: lp:~jelmer/brz/move-reference-functions
Diff against target: 399 lines (+77/-70)
9 files modified
breezy/bzr/branch.py (+27/-30)
breezy/bzr/inventorytree.py (+3/-2)
breezy/bzr/workingtree.py (+9/-2)
breezy/tests/blackbox/test_branch.py (+1/-1)
breezy/tests/blackbox/test_reference.py (+5/-6)
breezy/tests/per_workingtree/test_workingtree.py (+24/-20)
breezy/tests/test_branch.py (+4/-4)
breezy/tests/test_bzrdir.py (+1/-2)
breezy/tests/test_reconfigure.py (+3/-3)
To merge this branch: bzr merge lp:~jelmer/brz/reference-info-file-id
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+377801@code.launchpad.net

Commit message

Store bzr reference information by file id rather than by path.

Description of the change

Store bzr reference information by file id rathe rthan by path.

To post a comment you must log in.
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/bzr/branch.py'
2--- breezy/bzr/branch.py 2020-01-19 01:29:22 +0000
3+++ breezy/bzr/branch.py 2020-01-19 03:23:48 +0000
4@@ -450,28 +450,26 @@
5 reconciler = BranchReconciler(self, thorough=thorough)
6 return reconciler.reconcile()
7
8- def set_reference_info(self, tree_path, branch_location, file_id=None):
9+ def set_reference_info(self, file_id, branch_location, path=None):
10 """Set the branch location to use for a tree reference."""
11 raise errors.UnsupportedOperation(self.set_reference_info, self)
12
13- def get_reference_info(self, path):
14+ def get_reference_info(self, file_id, path=None):
15 """Get the tree_path and branch_location for a tree reference."""
16 raise errors.UnsupportedOperation(self.get_reference_info, self)
17
18- def reference_parent(self, path, possible_transports=None):
19+ def reference_parent(self, file_id, path, possible_transports=None):
20 """Return the parent branch for a tree-reference.
21
22 :param path: The path of the nested tree in the tree
23 :return: A branch associated with the nested tree
24 """
25- branch_location = self.get_reference_info(path)[0]
26- if branch_location is None:
27- try:
28- return Branch.open_from_transport(
29- self.controldir.root_transport.clone(path),
30- possible_transports=possible_transports)
31- except errors.NotBranchError:
32- return None
33+ try:
34+ return Branch.open_from_transport(
35+ self.controldir.root_transport.clone(path),
36+ possible_transports=possible_transports)
37+ except errors.NotBranchError:
38+ return None
39
40
41 class BzrBranch8(BzrBranch):
42@@ -541,15 +539,15 @@
43 def _set_all_reference_info(self, info_dict):
44 """Replace all reference info stored in a branch.
45
46- :param info_dict: A dict of {file_id: (tree_path, branch_location)}
47+ :param info_dict: A dict of {file_id: (branch_location, tree_path)}
48 """
49 s = BytesIO()
50 writer = rio.RioWriter(s)
51- for tree_path, (branch_location, file_id) in viewitems(info_dict):
52- stanza = rio.Stanza(tree_path=tree_path,
53+ for file_id, (branch_location, tree_path) in viewitems(info_dict):
54+ stanza = rio.Stanza(file_id=file_id,
55 branch_location=branch_location)
56- if file_id is not None:
57- stanza.add('file_id', file_id)
58+ if tree_path is not None:
59+ stanza.add('tree_path', tree_path)
60 writer.write_stanza(stanza)
61 with self.lock_write():
62 self._transport.put_bytes('references', s.getvalue())
63@@ -567,44 +565,43 @@
64 with self._transport.get('references') as rio_file:
65 stanzas = rio.read_stanzas(rio_file)
66 info_dict = {
67- s['tree_path']: (
68+ s['file_id'].encode('ascii'): (
69 s['branch_location'],
70- s['file_id'].encode('ascii')
71- if 'file_id' in s else None)
72+ s['tree_path'] if 'tree_path' in s else None)
73 for s in stanzas}
74 except errors.NoSuchFile:
75 info_dict = {}
76 self._reference_info = info_dict
77 return info_dict
78
79- def set_reference_info(self, tree_path, branch_location, file_id=None):
80+ def set_reference_info(self, file_id, branch_location, tree_path=None):
81 """Set the branch location to use for a tree reference.
82
83- :param tree_path: The path of the tree reference in the tree.
84 :param branch_location: The location of the branch to retrieve tree
85 references from.
86 :param file_id: The file-id of the tree reference.
87+ :param tree_path: The path of the tree reference in the tree.
88 """
89 info_dict = self._get_all_reference_info()
90- info_dict[tree_path] = (branch_location, file_id)
91+ info_dict[file_id] = (branch_location, tree_path)
92 if branch_location is None:
93- del info_dict[tree_path]
94+ del info_dict[file_id]
95 self._set_all_reference_info(info_dict)
96
97- def get_reference_info(self, path):
98+ def get_reference_info(self, file_id):
99 """Get the tree_path and branch_location for a tree reference.
100
101- :return: a tuple of (branch_location, file_id)
102+ :return: a tuple of (branch_location, tree_path)
103 """
104- return self._get_all_reference_info().get(path, (None, None))
105+ return self._get_all_reference_info().get(file_id, (None, None))
106
107- def reference_parent(self, path, possible_transports=None):
108+ def reference_parent(self, file_id, path, possible_transports=None):
109 """Return the parent branch for a tree-reference.
110
111 :param path: The path of the nested tree in the tree
112 :return: A branch associated with the nested tree
113 """
114- branch_location = self.get_reference_info(path)[0]
115+ branch_location = self.get_reference_info(file_id)[0]
116 if branch_location is None:
117 try:
118 return Branch.open_from_transport(
119@@ -716,9 +713,9 @@
120 class BzrBranch7(BzrBranch8):
121 """A branch with support for a fallback repository."""
122
123- def set_reference_info(self, tree_path, branch_location, file_id=None):
124+ def set_reference_info(self, file_id, branch_location, tree_path=None):
125 super(BzrBranch7, self).set_reference_info(
126- tree_path, branch_location, file_id=file_id)
127+ file_id, branch_location, tree_path)
128 format_string = BzrBranchFormat8.get_format_string()
129 mutter('Upgrading branch to format %r', format_string)
130 self._transport.put_bytes('format', format_string)
131
132=== modified file 'breezy/bzr/inventorytree.py'
133--- breezy/bzr/inventorytree.py 2020-01-19 01:29:22 +0000
134+++ breezy/bzr/inventorytree.py 2020-01-19 03:23:48 +0000
135@@ -790,7 +790,8 @@
136
137 def reference_parent(self, path, branch=None, possible_transports=None):
138 if branch is not None:
139- parent_url = branch.get_reference_info(path)[0]
140+ file_id = self.path2id(path)
141+ parent_url = branch.get_reference_info(file_id)[0]
142 else:
143 subdir = ControlDir.open_from_transport(
144 self._repository.user_transport.clone(path))
145@@ -802,7 +803,7 @@
146 possible_transports=possible_transports)
147
148 def get_reference_info(self, path, branch=None):
149- return branch.get_reference_info(path)[0]
150+ return branch.get_reference_info(self.path2id(path))[0]
151
152 def list_files(self, include_root=False, from_dir=None, recursive=True,
153 recurse_nested=False):
154
155=== modified file 'breezy/bzr/workingtree.py'
156--- breezy/bzr/workingtree.py 2020-01-19 01:29:22 +0000
157+++ breezy/bzr/workingtree.py 2020-01-19 03:23:48 +0000
158@@ -1797,13 +1797,20 @@
159 yield get_canonical_path(self, path, normalize)
160
161 def get_reference_info(self, path, branch=None):
162- return self.branch.get_reference_info(path)[0]
163+ file_id = self.path2id(path)
164+ if file_id is None:
165+ return None
166+ return self.branch.get_reference_info(file_id)[0]
167
168 def set_reference_info(self, tree_path, branch_location):
169- self.branch.set_reference_info(tree_path, branch_location)
170+ file_id = self.path2id(tree_path)
171+ if file_id is None:
172+ raise errors.NoSuchFile(tree_path)
173+ self.branch.set_reference_info(file_id, branch_location, tree_path)
174
175 def reference_parent(self, path, branch=None, possible_transports=None):
176 return self.branch.reference_parent(
177+ self.path2id(path),
178 path, possible_transports=possible_transports)
179
180
181
182=== modified file 'breezy/tests/blackbox/test_branch.py'
183--- breezy/tests/blackbox/test_branch.py 2020-01-18 16:14:28 +0000
184+++ breezy/tests/blackbox/test_branch.py 2020-01-19 03:23:48 +0000
185@@ -367,7 +367,7 @@
186 subtree.add(['a'])
187 subtree.commit('add subtree contents')
188 orig.add_reference(subtree)
189- orig.branch.set_reference_info('subtree', subtree.branch.user_url)
190+ orig.set_reference_info('subtree', subtree.branch.user_url)
191 orig.commit('add subtree')
192
193 self.run_bzr('branch source target')
194
195=== modified file 'breezy/tests/blackbox/test_reference.py'
196--- breezy/tests/blackbox/test_reference.py 2020-01-18 22:02:05 +0000
197+++ breezy/tests/blackbox/test_reference.py 2020-01-19 03:23:48 +0000
198@@ -32,10 +32,10 @@
199 def test_no_args_lists(self):
200 tree = self.make_branch_and_tree('branch')
201 branch = tree.branch
202- branch.set_reference_info('path', 'http://example.org')
203 tree.add_reference(self.make_branch_and_tree('branch/path'))
204 tree.add_reference(self.make_branch_and_tree('branch/lath'))
205- branch.set_reference_info('lath', 'http://example.org/2')
206+ tree.set_reference_info('path', 'http://example.org')
207+ tree.set_reference_info('lath', 'http://example.org/2')
208 out, err = self.run_bzr('reference', working_dir='branch')
209 lines = out.splitlines()
210 self.assertEqual('lath http://example.org/2', lines[0])
211@@ -45,9 +45,8 @@
212 tree = self.make_branch_and_tree('tree')
213 subtree = self.make_branch_and_tree('tree/newpath')
214 tree.add_reference(subtree)
215+ tree.set_reference_info('newpath', 'http://example.org')
216 tree.commit('add reference')
217- tree.set_reference_info('newpath', 'http://example.org')
218- tree.set_reference_info('lath', 'http://example.org/2')
219 return tree
220
221 def test_uses_working_tree_location(self):
222@@ -57,7 +56,6 @@
223
224 def test_uses_basis_tree_location(self):
225 tree = self.make_tree_with_reference()
226- tree.commit('add newpath')
227 tree.controldir.destroy_workingtree()
228 out, err = self.run_bzr('reference', working_dir='tree')
229 self.assertContainsRe(out, 'newpath http://example.org\n')
230@@ -90,10 +88,11 @@
231
232 def test_missing_file_forced(self):
233 tree = self.make_branch_and_tree('tree')
234+ tree.add_reference(self.make_branch_and_tree('tree/file'))
235 out, err = self.run_bzr(
236 'reference --force-unversioned file http://example.org',
237 working_dir='tree')
238- location, file_id = tree.branch.get_reference_info('file')
239+ location = tree.get_reference_info('file')
240 self.assertEqual('http://example.org', location)
241 self.assertEqual('', out)
242 self.assertEqual('', err)
243
244=== modified file 'breezy/tests/per_workingtree/test_workingtree.py'
245--- breezy/tests/per_workingtree/test_workingtree.py 2020-01-19 01:29:22 +0000
246+++ breezy/tests/per_workingtree/test_workingtree.py 2020-01-19 03:23:48 +0000
247@@ -1377,18 +1377,10 @@
248 self.assertIs(None, loc)
249
250 def test_set_reference_info(self):
251- tree = self.make_branch_and_tree('branch')
252- try:
253- tree.set_reference_info('path/to/file', 'path/to/location')
254- except errors.UnsupportedOperation:
255- raise tests.TestNotApplicable('Branch cannot hold references.')
256+ self.make_tree_with_reference('branch', 'path/to/location')
257
258 def test_set_get_reference_info(self):
259- tree = self.make_branch_and_tree('branch')
260- try:
261- tree.set_reference_info('path/to/file', 'path/to/location')
262- except errors.UnsupportedOperation:
263- raise tests.TestNotApplicable('Branch cannot hold references.')
264+ tree = self.make_tree_with_reference('branch', 'path/to/location')
265 # Create a new instance to ensure storage is permanent
266 tree = WorkingTree.open('branch')
267 branch_location = tree.get_reference_info('path/to/file')
268@@ -1398,12 +1390,14 @@
269
270 def test_set_null_reference_info(self):
271 tree = self.make_branch_and_tree('branch')
272+ self.build_tree(['branch/file'])
273+ tree.add(['file'])
274 try:
275- tree.set_reference_info('path/to/file', 'path/to/location')
276+ tree.set_reference_info('file', 'path/to/location')
277 except errors.UnsupportedOperation:
278 raise tests.TestNotApplicable('Branch cannot hold references.')
279- tree.set_reference_info('path/to/file', None)
280- branch_location = tree.get_reference_info('path/to/file')
281+ tree.set_reference_info('file', None)
282+ branch_location = tree.get_reference_info('file')
283 self.assertIs(None, branch_location)
284
285 def test_set_null_reference_info_when_null(self):
286@@ -1413,10 +1407,19 @@
287 except errors.UnsupportedOperation:
288 raise tests.TestNotApplicable('Branch cannot hold references.')
289 self.assertIs(None, branch_location)
290- tree.set_reference_info('path/to/file', None)
291+ self.build_tree(['branch/file'])
292+ tree.add(['file'])
293+ try:
294+ tree.set_reference_info('file', None)
295+ except errors.UnsupportedOperation:
296+ raise tests.TestNotApplicable('Branch cannot hold references.')
297
298 def make_tree_with_reference(self, location, reference_location):
299 tree = self.make_branch_and_tree(location)
300+ self.build_tree(
301+ [os.path.join(location, name)
302+ for name in ['path/', 'path/to/', 'path/to/file']])
303+ tree.add(['path', 'path/to', 'path/to/file'])
304 try:
305 tree.set_reference_info('path/to/file', reference_location)
306 except errors.UnsupportedOperation:
307@@ -1431,12 +1434,7 @@
308 self.assertEqual(parent.base, referenced_branch.base)
309
310 def test_branch_relative_reference_location(self):
311- tree = self.make_branch_and_tree('branch')
312- try:
313- tree.set_reference_info('path/to/file', '../reference_branch')
314- except errors.UnsupportedOperation:
315- raise tests.TestNotApplicable('Branch cannot hold references.')
316- tree.commit('add reference')
317+ tree = self.make_tree_with_reference('branch', '../reference_branch')
318 referenced_branch = self.make_branch('reference_branch')
319 parent = tree.reference_parent('path/to/file')
320 self.assertEqual(parent.base, referenced_branch.base)
321@@ -1492,6 +1490,8 @@
322 tree = self.make_tree_with_reference('branch', 'reference')
323 new_tree = tree.controldir.sprout(
324 'branch/new-branch').open_workingtree()
325+ self.build_tree(['branch/new-branch/foo'])
326+ new_tree.add('foo')
327 new_tree.set_reference_info('foo', '../foo')
328 new_tree.branch.update_references(tree.branch)
329 self.assertEqual(
330@@ -1504,6 +1504,8 @@
331 tree = self.make_tree_with_reference('branch', 'reference')
332 new_tree = tree.controldir.sprout(
333 'branch/new-branch').open_workingtree()
334+ self.build_tree(['branch/new-branch/foo'])
335+ new_tree.add('foo')
336 new_tree.set_reference_info('foo', '../foo')
337 new_tree.commit('set reference')
338 tree.pull(new_tree.branch)
339@@ -1515,6 +1517,8 @@
340 tree = self.make_tree_with_reference('branch', 'reference')
341 new_tree = tree.controldir.sprout(
342 'branch/new-branch').open_workingtree()
343+ self.build_tree(['branch/new-branch/foo'])
344+ new_tree.add(['foo'])
345 new_tree.set_reference_info('foo', '../foo')
346 new_tree.commit('add reference')
347 tree.pull(new_tree.branch)
348
349=== modified file 'breezy/tests/test_branch.py'
350--- breezy/tests/test_branch.py 2020-01-19 01:29:22 +0000
351+++ breezy/tests/test_branch.py 2020-01-19 03:23:48 +0000
352@@ -491,11 +491,11 @@
353 def test_reference_info_caches_cleared(self):
354 branch = self.make_branch('branch')
355 with branch.lock_write():
356- branch.set_reference_info('path2', 'location2', b'file-id')
357+ branch.set_reference_info(b'file-id', 'location2', 'path2')
358 doppelganger = _mod_branch.Branch.open('branch')
359- doppelganger.set_reference_info('path3', 'location3', b'file-id')
360- self.assertEqual(('location3', b'file-id'),
361- branch.get_reference_info('path3'))
362+ doppelganger.set_reference_info(b'file-id', 'location3', 'path3')
363+ self.assertEqual(('location3', 'path3'),
364+ branch.get_reference_info(b'file-id'))
365
366 def _recordParentMapCalls(self, repo):
367 self._parent_map_calls = []
368
369=== modified file 'breezy/tests/test_bzrdir.py'
370--- breezy/tests/test_bzrdir.py 2020-01-19 01:29:22 +0000
371+++ breezy/tests/test_bzrdir.py 2020-01-19 03:23:48 +0000
372@@ -876,8 +876,7 @@
373 sub_tree.add('file')
374 tree.commit('Initial commit')
375 # The following line force the orhaning to reveal bug #634470
376- tree.branch.get_config_stack().set(
377- 'transform.orphan_policy', 'move')
378+ tree.branch.get_config_stack().set('transform.orphan_policy', 'move')
379 tree.controldir.destroy_workingtree()
380 # FIXME: subtree/.bzr is left here which allows the test to pass (or
381 # fail :-( ) -- vila 20100909
382
383=== modified file 'breezy/tests/test_reconfigure.py'
384--- breezy/tests/test_reconfigure.py 2018-11-12 01:41:38 +0000
385+++ breezy/tests/test_reconfigure.py 2020-01-19 03:23:48 +0000
386@@ -461,10 +461,10 @@
387 format = controldir.format_registry.make_controldir('1.9')
388 format.set_branch_format(_mod_bzrbranch.BzrBranchFormat8())
389 tree = self.make_branch_and_tree('tree', format=format)
390- tree.branch.set_reference_info('path', '../location', 'file_id')
391+ tree.branch.set_reference_info(b'file_id', '../location', 'path')
392 checkout = tree.branch.create_checkout('checkout', lightweight=True)
393 reconfiguration = reconfigure.Reconfigure.to_tree(checkout.controldir)
394 reconfiguration.apply()
395 checkout_branch = checkout.controldir.open_branch()
396- self.assertEqual(('../location', b'file_id'),
397- checkout_branch.get_reference_info('path'))
398+ self.assertEqual(('../location', 'path'),
399+ checkout_branch.get_reference_info(b'file_id'))

Subscribers

People subscribed via source and target branches