238
240
"""Store the inventory for the new revision."""
239
241
inv_text = serializer_v5.write_inventory_to_string(self.new_inv)
240
242
self.inv_sha1 = sha_string(inv_text)
241
s = self.branch.control_weaves
243
s = self.branch.control_weaves
242
244
s.add_text('inventory', self.rev_id,
243
split_lines(inv_text), self.parents)
245
split_lines(inv_text), self.parents)
247
def _escape_commit_message(self):
248
"""Replace xml-incompatible control characters."""
249
# Python strings can include characters that can't be
250
# represented in well-formed XML; escape characters that
251
# aren't listed in the XML specification
252
# (http://www.w3.org/TR/REC-xml/#NT-Char).
253
if isinstance(self.message, unicode):
254
char_pattern = u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]'
256
# Use a regular 'str' as pattern to avoid having re.subn
257
# return 'unicode' results.
258
char_pattern = '[^x09\x0A\x0D\x20-\xFF]'
259
self.message, escape_count = re.subn(
261
lambda match: match.group(0).encode('unicode_escape'),
264
note("replaced %d control characters in message", escape_count)
246
266
def _record_ancestry(self):
247
267
"""Append merged revision ancestry to the ancestry file.
249
269
This should be the merged ancestry of all parents, plus the
250
270
new revision id."""
251
s = self.branch.control_weaves
271
s = self.branch.control_weaves
252
272
w = s.get_weave_or_empty('ancestry')
253
273
lines = self._make_ancestry(w)
254
274
w.add(self.rev_id, self.parents, lines)