/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

  • Committer: Jelmer Vernooij
  • Date: 2007-09-16 19:29:00 UTC
  • mfrom: (2823 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2824.
  • Revision ID: jelmer@samba.org-20070916192900-fph1i2wsytberyyl
Merge bzr.dev.

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
80
80
        deprecated_function,
81
81
        DEPRECATED_PARAMETER)
82
82
from bzrlib.workingtree import WorkingTree
 
83
from bzrlib.urlutils import unescape_for_display
83
84
import bzrlib.ui
84
85
 
85
86
 
86
87
class NullCommitReporter(object):
87
88
    """I report on progress of a commit."""
88
89
 
 
90
    def started(self, revno, revid, location=None):
 
91
        pass
 
92
 
89
93
    def snapshot_change(self, change, path):
90
94
        pass
91
95
 
104
108
    def renamed(self, change, old_path, new_path):
105
109
        pass
106
110
 
 
111
    def is_verbose(self):
 
112
        return False
 
113
 
107
114
 
108
115
class ReportCommitToLog(NullCommitReporter):
109
116
 
121
128
            return
122
129
        self._note("%s %s", change, path)
123
130
 
 
131
    def started(self, revno, rev_id, location=None):
 
132
        if location is not None:
 
133
            location = ' to "' + unescape_for_display(location, 'utf-8') + '"'
 
134
        else:
 
135
            location = ''
 
136
        self._note('Committing revision %d%s.', revno, location)
 
137
 
124
138
    def completed(self, revno, rev_id):
125
139
        self._note('Committed revision %d.', revno)
126
 
    
 
140
 
127
141
    def deleted(self, file_id):
128
142
        self._note('deleted %s', file_id)
129
143
 
136
150
    def renamed(self, change, old_path, new_path):
137
151
        self._note('%s %s => %s', change, old_path, new_path)
138
152
 
 
153
    def is_verbose(self):
 
154
        return True
 
155
 
139
156
 
140
157
class Commit(object):
141
158
    """Task of committing a new revision.
152
169
    def __init__(self,
153
170
                 reporter=None,
154
171
                 config=None):
155
 
        if reporter is not None:
156
 
            self.reporter = reporter
157
 
        else:
158
 
            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
159
177
        self.config = config
160
 
        
 
178
 
161
179
    def commit(self,
162
180
               message=None,
163
181
               timestamp=None,
198
216
 
199
217
        :param revprops: Properties for new revision
200
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
201
221
        :param recursive: If set to 'down', commit in any subtrees that have
202
222
            pending changes of any sort during this commit.
203
223
        """
236
256
        self.strict = strict
237
257
        self.verbose = verbose
238
258
 
239
 
        if reporter is None and self.reporter is None:
240
 
            self.reporter = NullCommitReporter()
241
 
        elif reporter is not None:
242
 
            self.reporter = reporter
243
 
 
244
259
        self.work_tree.lock_write()
245
260
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
246
261
        self.basis_tree = self.work_tree.basis_tree()
256
271
            # Check that the working tree is up to date
257
272
            old_revno, new_revno = self._check_out_of_date_tree()
258
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()
259
279
            if self.config is None:
260
280
                self.config = self.branch.get_config()
261
281
 
290
310
            self._gather_parents()
291
311
            if len(self.parents) > 1 and self.specific_files:
292
312
                raise errors.CannotCommitSelectedFileMerge(self.specific_files)
293
 
            
 
313
 
294
314
            # Collect the changes
295
315
            self._set_progress_stage("Collecting changes",
296
316
                    entries_title="Directory")
298
318
                self.config, timestamp, timezone, committer, revprops, rev_id)
299
319
            
300
320
            try:
 
321
                # find the location being committed to
 
322
                if self.bound_branch:
 
323
                    master_location = self.master_branch.base
 
324
                else:
 
325
                    master_location = self.branch.base
 
326
 
 
327
                # report the start of the commit
 
328
                self.reporter.started(new_revno, self.rev_id, master_location)
 
329
 
301
330
                self._update_builder_with_changes()
302
331
                self._check_pointless()
303
332
 
348
377
            self._cleanup()
349
378
        return self.rev_id
350
379
 
 
380
    def _select_reporter(self):
 
381
        """Select the CommitReporter to use."""
 
382
        if is_quiet():
 
383
            return NullCommitReporter()
 
384
        return ReportCommitToLog()
 
385
 
351
386
    def _any_real_changes(self):
352
387
        """Are there real changes between new_inventory and basis?
353
388
 
646
681
                self.builder.record_entry_contents(ie, self.parent_invs, path,
647
682
                                                   self.basis_tree)
648
683
 
649
 
        # Report what was deleted. We could skip this when no deletes are
650
 
        # detected to gain a performance win, but it arguably serves as a
651
 
        # 'safety check' by informing the user whenever anything disappears.
652
 
        for path, ie in self.basis_inv.iter_entries():
653
 
            if ie.file_id not in self.builder.new_inventory:
654
 
                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)
655
689
 
656
690
    def _populate_from_inventory(self, specific_files):
657
691
        """Populate the CommitBuilder by walking the working tree inventory."""
660
694
            for unknown in self.work_tree.unknowns():
661
695
                raise StrictCommitFailed()
662
696
               
 
697
        report_changes = self.reporter.is_verbose()
663
698
        deleted_ids = []
664
699
        deleted_paths = set()
665
700
        work_inv = self.work_tree.inventory
702
737
            # without it thanks to a unicode normalisation issue. :-(
703
738
            definitely_changed = kind != existing_ie.kind 
704
739
            self._record_entry(path, file_id, specific_files, kind, name,
705
 
                parent_id, definitely_changed, existing_ie)
 
740
                parent_id, definitely_changed, existing_ie, report_changes)
706
741
 
707
742
        # Unversion IDs that were found to be deleted
708
743
        self.work_tree.unversion(deleted_ids)
733
768
            pass
734
769
 
735
770
    def _record_entry(self, path, file_id, specific_files, kind, name,
736
 
                      parent_id, definitely_changed, existing_ie=None):
 
771
            parent_id, definitely_changed, existing_ie=None,
 
772
            report_changes=True):
737
773
        "Record the new inventory entry for a path if any."
738
774
        # mutter('check %s {%s}', path, file_id)
739
775
        if (not specific_files or 
754
790
        if ie is not None:
755
791
            self.builder.record_entry_contents(ie, self.parent_invs, 
756
792
                path, self.work_tree)
757
 
            self._report_change(ie, path)
 
793
            if report_changes:
 
794
                self._report_change(ie, path)
758
795
        return ie
759
796
 
760
797
    def _report_change(self, ie, path):