Merge lp:~jelmer/brz/transform into lp:brz/3.1

Proposed by Jelmer Vernooij on 2020-07-04
Status: Merged
Approved by: Jelmer Vernooij on 2020-07-04
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/transform
Merge into: lp:brz/3.1
Diff against target: 460 lines (+63/-42)
9 files modified
breezy/conflicts.py (+2/-2)
breezy/git/workingtree.py (+2/-1)
breezy/merge.py (+3/-3)
breezy/shelf.py (+1/-1)
breezy/tests/per_workingtree/test_transform.py (+12/-12)
breezy/tests/test_import_tariff.py (+1/-0)
breezy/tests/test_transform.py (+3/-3)
breezy/transform.py (+37/-18)
breezy/upstream_import.py (+2/-2)
To merge this branch: bzr merge lp:~jelmer/brz/transform
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve on 2020-07-04
Review via email: mp+386855@code.launchpad.net

Commit message

Improve the API for Transform.

Description of the change

Improve the API for Transform.

To post a comment you must log in.
Jelmer Vernooij (jelmer) :
review: Approve
lp:~jelmer/brz/transform updated on 2020-07-04
7574. By Jelmer Vernooij on 2020-07-04

Add a code of conduct.

Merged from https://code.launchpad.net/~jelmer/brz/code-of-conduct/+merge/386850

7575. By Jelmer Vernooij on 2020-07-04

Improve the API for Transform.

