~ubuntu-branches/ubuntu/lucid/bzr/lucid-proposed

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

Tags: upstream-0.7
ImportĀ upstreamĀ versionĀ 0.7

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