~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2006-02-15 08:11:37 UTC
  • mto: (1534.1.24 integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: robertc@robertcollins.net-20060215081137-4c27377517e96dd1
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.

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
import bzrlib.errors as errors
82
83
from bzrlib.errors import (BzrError, PointlessCommit,
83
84
                           HistoryMissing,
84
85
                           ConflictsInTree,
90
91
from bzrlib.trace import mutter, note, warning
91
92
from bzrlib.xml5 import serializer_v5
92
93
from bzrlib.inventory import Inventory, ROOT_ID
 
94
from bzrlib.symbol_versioning import *
93
95
from bzrlib.weave import Weave
94
96
from bzrlib.weavefile import read_weave, write_weave_v5
95
 
from bzrlib.atomicfile import AtomicFile
96
 
 
97
 
 
 
97
from bzrlib.workingtree import WorkingTree
 
98
 
 
99
 
 
100
@deprecated_function(zero_seven)
98
101
def commit(*args, **kwargs):
99
102
    """Commit a new revision to a branch.
100
103
 
124
127
    def missing(self, path):
125
128
        pass
126
129
 
 
130
 
127
131
class ReportCommitToLog(NullCommitReporter):
128
132
 
129
133
    def snapshot_change(self, change, path):
141
145
    def missing(self, path):
142
146
        note('missing %s', path)
143
147
 
 
148
 
144
149
class Commit(object):
145
150
    """Task of committing a new revision.
146
151
 
166
171
            self.config = None
167
172
        
168
173
    def commit(self,
169
 
               branch, message,
 
174
               branch=DEPRECATED_PARAMETER, message=None,
170
175
               timestamp=None,
171
176
               timezone=None,
172
177
               committer=None,
175
180
               allow_pointless=True,
176
181
               strict=False,
177
182
               verbose=False,
178
 
               revprops=None):
 
183
               revprops=None,
 
184
               working_tree=None):
179
185
        """Commit working copy as a new revision.
180
186
 
 
187
        branch -- the deprecated branch to commit to. New callers should pass in 
 
188
                  working_tree instead
 
189
 
 
190
        message -- the commit message, a mandatory parameter
 
191
 
181
192
        timestamp -- if not None, seconds-since-epoch for a
182
193
             postdated/predated commit.
183
194
 
199
210
        """
200
211
        mutter('preparing to commit')
201
212
 
202
 
        self.branch = branch
203
 
        self.weave_store = branch.weave_store
 
213
        if deprecated_passed(branch):
 
214
            warn("Commit.commit (branch, ...): The branch parameter is "
 
215
                 "deprecated as of bzr 0.8. Please use working_tree= instead.",
 
216
                 DeprecationWarning, stacklevel=2)
 
217
            self.branch = branch
 
218
            self.work_tree = self.branch.bzrdir.open_workingtree()
 
219
        elif working_tree is None:
 
220
            raise BzrError("One of branch and working_tree must be passed into commit().")
 
221
        else:
 
222
            self.work_tree = working_tree
 
223
            self.branch = self.work_tree.branch
 
224
        if message is None:
 
225
            raise BzrError("The message keyword parameter is required for commit().")
 
226
 
 
227
        self.weave_store = self.branch.repository.weave_store
204
228
        self.rev_id = rev_id
205
229
        self.specific_files = specific_files
206
230
        self.allow_pointless = allow_pointless
207
 
        self.revprops = {'branch-nick': branch.nick}
 
231
        self.revprops = {'branch-nick': self.branch.nick}
208
232
        if revprops:
209
233
            self.revprops.update(revprops)
210
234
 
 
235
        # check for out of date working trees
 
236
        if self.work_tree.last_revision() != self.branch.last_revision():
 
237
            raise errors.OutOfDateTree(self.work_tree)
 
238
 
211
239
        if strict:
212
240
            # raise an exception as soon as we find a single unknown.
213
 
            for unknown in branch.unknowns():
 
241
            for unknown in self.work_tree.unknowns():
214
242
                raise StrictCommitFailed()
215
243
 
216
244
        if timestamp is None:
245
273
 
246
274
        self.branch.lock_write()
247
275
        try:
248
 
            self.work_tree = self.branch.working_tree()
249
276
            self.work_inv = self.work_tree.inventory
250
 
            self.basis_tree = self.branch.basis_tree()
 
277
            self.basis_tree = self.work_tree.basis_tree()
251
278
            self.basis_inv = self.basis_tree.inventory
252
279
 
253
280
            self._gather_parents()
270
297
 
271
298
            self._record_inventory()
272
299
            self._make_revision()
 
300
            self.work_tree.set_pending_merges([])
273
301
            self.branch.append_revision(self.rev_id)
274
 
            self.work_tree.set_pending_merges([])
 
302
            if len(self.parents):
 
303
                precursor = self.parents[0]
 
304
            else:
 
305
                precursor = None
 
306
            self.work_tree.set_last_revision(self.rev_id, precursor)
275
307
            self.reporter.completed(self.branch.revno()+1, self.rev_id)
276
308
            if self.config.post_commit() is not None:
277
309
                hooks = self.config.post_commit().split(' ')
288
320
        """Store the inventory for the new revision."""
289
321
        inv_text = serializer_v5.write_inventory_to_string(self.new_inv)
290
322
        self.inv_sha1 = sha_string(inv_text)
291
 
        s = self.branch.control_weaves
 
323
        s = self.branch.repository.control_weaves
292
324
        s.add_text('inventory', self.rev_id,
293
325
                   split_lines(inv_text), self.present_parents,
294
326
                   self.branch.get_transaction())
317
349
            self.parents.append(precursor_id)
318
350
        self.parents += pending_merges
319
351
        for revision in self.parents:
320
 
            if self.branch.has_revision(revision):
321
 
                self.parent_invs.append(self.branch.get_inventory(revision))
 
352
            if self.branch.repository.has_revision(revision):
 
353
                inventory = self.branch.repository.get_inventory(revision)
 
354
                self.parent_invs.append(inventory)
322
355
                self.present_parents.append(revision)
323
356
 
324
357
    def _check_parents_present(self):
325
358
        for parent_id in self.parents:
326
359
            mutter('commit parent revision {%s}', parent_id)
327
 
            if not self.branch.has_revision(parent_id):
 
360
            if not self.branch.repository.has_revision(parent_id):
328
361
                if parent_id == self.branch.last_revision():
329
362
                    warning("parent is missing %r", parent_id)
330
363
                    raise HistoryMissing(self.branch, 'revision', parent_id)
346
379
        rev_tmp.seek(0)
347
380
        if self.config.signature_needed():
348
381
            plaintext = Testament(self.rev, self.new_inv).as_short_text()
349
 
            self.branch.store_revision_signature(gpg.GPGStrategy(self.config),
350
 
                                                 plaintext, self.rev_id)
351
 
        self.branch.revision_store.add(rev_tmp, self.rev_id)
 
382
            self.branch.repository.store_revision_signature(
 
383
                gpg.GPGStrategy(self.config), plaintext, self.rev_id)
 
384
        self.branch.repository.revision_store.add(rev_tmp, self.rev_id)
352
385
        mutter('new revision_id is {%s}', self.rev_id)
353
386
 
354
387
    def _remove_deleted(self):
389
422
        for path, ie in self.new_inv.iter_entries():
390
423
            previous_entries = ie.find_previous_heads(
391
424
                self.parent_invs, 
392
 
                self.weave_store.get_weave_or_empty(ie.file_id,
 
425
                self.weave_store.get_weave_prelude_or_empty(ie.file_id,
393
426
                    self.branch.get_transaction()))
394
427
            if ie.revision is None:
395
428
                change = ie.snapshot(self.rev_id, path, previous_entries,