Merge lp:~jelmer/brz/iter-tree-references-lock 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/iter-tree-references-lock
Merge into: lp:brz
Diff against target: 106 lines (+34/-15)
4 files modified
breezy/bzr/workingtree_4.py (+18/-14)
breezy/tests/per_tree/test_tree.py (+1/-1)
breezy/tests/per_workingtree/test_add_reference.py (+1/-0)
breezy/transform.py (+14/-0)
To merge this branch: bzr merge lp:~jelmer/brz/iter-tree-references-lock
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+377793@code.launchpad.net

Commit message

Fix WorkingTree.iter_references, and add test.

Description of the change

Fix WorkingTree.iter_references, and add test.

To post a comment you must log in.
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/workingtree_4.py'
2--- breezy/bzr/workingtree_4.py 2020-01-11 22:33:18 +0000
3+++ breezy/bzr/workingtree_4.py 2020-01-18 00:19:13 +0000
4@@ -130,6 +130,9 @@
5 self.views = self._make_views()
6 # --- allow tests to select the dirstate iter_changes implementation
7 self._iter_changes = dirstate._process_entry
8+ self._repo_supports_tree_reference = getattr(
9+ self._branch.repository._format, "supports_tree_reference",
10+ False)
11
12 def _add(self, files, ids, kinds):
13 """See MutableTree._add."""
14@@ -550,20 +553,21 @@
15 # When the repo doesn't support references, we will have nothing to
16 # return
17 return
18- for key, tree_details in self.current_dirstate()._iter_entries():
19- if tree_details[0][0] in (b'a', b'r'): # absent, relocated
20- # not relevant to the working tree
21- continue
22- if not key[1]:
23- # the root is not a reference.
24- continue
25- relpath = pathjoin(key[0].decode('utf8'), key[1].decode('utf8'))
26- try:
27- if self.kind(relpath) == 'tree-reference':
28- yield relpath
29- except errors.NoSuchFile:
30- # path is missing on disk.
31- continue
32+ with self.lock_read():
33+ for key, tree_details in self.current_dirstate()._iter_entries():
34+ if tree_details[0][0] in (b'a', b'r'): # absent, relocated
35+ # not relevant to the working tree
36+ continue
37+ if not key[1]:
38+ # the root is not a reference.
39+ continue
40+ relpath = pathjoin(key[0].decode('utf8'), key[1].decode('utf8'))
41+ try:
42+ if self.kind(relpath) == 'tree-reference':
43+ yield relpath
44+ except errors.NoSuchFile:
45+ # path is missing on disk.
46+ continue
47
48 def _observed_sha1(self, path, sha_and_stat):
49 """See MutableTree._observed_sha1."""
50
51=== modified file 'breezy/tests/per_tree/test_tree.py'
52--- breezy/tests/per_tree/test_tree.py 2019-09-27 02:48:17 +0000
53+++ breezy/tests/per_tree/test_tree.py 2020-01-18 00:19:13 +0000
54@@ -78,7 +78,7 @@
55 class TestReference(TestCaseWithTree):
56
57 def skip_if_no_reference(self, tree):
58- if not getattr(tree, 'supports_tree_reference', lambda: False)():
59+ if not tree.supports_tree_reference():
60 raise tests.TestNotApplicable('Tree references not supported')
61
62 def create_nested(self):
63
64=== modified file 'breezy/tests/per_workingtree/test_add_reference.py'
65--- breezy/tests/per_workingtree/test_add_reference.py 2019-10-14 00:25:24 +0000
66+++ breezy/tests/per_workingtree/test_add_reference.py 2020-01-18 00:19:13 +0000
67@@ -61,6 +61,7 @@
68 self.assertEqual(
69 sub_tree.last_revision(),
70 tree.get_reference_revision('sub-tree'))
71+ self.assertEqual(['sub-tree'], list(tree.iter_references()))
72
73 def test_add_reference_same_root(self):
74 tree = self.make_branch_and_tree('tree')
75
76=== modified file 'breezy/transform.py'
77--- breezy/transform.py 2020-01-10 01:40:18 +0000
78+++ breezy/transform.py 2020-01-18 00:19:13 +0000
79@@ -2036,6 +2036,11 @@
80 self._iter_changes_cache = dict((c.file_id, c) for c in
81 self._transform.iter_changes())
82
83+ def supports_tree_reference(self):
84+ # TODO(jelmer): Support tree references in _PreviewTree.
85+ # return self._transform._tree.supports_tree_reference()
86+ return False
87+
88 def _content_change(self, file_id):
89 """Return True if the content of this file changed"""
90 changes = self._iter_changes_cache.get(file_id)
91@@ -2342,6 +2347,15 @@
92 with self.get_file(path) as fileobj:
93 return sha_file(fileobj)
94
95+ def get_reference_revision(self, path):
96+ trans_id = self._path2trans_id(path)
97+ if trans_id is None:
98+ raise errors.NoSuchFile(path)
99+ reference_revision = self._transform._new_reference_revision.get(trans_id)
100+ if reference_revision is None:
101+ return self._transform._tree.get_reference_revision(path)
102+ return reference_revision
103+
104 def is_executable(self, path):
105 trans_id = self._path2trans_id(path)
106 if trans_id is None:

Subscribers

People subscribed via source and target branches