Merge lp:~jelmer/brz/optional-all-file-ids 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/optional-all-file-ids
Merge into: lp:brz
Diff against target: 174 lines (+48/-33)
7 files modified
breezy/git/mapping.py (+0/-3)
breezy/git/tree.py (+1/-1)
breezy/git/workingtree.py (+1/-11)
breezy/tests/per_tree/test_test_trees.py (+17/-10)
breezy/tests/per_tree/test_tree.py (+7/-3)
breezy/tests/per_workingtree/test_workingtree.py (+6/-3)
breezy/transform.py (+16/-2)
To merge this branch: bzr merge lp:~jelmer/brz/optional-all-file-ids
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+358932@code.launchpad.net

Commit message

Make implementing Tree.all_file_ids() optional.

Description of the change

Make implementing Tree.all_file_ids() optional.

This is only used to find duplicate file ids in transform at the moment.
Because git file ids are based on the path, and paths are unique, we're
never going to have clashes.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Thanks!

review: Approve
Revision history for this message
The Breezy Bot (the-breezy-bot) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/git/mapping.py'
2--- breezy/git/mapping.py 2018-11-16 11:37:47 +0000
3+++ breezy/git/mapping.py 2018-11-16 23:22:15 +0000
4@@ -663,9 +663,6 @@
5 self.paths = None
6 self.mapping = mapping
7
8- def all_file_ids(self):
9- return self.file_ids.values()
10-
11 def set_file_id(self, path, file_id):
12 if type(path) is not str:
13 raise TypeError(path)
14
15=== modified file 'breezy/git/tree.py'
16--- breezy/git/tree.py 2018-11-16 22:18:20 +0000
17+++ breezy/git/tree.py 2018-11-16 23:22:15 +0000
18@@ -322,7 +322,7 @@
19 return self._fileid_map.lookup_file_id(osutils.safe_unicode(path))
20
21 def all_file_ids(self):
22- return {self.path2id(path) for path in self.all_versioned_paths()}
23+ raise errors.UnsupportedOperation(self.all_file_ids, self)
24
25 def all_versioned_paths(self):
26 ret = {u''}
27
28=== modified file 'breezy/git/workingtree.py'
29--- breezy/git/workingtree.py 2018-11-16 19:47:19 +0000
30+++ breezy/git/workingtree.py 2018-11-16 23:22:15 +0000
31@@ -833,17 +833,7 @@
32 self.is_ignored(path) else "?"), kind, None, ie)
33
34 def all_file_ids(self):
35- with self.lock_read():
36- ids = {u"": self.path2id("")}
37- for path in self.index:
38- if self.mapping.is_special_file(path):
39- continue
40- path = path.decode("utf-8")
41- parent = posixpath.dirname(path).strip("/")
42- for e in self._add_missing_parent_ids(parent, ids):
43- pass
44- ids[path] = self.path2id(path)
45- return set(ids.values())
46+ raise errors.UnsupportedOperation(self.all_file_ids, self)
47
48 def all_versioned_paths(self):
49 with self.lock_read():
50
51=== modified file 'breezy/tests/per_tree/test_test_trees.py'
52--- breezy/tests/per_tree/test_test_trees.py 2018-11-12 01:41:38 +0000
53+++ breezy/tests/per_tree/test_test_trees.py 2018-11-16 23:22:15 +0000
54@@ -176,12 +176,17 @@
55 list(tree.unknowns()))
56 # __iter__ has no strongly defined order
57 tree_root = tree.path2id('')
58+ try:
59+ all_file_ids = set(tree.all_file_ids())
60+ except errors.UnsupportedOperation:
61+ all_file_ids = None
62 if tree.has_versioned_directories():
63- self.assertEqual(
64- {tree.path2id(p) for p in [
65- '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
66- '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
67- set(tree.all_file_ids()))
68+ if all_file_ids is not None:
69+ self.assertEqual(
70+ {tree.path2id(p) for p in [
71+ '', '0file', '1top-dir', '1top-dir/1dir-in-1topdir',
72+ '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
73+ set(tree.all_file_ids()))
74 # note that the order of the paths and fileids is deliberately
75 # mismatched to ensure that the result order is path based.
76 self.assertEqual(
77@@ -194,11 +199,13 @@
78 ('1top-dir/1dir-in-1topdir', 'directory')],
79 [(path, node.kind) for path, node in tree.iter_entries_by_dir()])
80 else:
81- self.assertEqual(
82- {tree.path2id(p) for p in [
83- '', '0file', '1top-dir',
84- '1top-dir/0file-in-1topdir', 'symlink', u'2utf\u1234file']},
85- set(tree.all_file_ids()))
86+ if all_file_ids is not None:
87+ self.assertEqual(
88+ {tree.path2id(p) for p in [
89+ '', '0file', '1top-dir',
90+ '1top-dir/0file-in-1topdir', 'symlink',
91+ u'2utf\u1234file']},
92+ set(tree.all_file_ids()))
93 # note that the order of the paths and fileids is deliberately
94 # mismatched to ensure that the result order is path based.
95 self.assertEqual(
96
97=== modified file 'breezy/tests/per_tree/test_tree.py'
98--- breezy/tests/per_tree/test_tree.py 2018-11-16 18:33:17 +0000
99+++ breezy/tests/per_tree/test_tree.py 2018-11-16 23:22:15 +0000
100@@ -147,9 +147,13 @@
101 tree = self.get_tree_no_parents_abc_content(work_tree)
102 tree.lock_read()
103 self.addCleanup(tree.unlock)
104- self.assertEqual(tree.all_file_ids(),
105- {tree.path2id('a'), tree.path2id(''),
106- tree.path2id('b'), tree.path2id('b/c')})
107+ try:
108+ self.assertEqual(tree.all_file_ids(),
109+ {tree.path2id('a'), tree.path2id(''),
110+ tree.path2id('b'), tree.path2id('b/c')})
111+ except errors.UnsupportedOperation:
112+ raise tests.TestNotApplicable(
113+ 'Tree does not support all_file_ids')
114
115
116 class TestStoredKind(TestCaseWithTree):
117
118=== modified file 'breezy/tests/per_workingtree/test_workingtree.py'
119--- breezy/tests/per_workingtree/test_workingtree.py 2018-11-11 04:08:32 +0000
120+++ breezy/tests/per_workingtree/test_workingtree.py 2018-11-16 23:22:15 +0000
121@@ -1075,9 +1075,12 @@
122 self.build_tree(['tree/a', 'tree/b'])
123 tree.add(['a', 'b'])
124 os.unlink('tree/a')
125- self.assertEqual(
126- {'a', 'b', ''},
127- set(tree.all_versioned_paths()))
128+ try:
129+ self.assertEqual(
130+ {'a', 'b', ''},
131+ set(tree.all_versioned_paths()))
132+ except errors.UnsupportedOperation:
133+ raise TestNotApplicable('tree does not support all_file_ids')
134
135 def test_sprout_hardlink(self):
136 real_os_link = getattr(os, 'link', None)
137
138=== modified file 'breezy/transform.py'
139--- breezy/transform.py 2018-11-16 19:47:19 +0000
140+++ breezy/transform.py 2018-11-16 23:22:15 +0000
141@@ -720,9 +720,13 @@
142 def _duplicate_ids(self):
143 """Each inventory id may only be used once"""
144 conflicts = []
145+ try:
146+ all_ids = self._tree.all_file_ids()
147+ except errors.UnsupportedOperation:
148+ # it's okay for non-file-id trees to raise UnsupportedOperation.
149+ return []
150 removed_tree_ids = set((self.tree_file_id(trans_id) for trans_id in
151 self._removed_id))
152- all_ids = self._tree.all_file_ids()
153 active_tree_ids = all_ids.difference(removed_tree_ids)
154 for trans_id, file_id in viewitems(self._new_id):
155 if file_id in active_tree_ids:
156@@ -2064,7 +2068,17 @@
157 return tree_ids
158
159 def all_versioned_paths(self):
160- return {self.id2path(fid) for fid in self.all_file_ids()}
161+ tree_paths = set(self._transform._tree.all_versioned_paths())
162+
163+ tree_paths.difference_update(
164+ self._transform.trans_id_tree_path(t)
165+ for t in self._transform._removed_id)
166+
167+ tree_paths.update(
168+ self._final_paths._determine_path(t)
169+ for t in self._transform._new_id)
170+
171+ return tree_paths
172
173 def _has_id(self, file_id, fallback_check):
174 if file_id in self._transform._r_new_id:

Subscribers

People subscribed via source and target branches