/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: Ian Clatworthy
  • Date: 2007-09-04 06:49:51 UTC
  • mto: (2819.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2820.
  • Revision ID: ian.clatworthy@internode.on.net-20070904064951-t4833s0vn5hfq1qu
make change reporting smarter for initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
class NullCommitReporter(object):
87
87
    """I report on progress of a commit."""
88
88
 
89
 
    def snapshot_change(self, change, path):
90
 
        pass
91
 
 
92
 
    def completed(self, revno, rev_id):
93
 
        pass
94
 
 
95
 
    def deleted(self, file_id):
96
 
        pass
97
 
 
98
 
    def escaped(self, escape_count, message):
99
 
        pass
100
 
 
101
 
    def missing(self, path):
102
 
        pass
103
 
 
104
 
    def renamed(self, change, old_path, new_path):
105
 
        pass
106
 
 
107
 
    def is_verbose(self):
108
 
        return False
109
 
 
110
 
class DefaultCommitReporter(NullCommitReporter):
 
89
    def __init__(self, show_change_total=False):
 
90
        self.show_change_total = show_change_total
 
91
        self.changes = 0
111
92
 
112
93
    def _note(self, format, *args):
113
94
        """Output a message.
116
97
        """
117
98
        note(format, *args)
118
99
 
 
100
    def _note_change(self, format, *args):
 
101
        self._note(format, *args)
 
102
        self.changes += 1
 
103
 
 
104
    def snapshot_change(self, change, path):
 
105
        pass
 
106
 
 
107
    def completed(self, revno, rev_id):
 
108
        pass
 
109
 
 
110
    def deleted(self, file_id):
 
111
        pass
 
112
 
 
113
    def escaped(self, escape_count, message):
 
114
        pass
 
115
 
 
116
    def missing(self, path):
 
117
        pass
 
118
 
 
119
    def renamed(self, change, old_path, new_path):
 
120
        pass
 
121
 
 
122
    def is_verbose(self):
 
123
        return False
 
124
 
 
125
 
 
126
class _InitialCommitReporter(NullCommitReporter):
 
127
 
 
128
    def snapshot_change(self, change, path):
 
129
        self._note_change("%s %s", change, path)
 
130
 
119
131
    def completed(self, revno, rev_id):
120
132
        self._note('Committed revision %d.', revno)
121
 
 
122
 
 
123
 
class ReportCommitToLog(DefaultCommitReporter):
 
133
        if self.show_change_total:
 
134
            if self.changes == 1:
 
135
                self._note('%d change committed.', self.changes)
 
136
            else:
 
137
                self._note('%d changes committed.', self.changes)
 
138
 
 
139
 
 
140
class ReportCommitToLog(_InitialCommitReporter):
124
141
 
125
142
    def snapshot_change(self, change, path):
126
143
        if change == 'unchanged':
127
144
            return
128
145
        if change == 'added' and path == '':
129
146
            return
130
 
        self._note("%s %s", change, path)
 
147
        self._note_change("%s %s", change, path)
131
148
 
132
149
    def deleted(self, file_id):
133
 
        self._note('deleted %s', file_id)
 
150
        self._note_change('deleted %s', file_id)
134
151
 
135
152
    def escaped(self, escape_count, message):
136
153
        self._note("replaced %d control characters in message", escape_count)
137
154
 
138
155
    def missing(self, path):
139
 
        self._note('missing %s', path)
 
156
        self._note_change('missing %s', path)
140
157
 
141
158
    def renamed(self, change, old_path, new_path):
142
 
        self._note('%s %s => %s', change, old_path, new_path)
 
159
        self._note_change('%s %s => %s', change, old_path, new_path)
143
160
 
144
161
    def is_verbose(self):
145
162
        return True
146
163
 
147
164
 
 
165
# Provide an alias
 
166
VerboseCommitReporter = ReportCommitToLog
 
167
 
 
168
 
148
169
class Commit(object):
149
170
    """Task of committing a new revision.
150
171
 
247
268
        self.strict = strict
248
269
        self.verbose = verbose
249
270
 
 
271
        self.basis_tree = self.work_tree.basis_tree()
 
272
        self.initial_commit = self.basis_tree is None
250
273
        if reporter is not None:
251
274
            self.reporter = reporter
252
275
        elif self.reporter is None:
253
 
            self.reporter = self._get_default_reporter()
 
276
            self.reporter = self._select_reporter()
254
277
 
 
278
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
255
279
        self.work_tree.lock_write()
256
 
        self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
257
 
        self.basis_tree = self.work_tree.basis_tree()
258
280
        self.basis_tree.lock_read()
259
281
        try:
260
282
            # Cannot commit with conflicts present.
359
381
            self._cleanup()
360
382
        return self.rev_id
361
383
 
 
384
    def _select_reporter(self):
 
385
        """Select the CommitReporter to use."""
 
386
        if is_quiet():
 
387
            return NullCommitReporter()
 
388
 
 
389
        # For the initial commit in a branch which typically adds many files,
 
390
        # the filenames are not printed unless verbose is explicitly asked for.
 
391
        # We show the total number of changes regardless.
 
392
        if self.initial_commit:
 
393
            if self.verbose:
 
394
                return VerboseCommitReporter(True)
 
395
            else:
 
396
                return _InitialCommitReporter(True)
 
397
 
 
398
        # Otherwise, the changes are shown. In verbose mode, the total number
 
399
        # of changes is shown as well.
 
400
        return VerboseCommitReporter(self.verbose)
 
401
 
362
402
    def _any_real_changes(self):
363
403
        """Are there real changes between new_inventory and basis?
364
404
 
394
434
        # No actual changes present
395
435
        return False
396
436
 
397
 
    def _get_default_reporter(self):
398
 
        """Get the default CommitReporter."""
399
 
        if self.verbose:
400
 
            return ReportCommitToLog()
401
 
        elif is_quiet():
402
 
            return NullCommitReporter()
403
 
        else:
404
 
            return DefaultCommitReporter()
405
 
 
406
437
    def _check_pointless(self):
407
438
        if self.allow_pointless:
408
439
            return
775
806
        if ie is not None:
776
807
            self.builder.record_entry_contents(ie, self.parent_invs, 
777
808
                path, self.work_tree)
778
 
            if report_changes:
 
809
 
 
810
            # Special case initial commit for performance and UI reasons
 
811
            if self.initial_commit:
 
812
                self.reporter.snapshot_change('added', path)
 
813
            elif report_changes:
779
814
                self._report_change(ie, path)
780
815
        return ie
781
816