17
17
"""Utility for create branches with particular contents."""
19
from bzrlib import bzrdir, errors, memorytree
22
27
class BranchBuilder(object):
23
"""A BranchBuilder aids creating Branches with particular shapes.
28
r"""A BranchBuilder aids creating Branches with particular shapes.
25
30
The expected way to use BranchBuilder is to construct a
26
31
BranchBuilder on the transport you want your branch on, and then call
33
builder = BranchBuilder(self.get_transport().clone('relpath'))
34
builder.start_series()
35
builder.build_snapshot('rev-id', [],
36
[('add', ('filename', 'f-id', 'file', 'content\n'))])
37
builder.build_snapshot('rev2-id', ['rev-id'],
38
[('modify', ('f-id', 'new-content\n'))])
39
builder.finish_series()
40
branch = builder.get_branch()
39
>>> from bzrlib.transport.memory import MemoryTransport
40
>>> builder = BranchBuilder(MemoryTransport("memory:///"))
41
>>> builder.start_series()
42
>>> builder.build_snapshot('rev-id', None, [
43
... ('add', ('', 'root-id', 'directory', '')),
44
... ('add', ('filename', 'f-id', 'file', 'content\n'))])
46
>>> builder.build_snapshot('rev2-id', ['rev-id'],
47
... [('modify', ('f-id', 'new-content\n'))])
49
>>> builder.finish_series()
50
>>> branch = builder.get_branch()
42
52
:ivar _tree: This is a private member which is not meant to be modified by
43
53
users of this class. While a 'series' is in progress, it should hold a
74
return tree.commit('commit %d' % (self._branch.revno() + 1))
84
return self._do_commit(tree)
88
def _do_commit(self, tree, message=None, **kwargs):
89
reporter = commit.NullCommitReporter()
91
message = u'commit %d' % (self._branch.revno() + 1,)
92
return tree.commit(message,
78
96
def _move_branch_pointer(self, new_revision_id):
79
97
"""Point self._branch to a different revision id."""
80
98
self._branch.lock_write()
192
210
tree.add(to_add_files, to_add_file_ids, to_add_kinds)
193
211
for file_id, content in new_contents.iteritems():
194
212
tree.put_file_bytes_non_atomic(file_id, content)
197
message = u'commit %d' % (self._branch.revno() + 1,)
198
return tree.commit(message, rev_id=revision_id)
213
return self._do_commit(tree, message=message, rev_id=revision_id)