/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
# XXX: Can we do any better about making interrupted commits change
19
 
# nothing?  Perhaps the best approach is to integrate commit of
20
 
# AtomicFiles with releasing the lock on the Branch.
 
19
# nothing?  
21
20
 
22
21
# TODO: Separate 'prepare' phase where we find a list of potentially
23
22
# committed files.  We then can then pause the commit to prompt for a
67
66
import re
68
67
import sys
69
68
import time
70
 
import warnings
71
69
 
72
70
from cStringIO import StringIO
73
71
 
74
 
from bzrlib.atomicfile import AtomicFile
75
72
import bzrlib.config
76
73
import bzrlib.errors as errors
77
74
from bzrlib.errors import (BzrError, PointlessCommit,
85
82
from bzrlib.trace import mutter, note, warning
86
83
from bzrlib.xml5 import serializer_v5
87
84
from bzrlib.inventory import Inventory, ROOT_ID, InventoryEntry
 
85
from bzrlib import symbol_versioning
88
86
from bzrlib.symbol_versioning import (deprecated_passed,
89
87
        deprecated_function,
90
 
        zero_seven,
91
88
        DEPRECATED_PARAMETER)
92
89
from bzrlib.workingtree import WorkingTree
93
90
 
94
91
 
95
 
@deprecated_function(zero_seven)
96
 
def commit(*args, **kwargs):
97
 
    """Commit a new revision to a branch.
98
 
 
99
 
    Function-style interface for convenience of old callers.
100
 
 
101
 
    New code should use the Commit class instead.
102
 
    """
103
 
    ## XXX: Remove this in favor of WorkingTree.commit?
104
 
    Commit().commit(*args, **kwargs)
105
 
 
106
 
 
107
92
class NullCommitReporter(object):
108
93
    """I report on progress of a commit."""
109
94
 
223
208
        mutter('preparing to commit')
224
209
 
225
210
        if deprecated_passed(branch):
226
 
            warnings.warn("Commit.commit (branch, ...): The branch parameter is "
 
211
            symbol_versioning.warn("Commit.commit (branch, ...): The branch parameter is "
227
212
                 "deprecated as of bzr 0.8. Please use working_tree= instead.",
228
213
                 DeprecationWarning, stacklevel=2)
229
214
            self.branch = branch
260
245
            self._check_bound_branch()
261
246
 
262
247
            # check for out of date working trees
263
 
            # if we are bound, then self.branch is the master branch and this
264
 
            # test is thus all we need.
265
 
            if self.work_tree.last_revision() != self.master_branch.last_revision():
 
248
            try:
 
249
                first_tree_parent = self.work_tree.get_parent_ids()[0]
 
250
            except IndexError:
 
251
                # if there are no parents, treat our parent as 'None'
 
252
                # this is so that we still consier the master branch
 
253
                # - in a checkout scenario the tree may have no
 
254
                # parents but the branch may do.
 
255
                first_tree_parent = None
 
256
            master_last = self.master_branch.last_revision()
 
257
            if (master_last is not None and
 
258
                master_last != first_tree_parent):
266
259
                raise errors.OutOfDateTree(self.work_tree)
267
260
    
268
261
            if strict:
294
287
            if len(self.parents) > 1 and self.specific_files:
295
288
                raise NotImplementedError('selected-file commit of merges is not supported yet: files %r',
296
289
                        self.specific_files)
297
 
            self._check_parents_present()
 
290
            
298
291
            self.builder = self.branch.get_commit_builder(self.parents, 
299
292
                self.config, timestamp, timezone, committer, revprops, rev_id)
300
293
            
308
301
                raise PointlessCommit()
309
302
 
310
303
            self._emit_progress_update()
311
 
            # TODO: Now the new inventory is known, check for conflicts and prompt the 
312
 
            # user for a commit message.
 
304
            # TODO: Now the new inventory is known, check for conflicts and
 
305
            # prompt the user for a commit message.
 
306
            # ADHB 2006-08-08: If this is done, populate_new_inv should not add
 
307
            # weave lines, because nothing should be recorded until it is known
 
308
            # that commit will succeed.
313
309
            self.builder.finish_inventory()
314
310
            self._emit_progress_update()
315
311
            self.rev_id = self.builder.commit(self.message)
329
325
            # and now do the commit locally.
330
326
            self.branch.append_revision(self.rev_id)
331
327
 
332
 
            self.work_tree.set_pending_merges([])
333
 
            self.work_tree.set_last_revision(self.rev_id)
 
328
            # if the builder gave us the revisiontree it created back, we
 
329
            # could use it straight away here.
 
330
            # TODO: implement this.
 
331
            self.work_tree.set_parent_trees([(self.rev_id,
 
332
                self.branch.repository.revision_tree(self.rev_id))])
334
333
            # now the work tree is up to date with the branch
335
334
            
336
335
            self.reporter.completed(self.branch.revno(), self.rev_id)
450
449
        self.parent_invs = []
451
450
        for revision in self.parents:
452
451
            if self.branch.repository.has_revision(revision):
 
452
                mutter('commit parent revision {%s}', revision)
453
453
                inventory = self.branch.repository.get_inventory(revision)
454
454
                self.parent_invs.append(inventory)
 
455
            else:
 
456
                mutter('commit parent ghost revision {%s}', revision)
455
457
 
456
 
    def _check_parents_present(self):
457
 
        for parent_id in self.parents:
458
 
            mutter('commit parent revision {%s}', parent_id)
459
 
            if not self.branch.repository.has_revision(parent_id):
460
 
                if parent_id == self.branch.last_revision():
461
 
                    warning("parent is missing %r", parent_id)
462
 
                    raise BzrCheckError("branch %s is missing revision {%s}"
463
 
                            % (self.branch, parent_id))
464
 
            
465
458
    def _remove_deleted(self):
466
459
        """Remove deleted files from the working inventories.
467
460
 
475
468
        """
476
469
        specific = self.specific_files
477
470
        deleted_ids = []
 
471
        deleted_paths = set()
478
472
        for path, ie in self.work_inv.iter_entries():
 
473
            if is_inside_any(deleted_paths, path):
 
474
                # The tree will delete the required ids recursively.
 
475
                continue
479
476
            if specific and not is_inside_any(specific, path):
480
477
                continue
481
478
            if not self.work_tree.has_filename(path):
 
479
                deleted_paths.add(path)
482
480
                self.reporter.missing(path)
483
 
                deleted_ids.append((path, ie.file_id))
484
 
        if deleted_ids:
485
 
            deleted_ids.sort(reverse=True)
486
 
            for path, file_id in deleted_ids:
487
 
                del self.work_inv[file_id]
488
 
            self.work_tree._write_inventory(self.work_inv)
 
481
                deleted_ids.append(ie.file_id)
 
482
        self.work_tree.unversion(deleted_ids)
489
483
 
490
484
    def _populate_new_inv(self):
491
485
        """Build revision inventory.
502
496
        # in bugs like #46635.  Any reason not to use/enhance Tree.changes_from?
503
497
        # ADHB 11-07-2006
504
498
        mutter("Selecting files for commit with filter %s", self.specific_files)
505
 
        # at this point we dont copy the root entry:
506
499
        entries = self.work_inv.iter_entries()
507
 
        entries.next()
508
 
        self._emit_progress_update()
 
500
        if not self.builder.record_root_entry:
 
501
            symbol_versioning.warn('CommitBuilders should support recording'
 
502
                ' the root entry as of bzr 0.10.', DeprecationWarning, 
 
503
                stacklevel=1)
 
504
            self.builder.new_inventory.add(self.basis_inv.root.copy())
 
505
            entries.next()
 
506
            self._emit_progress_update()
509
507
        for path, new_ie in entries:
510
508
            self._emit_progress_update()
511
509
            file_id = new_ie.file_id