~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2005-09-27 07:24:40 UTC
  • mfrom: (1185.1.41)
  • Revision ID: robertc@robertcollins.net-20050927072440-1bf4d99c3e1db5b3
pair programming worx... merge integration and weave

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
 
65
65
import os
 
66
import re
66
67
import sys
67
68
import time
68
69
import pdb
198
199
 
199
200
        assert isinstance(message, basestring), type(message)
200
201
        self.message = message
 
202
        self._escape_commit_message()
201
203
 
202
204
        self.branch.lock_write()
203
205
        try:
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)
244
246
 
 
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]'
 
255
        else:
 
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(
 
260
            char_pattern,
 
261
            lambda match: match.group(0).encode('unicode_escape'),
 
262
            self.message)
 
263
        if escape_count:
 
264
            note("replaced %d control characters in message", escape_count)
245
265
 
246
266
    def _record_ancestry(self):
247
267
        """Append merged revision ancestry to the ancestry file.
248
268
 
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)
512
532
    assert r not in seen
513
533
    ancs.append(r)
514
534
    return ancs
515