57
56
a series in progress, it should be None.
60
def __init__(self, transport=None, format=None, branch=None):
59
def __init__(self, transport, format=None):
61
60
"""Construct a BranchBuilder on transport.
63
62
:param transport: The transport the branch should be created on.
65
64
it will be created.
66
65
:param format: Either a BzrDirFormat, or the name of a format in the
67
66
bzrdir format registry for the branch to be built.
68
:param branch: An already constructed branch to use. This param is
69
mutually exclusive with the transport and format params.
71
if branch is not None:
72
if format is not None:
74
"branch and format kwargs are mutually exclusive")
75
if transport is not None:
77
"branch and transport kwargs are mutually exclusive")
80
if not transport.has('.'):
84
if isinstance(format, str):
85
format = bzrdir.format_registry.make_bzrdir(format)
86
self._branch = bzrdir.BzrDir.create_branch_convenience(
87
transport.base, format=format, force_new_tree=False)
68
if not transport.has('.'):
72
if isinstance(format, str):
73
format = bzrdir.format_registry.make_bzrdir(format)
74
self._branch = bzrdir.BzrDir.create_branch_convenience(transport.base,
75
format=format, force_new_tree=False)
90
78
def build_commit(self, **commit_kwargs):
107
def _do_commit(self, tree, message=None, message_callback=None, **kwargs):
95
def _do_commit(self, tree, message=None, **kwargs):
108
96
reporter = commit.NullCommitReporter()
109
if message is None and message_callback is None:
110
98
message = u'commit %d' % (self._branch.revno() + 1,)
111
return tree.commit(message, message_callback=message_callback,
99
return tree.commit(message,
112
100
reporter=reporter,
115
def _move_branch_pointer(self, new_revision_id,
116
allow_leftmost_as_ghost=False):
103
def _move_branch_pointer(self, new_revision_id):
117
104
"""Point self._branch to a different revision id."""
118
105
self._branch.lock_write()
120
107
# We don't seem to have a simple set_last_revision(), so we
121
108
# implement it here.
122
109
cur_revno, cur_revision_id = self._branch.last_revision_info()
124
g = self._branch.repository.get_graph()
125
new_revno = g.find_distance_to_null(new_revision_id,
126
[(cur_revision_id, cur_revno)])
127
self._branch.set_last_revision_info(new_revno, new_revision_id)
128
except errors.GhostRevisionsHaveNoRevno:
129
if not allow_leftmost_as_ghost:
110
g = self._branch.repository.get_graph()
111
new_revno = g.find_distance_to_null(new_revision_id,
112
[(cur_revision_id, cur_revno)])
113
self._branch.set_last_revision_info(new_revno, new_revision_id)
133
115
self._branch.unlock()
134
116
if self._tree is not None:
162
144
self._tree = None
164
146
def build_snapshot(self, revision_id, parent_ids, actions,
165
message=None, timestamp=None, allow_leftmost_as_ghost=False,
166
committer=None, timezone=None, message_callback=None):
147
message=None, timestamp=None):
167
148
"""Build a commit, shaped in a specific way.
169
150
:param revision_id: The handle for the new commit, can be None
176
157
('rename', ('orig-path', 'new-path'))
177
158
:param message: An optional commit message, if not supplied, a default
178
159
commit message will be written.
179
:param message_callback: A message callback to use for the commit, as
180
per mutabletree.commit.
181
160
:param timestamp: If non-None, set the timestamp of the commit to this
183
:param timezone: An optional timezone for timestamp.
184
:param committer: An optional username to use for commit
185
:param allow_leftmost_as_ghost: True if the leftmost parent should be
186
permitted to be a ghost.
187
162
:return: The revision_id of the new commit
189
164
if parent_ids is not None:
190
if len(parent_ids) == 0:
191
base_id = revision.NULL_REVISION
193
base_id = parent_ids[0]
165
base_id = parent_ids[0]
194
166
if base_id != self._branch.last_revision():
195
self._move_branch_pointer(base_id,
196
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
167
self._move_branch_pointer(base_id)
198
169
if self._tree is not None:
199
170
tree = self._tree
202
173
tree.lock_write()
204
175
if parent_ids is not None:
205
tree.set_parent_ids(parent_ids,
206
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
176
tree.set_parent_ids(parent_ids)
207
177
# Unfortunately, MemoryTree.add(directory) just creates an
208
178
# inventory entry. And the only public function to create a
209
179
# directory is MemoryTree.mkdir() which creates the directory, but
250
220
for file_id, content in new_contents.iteritems():
251
221
tree.put_file_bytes_non_atomic(file_id, content)
252
222
return self._do_commit(tree, message=message, rev_id=revision_id,
253
timestamp=timestamp, timezone=timezone, committer=committer,
254
message_callback=message_callback)