Merged from https://code.launchpad.net/~jelmer/brz/transform/+merge/386855

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/conflicts.py'
2--- breezy/conflicts.py 2020-07-04 00:38:37 +0000
3+++ breezy/conflicts.py 2020-07-04 14:59:08 +0000
4@@ -518,7 +518,7 @@
5 tree = self._revision_tree(tt._tree, revid)
6 transform.create_from_tree(
7 tt, tid, tree, tree.id2path(file_id))
8- tt.version_file(file_id, tid)
9+ tt.version_file(tid, file_id=file_id)
10 else:
11 tid = tt.trans_id_file_id(file_id)
12 # Adjust the path for the retained file id
13@@ -672,7 +672,7 @@
14 item_parent_tid, item_tid)
15 # Associate the file_id to the right content
16 tt.unversion_file(item_tid)
17- tt.version_file(self.file_id, winner_tid)
18+ tt.version_file(winner_tid, file_id=self.file_id)
19 tt.apply()
20
21 def action_auto(self, tree):
22
23=== modified file 'breezy/git/workingtree.py'
24--- breezy/git/workingtree.py 2020-07-04 00:38:37 +0000
25+++ breezy/git/workingtree.py 2020-07-04 14:59:08 +0000
26@@ -56,7 +56,6 @@
27 controldir as _mod_controldir,
28 globbing,
29 lock,
30- merge,
31 osutils,
32 revision as _mod_revision,
33 trace,
34@@ -1208,6 +1207,7 @@
35 show_base=False):
36 basis_tree = self.revision_tree(old_revision)
37 if new_revision != old_revision:
38+ from .. import merge
39 with basis_tree.lock_read():
40 new_basis_tree = self.branch.basis_tree()
41 merge.merge_inner(
42@@ -1316,6 +1316,7 @@
43
44 def copy_content_into(self, tree, revision_id=None):
45 """Copy the current content and user files of this tree into tree."""
46+ from .. import merge
47 with self.lock_read():
48 if revision_id is None:
49 merge.transform_tree(tree, self)
50
51=== modified file 'breezy/merge.py'
52--- breezy/merge.py 2020-07-04 01:15:59 +0000
53+++ breezy/merge.py 2020-07-04 14:59:08 +0000
54@@ -1288,7 +1288,7 @@
55 keep_this = True
56 # versioning the merged file will trigger a duplicate
57 # conflict
58- self.tt.version_file(file_id, trans_id)
59+ self.tt.version_file(trans_id, file_id=file_id)
60 transform.create_from_tree(
61 self.tt, trans_id, self.other_tree,
62 other_path,
63@@ -1335,7 +1335,7 @@
64 else:
65 raise AssertionError('unknown hook_status: %r' % (hook_status,))
66 if not this_path and result == "modified":
67- self.tt.version_file(file_id, trans_id)
68+ self.tt.version_file(trans_id, file_id=file_id)
69 if not keep_this:
70 # The merge has been performed and produced a new content, so the
71 # old contents should not be retained.
72@@ -1486,7 +1486,7 @@
73 filter_tree_path)
74 file_group.append(trans_id)
75 if set_version and not versioned:
76- self.tt.version_file(file_id, trans_id)
77+ self.tt.version_file(trans_id, file_id=file_id)
78 versioned = True
79 return file_group
80
81
82=== modified file 'breezy/shelf.py'
83--- breezy/shelf.py 2020-07-04 01:15:59 +0000
84+++ breezy/shelf.py 2020-07-04 14:59:08 +0000
85@@ -268,7 +268,7 @@
86 to_transform, s_trans_id, tree,
87 tree.id2path(file_id))
88 if version:
89- to_transform.version_file(file_id, s_trans_id)
90+ to_transform.version_file(s_trans_id, file_id=file_id)
91
92 def _inverse_lines(self, new_lines, file_id):
93 """Produce a version with only those changes removed from new_lines."""
94
95=== modified file 'breezy/tests/per_workingtree/test_transform.py'
96--- breezy/tests/per_workingtree/test_transform.py 2020-07-04 12:18:47 +0000
97+++ breezy/tests/per_workingtree/test_transform.py 2020-07-04 14:59:08 +0000
98@@ -135,20 +135,20 @@
99 self.assertIs(None, transform.final_kind(trans_id))
100 transform.create_file([b'contents'], trans_id)
101 transform.set_executability(True, trans_id)
102- transform.version_file(b'my_pretties', trans_id)
103+ transform.version_file(trans_id, file_id=b'my_pretties')
104 self.assertRaises(DuplicateKey, transform.version_file,
105- b'my_pretties', trans_id)
106+ trans_id, file_id=b'my_pretties')
107 self.assertEqual(transform.final_file_id(trans_id), b'my_pretties')
108 self.assertEqual(transform.final_parent(trans_id), root)
109 self.assertIs(transform.final_parent(root), ROOT_PARENT)
110 self.assertIs(transform.get_tree_parent(root), ROOT_PARENT)
111 oz_id = transform.create_path('oz', root)
112 transform.create_directory(oz_id)
113- transform.version_file(b'ozzie', oz_id)
114+ transform.version_file(oz_id, file_id=b'ozzie')
115 trans_id2 = transform.create_path('name2', root)
116 transform.create_file([b'contents'], trans_id2)
117 transform.set_executability(False, trans_id2)
118- transform.version_file(b'my_pretties2', trans_id2)
119+ transform.version_file(trans_id2, file_id=b'my_pretties2')
120 modified_paths = transform.apply().modified_paths
121 with self.wt.get_file('name') as f:
122 self.assertEqual(b'contents', f.read())
123@@ -419,7 +419,7 @@
124 self.assertEqual(transform.find_conflicts(),
125 [('unversioned parent', lion_id),
126 ('missing parent', lion_id)])
127- transform.version_file(b"Courage", lion_id)
128+ transform.version_file(lion_id, file_id=b"Courage")
129 self.assertEqual(transform.find_conflicts(),
130 [('missing parent', lion_id),
131 ('versioning no contents', lion_id)])
132@@ -436,7 +436,7 @@
133 transform.set_executability(True, oz_id)
134 self.assertEqual(transform.find_conflicts(),
135 [('unversioned executability', oz_id)])
136- transform.version_file(b'oz-id', oz_id)
137+ transform.version_file(oz_id, file_id=b'oz-id')
138 self.assertEqual(transform.find_conflicts(),
139 [('non-file executability', oz_id)])
140 transform.set_executability(None, oz_id)
141@@ -764,7 +764,7 @@
142 transform.new_symlink(link_name1, oz_id, link_target1, b'wizard-id')
143 wiz_id = transform.create_path(link_name2, oz_id)
144 transform.create_symlink(link_target2, wiz_id)
145- transform.version_file(b'wiz-id2', wiz_id)
146+ transform.version_file(wiz_id, file_id=b'wiz-id2')
147 transform.set_executability(True, wiz_id)
148 self.assertEqual(transform.find_conflicts(),
149 [('non-file executability', wiz_id)])
150@@ -987,7 +987,7 @@
151 transform, root = self.transform()
152 transform.adjust_root_path('oldroot', fun)
153 new_root = transform.trans_id_tree_path('')
154- transform.version_file(b'new-root', new_root)
155+ transform.version_file(new_root, file_id=b'new-root')
156 transform.apply()
157
158 def test_renames(self):
159@@ -1148,7 +1148,7 @@
160 transform, root = self.transform()
161 try:
162 old = transform.trans_id_tree_path('old')
163- transform.version_file(b'id-1', old)
164+ transform.version_file(old, file_id=b'id-1')
165 self.assertEqual([(b'id-1', (None, 'old'), False, (False, True),
166 (b'eert_toor', b'eert_toor'),
167 ('old', 'old'), ('file', 'file'),
168@@ -1197,7 +1197,7 @@
169 # move file_id to a different file
170 self.assertEqual([], list(transform.iter_changes()))
171 transform.unversion_file(old)
172- transform.version_file(b'id-1', new)
173+ transform.version_file(new, file_id=b'id-1')
174 transform.adjust_path('old', root, new)
175 self.assertEqual([(b'id-1', ('old', 'old'), True, (True, True),
176 (b'eert_toor', b'eert_toor'),
177@@ -1308,7 +1308,7 @@
178 transform.create_directory(subdir)
179 transform.set_executability(False, old)
180 transform.unversion_file(old)
181- transform.version_file(b'id-1', old)
182+ transform.version_file(old, file_id=b'id-1')
183 transform.adjust_path('old', root, old)
184 self.assertEqual([], list(transform.iter_changes()))
185 finally:
186@@ -1550,7 +1550,7 @@
187 tt.create_directory(foo_trans_id)
188 bar_trans_id = tt.trans_id_tree_path("foo/bar")
189 tt.create_file([b"aa\n"], bar_trans_id)
190- tt.version_file(b"bar-1", bar_trans_id)
191+ tt.version_file(bar_trans_id, file_id=b"bar-1")
192 tt.apply()
193 self.assertPathExists("foo/bar")
194 with wt.lock_read():
195
196=== modified file 'breezy/tests/test_import_tariff.py'
197--- breezy/tests/test_import_tariff.py 2020-06-22 02:05:31 +0000
198+++ breezy/tests/test_import_tariff.py 2020-07-04 14:59:08 +0000
199@@ -228,6 +228,7 @@
200 'breezy.gpg',
201 'breezy.info',
202 'breezy.bzr.knit',
203+ 'breezy.merge',
204 'breezy.merge3',
205 'breezy.merge_directive',
206 'breezy.msgeditor',
207
208=== modified file 'breezy/tests/test_transform.py'
209--- breezy/tests/test_transform.py 2020-07-04 12:23:16 +0000
210+++ breezy/tests/test_transform.py 2020-07-04 14:59:08 +0000
211@@ -124,7 +124,7 @@
212 tree.add('foo', b'foo-id')
213 with tree.preview_transform() as tt:
214 tt.unversion_file(tt.root)
215- tt.version_file(b'new-id', tt.root)
216+ tt.version_file(tt.root, file_id=b'new-id')
217 foo_trans_id = tt.trans_id_tree_path('foo')
218 foo_tuple = ('foo', foo_trans_id)
219 root_tuple = ('', tt.root)
220@@ -136,7 +136,7 @@
221 tree.add('foo', b'foo-id')
222 with tree.preview_transform() as tt:
223 tt.unversion_file(tt.root)
224- tt.version_file(tree.path2id(''), tt.root)
225+ tt.version_file(tt.root, file_id=tree.path2id(''))
226 tt.trans_id_tree_path('foo')
227 self.assertEqual([], tt._inventory_altered())
228
229@@ -1374,7 +1374,7 @@
230 preview.unversion_file(preview.trans_id_file_id(b'b-id'))
231 c_trans_id = preview.trans_id_file_id(b'c-id')
232 preview.unversion_file(c_trans_id)
233- preview.version_file(b'c-id', c_trans_id)
234+ preview.version_file(c_trans_id, file_id=b'c-id')
235 preview_tree = preview.get_preview_tree()
236 self.assertEqual({b'a-id', b'c-id', tree.path2id('')},
237 preview_tree.all_file_ids())
238
239=== modified file 'breezy/transform.py'
240--- breezy/transform.py 2020-07-04 00:38:37 +0000
241+++ breezy/transform.py 2020-07-04 14:59:08 +0000
242@@ -23,8 +23,10 @@
243
244 from . import (
245 config as _mod_config,
246+ controldir,
247 errors,
248 lazy_import,
249+ osutils,
250 registry,
251 trace,
252 tree,
253@@ -32,25 +34,22 @@
254 lazy_import.lazy_import(globals(), """
255 from breezy import (
256 annotate,
257- bencode,
258 cleanup,
259- controldir,
260 commit,
261 conflicts,
262- delta,
263 lock,
264 multiparent,
265- osutils,
266 revision as _mod_revision,
267 ui,
268 urlutils,
269 )
270+from breezy.i18n import gettext
271 from breezy.bzr import (
272 inventory,
273 inventorytree,
274 )
275-from breezy.i18n import gettext
276 """)
277+
278 from .errors import (DuplicateKey,
279 CantMoveRoot,
280 BzrError, InternalBzrError)
281@@ -188,6 +187,23 @@
282 """Support Context Manager API."""
283 self.finalize()
284
285+ def iter_tree_children(self, trans_id):
286+ """Iterate through the entry's tree children, if any.
287+
288+ :param trans_id: trans id to iterate
289+ :returns: Iterator over paths
290+ """
291+ raise NotImplementedError(self.iter_tree_children)
292+
293+ def _read_symlink_target(self, trans_id):
294+ raise NotImplementedError(self._read_symlink_target)
295+
296+ def canonical_path(self, path):
297+ return path
298+
299+ def tree_kind(self, trans_id):
300+ raise NotImplementedError(self.tree_kind)
301+
302 def finalize(self):
303 """Release the working tree lock, if held.
304
305@@ -247,7 +263,7 @@
306 file_id = self.final_file_id(child_id)
307 if file_id is not None:
308 self.unversion_file(child_id)
309- self.version_file(file_id, child_id)
310+ self.version_file(child_id, file_id=file_id)
311
312 # the physical root needs a new transaction id
313 self._tree_path_ids.pop("")
314@@ -257,7 +273,7 @@
315 parent = self._new_root
316 self.adjust_path(name, parent, old_root)
317 self.create_directory(old_root)
318- self.version_file(old_root_file_id, old_root)
319+ self.version_file(old_root, file_id=old_root_file_id)
320 self.unversion_file(self._new_root)
321
322 def fixup_new_roots(self):
323@@ -297,7 +313,7 @@
324 and self._new_root not in self._removed_id):
325 self.unversion_file(self._new_root)
326 if file_id is not None:
327- self.version_file(file_id, self._new_root)
328+ self.version_file(self._new_root, file_id=file_id)
329
330 # Now move children of new root into old root directory.
331 # Ensure all children are registered with the transaction, but don't
332@@ -391,7 +407,7 @@
333 """Set the reference associated with a directory"""
334 unique_add(self._new_reference_revision, trans_id, revision_id)
335
336- def version_file(self, file_id, trans_id):
337+ def version_file(self, trans_id, file_id=None):
338 """Schedule a file to become versioned."""
339 if file_id is None:
340 raise ValueError()
341@@ -819,7 +835,7 @@
342 """Helper function to create a new filesystem entry."""
343 trans_id = self.create_path(name, parent_id)
344 if file_id is not None:
345- self.version_file(file_id, trans_id)
346+ self.version_file(trans_id, file_id=file_id)
347 return trans_id
348
349 def new_file(self, name, parent_id, contents, file_id=None,
350@@ -897,7 +913,7 @@
351 # The child is removed as part of the transform. Since it was
352 # versioned before, it's not an orphan
353 continue
354- elif self.final_file_id(child_tid) is None:
355+ if self.final_file_id(child_tid) is None:
356 # The child is not versioned
357 orphans.append(child_tid)
358 else:
359@@ -1144,6 +1160,7 @@
360
361 :param serializer: A Serialiser like pack.ContainerSerializer.
362 """
363+ from . import bencode
364 new_name = {k.encode('utf-8'): v.encode('utf-8')
365 for k, v in viewitems(self._new_name)}
366 new_parent = {k.encode('utf-8'): v.encode('utf-8')
367@@ -1195,6 +1212,7 @@
368 :param records: An iterable of (names, content) tuples, as per
369 pack.ContainerPushParser.
370 """
371+ from . import bencode
372 names, content = next(records)
373 attribs = bencode.bdecode(content)
374 self._id_number = attribs[b'_id_number']
375@@ -1403,6 +1421,9 @@
376 descendants.update(self._limbo_descendants(descendant))
377 return descendants
378
379+ def _set_mode(self, trans_id, mode_id, typefunc):
380+ raise NotImplementedError(self._set_mode)
381+
382 def create_file(self, contents, trans_id, mode_id=None, sha1=None):
383 """Schedule creation of a new file.
384
385@@ -2014,9 +2035,6 @@
386 limbodir = osutils.mkdtemp(prefix='bzr-limbo-')
387 DiskTreeTransform.__init__(self, tree, limbodir, pb, case_sensitive)
388
389- def canonical_path(self, path):
390- return path
391-
392 def tree_kind(self, trans_id):
393 path = self._tree_id_paths.get(trans_id)
394 if path is None:
395@@ -2709,7 +2727,7 @@
396 # getting the file text, and get them all at once.
397 trans_id = tt.create_path(entry.name, parent_id)
398 file_trans_id[file_id] = trans_id
399- tt.version_file(file_id, trans_id)
400+ tt.version_file(trans_id, file_id=file_id)
401 executable = tree.is_executable(tree_path)
402 if executable:
403 tt.set_executability(executable, trans_id)
404@@ -2925,6 +2943,7 @@
405 conflicts, merge_modified = _prepare_revert_transform(
406 working_tree, target_tree, tt, filenames, backups, pp)
407 if change_reporter:
408+ from . import delta
409 change_reporter = delta._ChangeReporter(
410 unversioned_filter=working_tree.is_ignored)
411 delta.report_changes(tt.iter_changes(), change_reporter)
412@@ -3013,7 +3032,7 @@
413 new_trans_id = tt.create_path(wt_name, parent_trans_id)
414 if wt_versioned and target_versioned:
415 tt.unversion_file(trans_id)
416- tt.version_file(file_id, new_trans_id)
417+ tt.version_file(new_trans_id, file_id=file_id)
418 # New contents should have the same unix perms as old
419 # contents
420 mode_id = trans_id
421@@ -3051,7 +3070,7 @@
422 elif target_kind is not None:
423 raise AssertionError(target_kind)
424 if not wt_versioned and target_versioned:
425- tt.version_file(file_id, trans_id)
426+ tt.version_file(trans_id, file_id=file_id)
427 if wt_versioned and not target_versioned:
428 tt.unversion_file(trans_id)
429 if (target_name is not None
430@@ -3196,7 +3215,7 @@
431 if path_tree and path_tree.path2id('') == file_id:
432 # This is the root entry, skip it
433 continue
434- tt.version_file(file_id, conflict[1])
435+ tt.version_file(conflict[1], file_id=file_id)
436 new_conflicts.add((c_type, 'Versioned directory', conflict[1]))
437 elif c_type == 'non-directory parent':
438 parent_id = conflict[1]
439
440=== modified file 'breezy/upstream_import.py'
441--- breezy/upstream_import.py 2020-07-04 00:38:37 +0000
442+++ breezy/upstream_import.py 2020-07-04 14:59:08 +0000
443@@ -290,7 +290,7 @@
444 if tt.tree_file_id(trans_id) is None:
445 name = basename(member.name.rstrip('/'))
446 file_id = generate_ids.gen_file_id(name)
447- tt.version_file(file_id, trans_id)
448+ tt.version_file(trans_id, file_id=file_id)
449
450 for relative_path in implied_parents.difference(added):
451 if relative_path == "":
452@@ -299,7 +299,7 @@
453 path = tree.abspath(relative_path)
454 do_directory(tt, trans_id, tree, relative_path, path)
455 if tt.tree_file_id(trans_id) is None:
456- tt.version_file(trans_id, trans_id)
457+ tt.version_file(trans_id, file_id=trans_id)
458 added.add(relative_path)
459
460 for path in removed.difference(added):

Subscribers

People subscribed via source and target branches