~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

Merge in bzrdir work to enable checkout improvements.

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
from bzrlib.trace import mutter, note, warning
91
91
from bzrlib.xml5 import serializer_v5
92
92
from bzrlib.inventory import Inventory, ROOT_ID
 
93
from bzrlib.symbol_versioning import *
93
94
from bzrlib.weave import Weave
94
95
from bzrlib.weavefile import read_weave, write_weave_v5
95
96
from bzrlib.workingtree import WorkingTree
96
97
 
97
98
 
 
99
@deprecated_function(zero_seven)
98
100
def commit(*args, **kwargs):
99
101
    """Commit a new revision to a branch.
100
102
 
168
170
            self.config = None
169
171
        
170
172
    def commit(self,
171
 
               branch, message,
 
173
               branch=DEPRECATED_PARAMETER, message=None,
172
174
               timestamp=None,
173
175
               timezone=None,
174
176
               committer=None,
177
179
               allow_pointless=True,
178
180
               strict=False,
179
181
               verbose=False,
180
 
               revprops=None):
 
182
               revprops=None,
 
183
               working_tree=None):
181
184
        """Commit working copy as a new revision.
182
185
 
 
186
        branch -- the deprecated branch to commit to. New callers should pass in 
 
187
                  working_tree instead
 
188
 
 
189
        message -- the commit message, a mandatory parameter
 
190
 
183
191
        timestamp -- if not None, seconds-since-epoch for a
184
192
             postdated/predated commit.
185
193
 
201
209
        """
202
210
        mutter('preparing to commit')
203
211
 
204
 
        self.branch = branch
205
 
        self.weave_store = branch.weave_store
 
212
        if deprecated_passed(branch):
 
213
            warn("Commit.commit (branch, ...): The branch parameter is "
 
214
                 "deprecated as of bzr 0.8. Please use working_tree= instead.",
 
215
                 DeprecationWarning, stacklevel=2)
 
216
            self.branch = branch
 
217
            self.work_tree = WorkingTree(branch.base, branch)
 
218
        elif working_tree is None:
 
219
            raise BzrError("One of branch and working_tree must be passed into commit().")
 
220
        else:
 
221
            self.work_tree = working_tree
 
222
            self.branch = self.work_tree.branch
 
223
        if message is None:
 
224
            raise BzrError("The message keyword parameter is required for commit().")
 
225
 
 
226
        self.weave_store = self.branch.repository.weave_store
206
227
        self.rev_id = rev_id
207
228
        self.specific_files = specific_files
208
229
        self.allow_pointless = allow_pointless
209
 
        self.revprops = {'branch-nick': branch.nick}
 
230
        self.revprops = {'branch-nick': self.branch.nick}
210
231
        if revprops:
211
232
            self.revprops.update(revprops)
212
 
        self.work_tree = WorkingTree(branch.base, branch)
213
233
 
214
234
        if strict:
215
235
            # raise an exception as soon as we find a single unknown.
249
269
        self.branch.lock_write()
250
270
        try:
251
271
            self.work_inv = self.work_tree.inventory
252
 
            self.basis_tree = self.branch.basis_tree()
 
272
            self.basis_tree = self.work_tree.basis_tree()
253
273
            self.basis_inv = self.basis_tree.inventory
254
274
 
255
275
            self._gather_parents()
274
294
            self._make_revision()
275
295
            self.work_tree.set_pending_merges([])
276
296
            self.branch.append_revision(self.rev_id)
 
297
            if len(self.parents):
 
298
                precursor = self.parents[0]
 
299
            else:
 
300
                precursor = None
 
301
            self.work_tree.set_last_revision(self.rev_id, precursor)
277
302
            self.reporter.completed(self.branch.revno()+1, self.rev_id)
278
303
            if self.config.post_commit() is not None:
279
304
                hooks = self.config.post_commit().split(' ')
290
315
        """Store the inventory for the new revision."""
291
316
        inv_text = serializer_v5.write_inventory_to_string(self.new_inv)
292
317
        self.inv_sha1 = sha_string(inv_text)
293
 
        s = self.branch.control_weaves
 
318
        s = self.branch.repository.control_weaves
294
319
        s.add_text('inventory', self.rev_id,
295
320
                   split_lines(inv_text), self.present_parents,
296
321
                   self.branch.get_transaction())
319
344
            self.parents.append(precursor_id)
320
345
        self.parents += pending_merges
321
346
        for revision in self.parents:
322
 
            if self.branch.has_revision(revision):
323
 
                self.parent_invs.append(self.branch.get_inventory(revision))
 
347
            if self.branch.repository.has_revision(revision):
 
348
                inventory = self.branch.repository.get_inventory(revision)
 
349
                self.parent_invs.append(inventory)
324
350
                self.present_parents.append(revision)
325
351
 
326
352
    def _check_parents_present(self):
327
353
        for parent_id in self.parents:
328
354
            mutter('commit parent revision {%s}', parent_id)
329
 
            if not self.branch.has_revision(parent_id):
 
355
            if not self.branch.repository.has_revision(parent_id):
330
356
                if parent_id == self.branch.last_revision():
331
357
                    warning("parent is missing %r", parent_id)
332
358
                    raise HistoryMissing(self.branch, 'revision', parent_id)
348
374
        rev_tmp.seek(0)
349
375
        if self.config.signature_needed():
350
376
            plaintext = Testament(self.rev, self.new_inv).as_short_text()
351
 
            self.branch.store_revision_signature(gpg.GPGStrategy(self.config),
352
 
                                                 plaintext, self.rev_id)
353
 
        self.branch.revision_store.add(rev_tmp, self.rev_id)
 
377
            self.branch.repository.store_revision_signature(
 
378
                gpg.GPGStrategy(self.config), plaintext, self.rev_id)
 
379
        self.branch.repository.revision_store.add(rev_tmp, self.rev_id)
354
380
        mutter('new revision_id is {%s}', self.rev_id)
355
381
 
356
382
    def _remove_deleted(self):