~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: Robert Collins
  • Date: 2007-09-14 02:17:32 UTC
  • mfrom: (2820 +trunk)
  • mto: (2592.3.140 repository)
  • mto: This revision was merged to the branch mainline in revision 2821.
  • Revision ID: robertc@robertcollins.net-20070914021732-q43pb6khebypqnjm
Resolve conflicts in NEWS.

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
                            is_inside_or_parent_of_any,
73
73
                            quotefn, sha_file, split_lines)
74
74
from bzrlib.testament import Testament
75
 
from bzrlib.trace import mutter, note, warning
 
75
from bzrlib.trace import mutter, note, warning, is_quiet
76
76
from bzrlib.xml5 import serializer_v5
77
77
from bzrlib.inventory import Inventory, InventoryEntry
78
78
from bzrlib import symbol_versioning
108
108
    def renamed(self, change, old_path, new_path):
109
109
        pass
110
110
 
 
111
    def is_verbose(self):
 
112
        return False
 
113
 
111
114
 
112
115
class ReportCommitToLog(NullCommitReporter):
113
116
 
134
137
 
135
138
    def completed(self, revno, rev_id):
136
139
        self._note('Committed revision %d.', revno)
137
 
    
 
140
 
138
141
    def deleted(self, file_id):
139
142
        self._note('deleted %s', file_id)
140
143
 
147
150
    def renamed(self, change, old_path, new_path):
148
151
        self._note('%s %s => %s', change, old_path, new_path)
149
152
 
 
153
    def is_verbose(self):
 
154
        return True
 
155
 
150
156
 
151
157
class Commit(object):
152
158
    """Task of committing a new revision.
163
169
    def __init__(self,
164
170
                 reporter=None,
165
171
                 config=None):
166
 
        if reporter is not None:
167
 
            self.reporter = reporter
168
 
        else:
169
 
            self.reporter = NullCommitReporter()
 
172
        """Create a Commit object.
 
173
 
 
174
        :param reporter: the default reporter to use or None to decide later
 
175
        """
 
176
        self.reporter = reporter
170
177
        self.config = config
171
 
        
 
178
 
172
179
    def commit(self,
173
180
               message=None,
174
181
               timestamp=None,
209
216
 
210
217
        :param revprops: Properties for new revision
211
218
        :param local: Perform a local only commit.
 
219
        :param reporter: the reporter to use or None for the default
 
220
        :param verbose: if True and the reporter is not None, report everything
212
221
        :param recursive: If set to 'down', commit in any subtrees that have
213
222
            pending changes of any sort during this commit.
214
223
        """
247
256
        self.strict = strict
248
257
        self.verbose = verbose
249
258
 
250
 
        if reporter is None and self.reporter is None:
251
 
            self.reporter = NullCommitReporter()
252
 
        elif reporter is not None:
253
 
            self.reporter = reporter
254
 
 
255
259
        self.work_tree.lock_write()
256
260
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
257
261
        self.basis_tree = self.work_tree.basis_tree()
267
271
            # Check that the working tree is up to date
268
272
            old_revno, new_revno = self._check_out_of_date_tree()
269
273
 
 
274
            # Complete configuration setup
 
275
            if reporter is not None:
 
276
                self.reporter = reporter
 
277
            elif self.reporter is None:
 
278
                self.reporter = self._select_reporter()
270
279
            if self.config is None:
271
280
                self.config = self.branch.get_config()
272
281
 
368
377
            self._cleanup()
369
378
        return self.rev_id
370
379
 
 
380
    def _select_reporter(self):
 
381
        """Select the CommitReporter to use."""
 
382
        if is_quiet():
 
383
            return NullCommitReporter()
 
384
        return ReportCommitToLog()
 
385
 
371
386
    def _any_real_changes(self):
372
387
        """Are there real changes between new_inventory and basis?
373
388
 
666
681
                self.builder.record_entry_contents(ie, self.parent_invs, path,
667
682
                                                   self.basis_tree)
668
683
 
669
 
        # Report what was deleted. We could skip this when no deletes are
670
 
        # detected to gain a performance win, but it arguably serves as a
671
 
        # 'safety check' by informing the user whenever anything disappears.
672
 
        for path, ie in self.basis_inv.iter_entries():
673
 
            if ie.file_id not in self.builder.new_inventory:
674
 
                self.reporter.deleted(path)
 
684
        # Report what was deleted.
 
685
        if self.reporter.is_verbose():
 
686
            for path, ie in self.basis_inv.iter_entries():
 
687
                if ie.file_id not in self.builder.new_inventory:
 
688
                    self.reporter.deleted(path)
675
689
 
676
690
    def _populate_from_inventory(self, specific_files):
677
691
        """Populate the CommitBuilder by walking the working tree inventory."""
680
694
            for unknown in self.work_tree.unknowns():
681
695
                raise StrictCommitFailed()
682
696
               
 
697
        report_changes = self.reporter.is_verbose()
683
698
        deleted_ids = []
684
699
        deleted_paths = set()
685
700
        work_inv = self.work_tree.inventory
722
737
            # without it thanks to a unicode normalisation issue. :-(
723
738
            definitely_changed = kind != existing_ie.kind 
724
739
            self._record_entry(path, file_id, specific_files, kind, name,
725
 
                parent_id, definitely_changed, existing_ie)
 
740
                parent_id, definitely_changed, existing_ie, report_changes)
726
741
 
727
742
        # Unversion IDs that were found to be deleted
728
743
        self.work_tree.unversion(deleted_ids)
753
768
            pass
754
769
 
755
770
    def _record_entry(self, path, file_id, specific_files, kind, name,
756
 
                      parent_id, definitely_changed, existing_ie=None):
 
771
            parent_id, definitely_changed, existing_ie=None,
 
772
            report_changes=True):
757
773
        "Record the new inventory entry for a path if any."
758
774
        # mutter('check %s {%s}', path, file_id)
759
775
        if (not specific_files or 
774
790
        if ie is not None:
775
791
            self.builder.record_entry_contents(ie, self.parent_invs, 
776
792
                path, self.work_tree)
777
 
            self._report_change(ie, path)
 
793
            if report_changes:
 
794
                self._report_change(ie, path)
778
795
        return ie
779
796
 
780
797
    def _report_change(self, ie, path):