~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

Handled more pipe errors for display commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
from binascii import hexlify
73
73
from cStringIO import StringIO
74
74
 
75
 
from bzrlib.atomicfile import AtomicFile
76
75
from bzrlib.osutils import (local_time_offset,
77
76
                            rand_bytes, compact_date,
78
77
                            kind_marker, is_inside_any, quotefn,
79
78
                            sha_string, sha_strings, sha_file, isdir, isfile,
80
79
                            split_lines)
 
80
from bzrlib.branch import gen_file_id
81
81
import bzrlib.config
82
82
from bzrlib.errors import (BzrError, PointlessCommit,
83
83
                           HistoryMissing,
92
92
from bzrlib.inventory import Inventory, ROOT_ID
93
93
from bzrlib.weave import Weave
94
94
from bzrlib.weavefile import read_weave, write_weave_v5
95
 
from bzrlib.workingtree import WorkingTree
 
95
from bzrlib.atomicfile import AtomicFile
96
96
 
97
97
 
98
98
def commit(*args, **kwargs):
124
124
    def missing(self, path):
125
125
        pass
126
126
 
127
 
 
128
127
class ReportCommitToLog(NullCommitReporter):
129
128
 
130
129
    def snapshot_change(self, change, path):
142
141
    def missing(self, path):
143
142
        note('missing %s', path)
144
143
 
145
 
 
146
144
class Commit(object):
147
145
    """Task of committing a new revision.
148
146
 
209
207
        self.revprops = {'branch-nick': branch.nick}
210
208
        if revprops:
211
209
            self.revprops.update(revprops)
212
 
        self.work_tree = WorkingTree(branch.base, branch)
213
210
 
214
211
        if strict:
215
212
            # raise an exception as soon as we find a single unknown.
216
 
            for unknown in self.work_tree.unknowns():
 
213
            for unknown in branch.unknowns():
217
214
                raise StrictCommitFailed()
218
215
 
219
216
        if timestamp is None:
240
237
        else:
241
238
            self.timezone = int(timezone)
242
239
 
243
 
        if isinstance(message, str):
244
 
            message = message.decode(bzrlib.user_encoding)
245
 
        assert isinstance(message, unicode), type(message)
 
240
        assert isinstance(message, basestring), type(message)
246
241
        self.message = message
247
242
        self._escape_commit_message()
248
243
 
249
244
        self.branch.lock_write()
250
245
        try:
 
246
            self.work_tree = self.branch.working_tree()
251
247
            self.work_inv = self.work_tree.inventory
252
248
            self.basis_tree = self.branch.basis_tree()
253
249
            self.basis_inv = self.basis_tree.inventory
272
268
 
273
269
            self._record_inventory()
274
270
            self._make_revision()
275
 
            self.work_tree.set_pending_merges([])
276
271
            self.branch.append_revision(self.rev_id)
 
272
            self.branch.set_pending_merges([])
277
273
            self.reporter.completed(self.branch.revno()+1, self.rev_id)
278
274
            if self.config.post_commit() is not None:
279
275
                hooks = self.config.post_commit().split(' ')
301
297
        # represented in well-formed XML; escape characters that
302
298
        # aren't listed in the XML specification
303
299
        # (http://www.w3.org/TR/REC-xml/#NT-Char).
 
300
        if isinstance(self.message, unicode):
 
301
            char_pattern = u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]'
 
302
        else:
 
303
            # Use a regular 'str' as pattern to avoid having re.subn
 
304
            # return 'unicode' results.
 
305
            char_pattern = '[^x09\x0A\x0D\x20-\xFF]'
304
306
        self.message, escape_count = re.subn(
305
 
            u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
 
307
            char_pattern,
306
308
            lambda match: match.group(0).encode('unicode_escape'),
307
309
            self.message)
308
310
        if escape_count:
310
312
 
311
313
    def _gather_parents(self):
312
314
        """Record the parents of a merge for merge detection."""
313
 
        pending_merges = self.work_tree.pending_merges()
 
315
        pending_merges = self.branch.pending_merges()
314
316
        self.parents = []
315
317
        self.parent_invs = []
316
318
        self.present_parents = []
376
378
            deleted_ids.sort(reverse=True)
377
379
            for path, file_id in deleted_ids:
378
380
                del self.work_inv[file_id]
379
 
            self.work_tree._write_inventory(self.work_inv)
 
381
            self.branch._write_inventory(self.work_inv)
380
382
 
381
383
    def _store_snapshot(self):
382
384
        """Pass over inventory and record a snapshot.
391
393
        for path, ie in self.new_inv.iter_entries():
392
394
            previous_entries = ie.find_previous_heads(
393
395
                self.parent_invs, 
394
 
                self.weave_store.get_weave_prelude_or_empty(ie.file_id,
 
396
                self.weave_store.get_weave_or_empty(ie.file_id,
395
397
                    self.branch.get_transaction()))
396
398
            if ie.revision is None:
397
399
                change = ie.snapshot(self.rev_id, path, previous_entries,