86
86
class NullCommitReporter(object):
87
87
"""I report on progress of a commit."""
89
def snapshot_change(self, change, path):
92
def completed(self, revno, rev_id):
95
def deleted(self, file_id):
98
def escaped(self, escape_count, message):
101
def missing(self, path):
104
def renamed(self, change, old_path, new_path):
107
def is_verbose(self):
110
class DefaultCommitReporter(NullCommitReporter):
89
def __init__(self, show_change_total=False):
90
self.show_change_total = show_change_total
112
93
def _note(self, format, *args):
113
94
"""Output a message.
117
98
note(format, *args)
100
def _note_change(self, format, *args):
101
self._note(format, *args)
104
def snapshot_change(self, change, path):
107
def completed(self, revno, rev_id):
110
def deleted(self, file_id):
113
def escaped(self, escape_count, message):
116
def missing(self, path):
119
def renamed(self, change, old_path, new_path):
122
def is_verbose(self):
126
class _InitialCommitReporter(NullCommitReporter):
128
def snapshot_change(self, change, path):
129
self._note_change("%s %s", change, path)
119
131
def completed(self, revno, rev_id):
120
132
self._note('Committed revision %d.', revno)
123
class ReportCommitToLog(DefaultCommitReporter):
133
if self.show_change_total:
134
if self.changes == 1:
135
self._note('%d change committed.', self.changes)
137
self._note('%d changes committed.', self.changes)
140
class ReportCommitToLog(_InitialCommitReporter):
125
142
def snapshot_change(self, change, path):
126
143
if change == 'unchanged':
128
145
if change == 'added' and path == '':
130
self._note("%s %s", change, path)
147
self._note_change("%s %s", change, path)
132
149
def deleted(self, file_id):
133
self._note('deleted %s', file_id)
150
self._note_change('deleted %s', file_id)
135
152
def escaped(self, escape_count, message):
136
153
self._note("replaced %d control characters in message", escape_count)
138
155
def missing(self, path):
139
self._note('missing %s', path)
156
self._note_change('missing %s', path)
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)
144
161
def is_verbose(self):
166
VerboseCommitReporter = ReportCommitToLog
148
169
class Commit(object):
149
170
"""Task of committing a new revision.
247
268
self.strict = strict
248
269
self.verbose = verbose
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()
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()
260
282
# Cannot commit with conflicts present.
360
382
return self.rev_id
384
def _select_reporter(self):
385
"""Select the CommitReporter to use."""
387
return NullCommitReporter()
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:
394
return VerboseCommitReporter(True)
396
return _InitialCommitReporter(True)
398
# Otherwise, the changes are shown. In verbose mode, the total number
399
# of changes is shown as well.
400
return VerboseCommitReporter(self.verbose)
362
402
def _any_real_changes(self):
363
403
"""Are there real changes between new_inventory and basis?