46
46
>>> builder = BranchBuilder(MemoryTransport("memory:///"))
47
47
>>> builder.start_series()
48
48
>>> builder.build_snapshot(None, [
49
... ('add', ('', b'root-id', 'directory', '')),
50
... ('add', ('filename', b'f-id', 'file', 'content\n'))],
51
... revision_id=b'rev-id')
49
... ('add', ('', 'root-id', 'directory', '')),
50
... ('add', ('filename', 'f-id', 'file', 'content\n'))],
51
... revision_id='rev-id')
53
53
>>> builder.build_snapshot(['rev-id'],
54
... [('modify', (b'f-id', 'new-content\n'))],
55
... revision_id=b'rev2-id')
54
... [('modify', ('f-id', 'new-content\n'))],
55
... revision_id='rev2-id')
57
57
>>> builder.finish_series()
58
58
>>> branch = builder.get_branch()
194
194
It can be None, which indicates to use the last commit.
195
195
:param actions: A list of actions to perform. Supported actions are:
196
196
('add', ('path', 'file-id', 'kind', 'content' or None))
197
('modify', ('path', 'new-content'))
198
('unversion', 'path')
197
('modify', ('file-id', 'new-content'))
198
('unversion', 'file-id')
199
199
('rename', ('orig-path', 'new-path'))
201
201
:param message: An optional commit message, if not supplied, a default
243
244
pending.to_add_file_ids.append(file_id)
244
245
pending.to_add_kinds.append(kind)
245
246
if content is not None:
246
pending.new_contents[path] = content
247
pending.new_contents[file_id] = content
247
248
elif action == 'modify':
249
pending.new_contents[path] = content
249
file_id, content = info
250
pending.new_contents[file_id] = content
250
251
elif action == 'unversion':
251
pending.to_unversion_paths.add(info)
252
pending.to_unversion_ids.add(info)
252
253
elif action == 'rename':
253
254
from_relpath, to_relpath = info
254
255
pending.to_rename.append((from_relpath, to_relpath))
261
262
return self._do_commit(tree, message=message, rev_id=revision_id,
262
263
timestamp=timestamp, timezone=timezone, committer=committer,
263
264
message_callback=message_callback)
265
268
def _flush_pending(self, tree, pending):
266
269
"""Flush the pending actions in 'pending', i.e. apply them to 'tree'."""
267
270
for path, file_id in pending.to_add_directories:
269
if tree.has_filename(path) and path in pending.to_unversion_paths:
272
old_id = tree.path2id(path)
273
if old_id is not None and old_id in pending.to_unversion_ids:
270
274
# We're overwriting this path, no need to unversion
271
pending.to_unversion_paths.discard(path)
275
pending.to_unversion_ids.discard(old_id)
272
276
# Special case, because the path already exists
273
277
tree.add([path], [file_id], ['directory'])
275
279
tree.mkdir(path, file_id)
276
280
for from_relpath, to_relpath in pending.to_rename:
277
281
tree.rename_one(from_relpath, to_relpath)
278
if pending.to_unversion_paths:
279
tree.unversion(pending.to_unversion_paths)
282
if pending.to_unversion_ids:
283
tree.unversion([tree.id2path(fid) for fid in pending.to_unversion_ids])
280
284
tree.add(pending.to_add_files, pending.to_add_file_ids, pending.to_add_kinds)
281
for path, content in viewitems(pending.new_contents):
282
tree.put_file_bytes_non_atomic(path, content)
285
for file_id, content in viewitems(pending.new_contents):
286
tree.put_file_bytes_non_atomic(
287
tree.id2path(file_id), content,
284
290
def get_branch(self):
285
291
"""Return the branch created by the builder."""