107
def _do_commit(self, tree, message=None, message_callback=None, **kwargs):
106
def _do_commit(self, tree, message=None, **kwargs):
108
107
reporter = commit.NullCommitReporter()
109
if message is None and message_callback is None:
110
109
message = u'commit %d' % (self._branch.revno() + 1,)
111
return tree.commit(message, message_callback=message_callback,
110
return tree.commit(message,
112
111
reporter=reporter,
115
def _move_branch_pointer(self, new_revision_id,
116
allow_leftmost_as_ghost=False):
114
def _move_branch_pointer(self, new_revision_id):
117
115
"""Point self._branch to a different revision id."""
118
116
self._branch.lock_write()
120
118
# We don't seem to have a simple set_last_revision(), so we
121
119
# implement it here.
122
120
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:
121
g = self._branch.repository.get_graph()
122
new_revno = g.find_distance_to_null(new_revision_id,
123
[(cur_revision_id, cur_revno)])
124
self._branch.set_last_revision_info(new_revno, new_revision_id)
133
126
self._branch.unlock()
134
127
if self._tree is not None:
162
155
self._tree = None
164
157
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):
158
message=None, timestamp=None):
167
159
"""Build a commit, shaped in a specific way.
169
161
:param revision_id: The handle for the new commit, can be None
176
168
('rename', ('orig-path', 'new-path'))
177
169
:param message: An optional commit message, if not supplied, a default
178
170
commit message will be written.
179
:param message_callback: A message callback to use for the commit, as
180
per mutabletree.commit.
181
171
: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
173
:return: The revision_id of the new commit
189
175
if parent_ids is not None:
190
if len(parent_ids) == 0:
191
base_id = revision.NULL_REVISION
193
base_id = parent_ids[0]
176
base_id = parent_ids[0]
194
177
if base_id != self._branch.last_revision():
195
self._move_branch_pointer(base_id,
196
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
178
self._move_branch_pointer(base_id)
198
180
if self._tree is not None:
199
181
tree = self._tree
202
184
tree.lock_write()
204
186
if parent_ids is not None:
205
tree.set_parent_ids(parent_ids,
206
allow_leftmost_as_ghost=allow_leftmost_as_ghost)
187
tree.set_parent_ids(parent_ids)
207
188
# Unfortunately, MemoryTree.add(directory) just creates an
208
189
# inventory entry. And the only public function to create a
209
190
# directory is MemoryTree.mkdir() which creates the directory, but
250
231
for file_id, content in new_contents.iteritems():
251
232
tree.put_file_bytes_non_atomic(file_id, content)
252
233
return self._do_commit(tree, message=message, rev_id=revision_id,
253
timestamp=timestamp, timezone=timezone, committer=committer,
254
message_callback=message_callback)