80
80
deprecated_function,
81
81
DEPRECATED_PARAMETER)
82
82
from bzrlib.workingtree import WorkingTree
83
from bzrlib.urlutils import unescape_for_display
86
87
class NullCommitReporter(object):
87
88
"""I report on progress of a commit."""
90
def started(self, revno, revid, location=None):
89
93
def snapshot_change(self, change, path):
122
126
self._note("%s %s", change, path)
128
def started(self, revno, rev_id, location=None):
129
if location is not None:
130
location = ' to "' + unescape_for_display(location, 'utf-8') + '"'
133
self._note('Committing revision %d%s.', revno, location)
124
135
def completed(self, revno, rev_id):
125
136
self._note('Committed revision %d.', revno)
254
265
self._check_bound_branch()
256
267
# Check that the working tree is up to date
257
old_revno,new_revno = self._check_out_of_date_tree()
268
old_revno, new_revno = self._check_out_of_date_tree()
259
270
if self.config is None:
260
271
self.config = self.branch.get_config()
290
301
self._gather_parents()
291
302
if len(self.parents) > 1 and self.specific_files:
292
303
raise errors.CannotCommitSelectedFileMerge(self.specific_files)
294
305
# Collect the changes
295
306
self._set_progress_stage("Collecting changes",
296
307
entries_title="Directory")
297
308
self.builder = self.branch.get_commit_builder(self.parents,
298
309
self.config, timestamp, timezone, committer, revprops, rev_id)
312
# find the location being committed to
313
if self.bound_branch:
314
master_location = self.master_branch.base
316
master_location = self.branch.base
318
# report the start of the commit
319
self.reporter.started(new_revno, self.rev_id, master_location)
300
321
self._update_builder_with_changes()
301
322
self._check_pointless()
316
337
# Add revision data to the local branch
317
338
self.rev_id = self.builder.commit(self.message)
319
341
self.builder.abort()
344
self._process_pre_hooks(old_revno, new_revno)
322
346
# Upload revision data to the master.
323
347
# this will propagate merged revisions too if needed.
324
348
if self.bound_branch:
339
363
rev_tree = self.builder.revision_tree()
340
364
self.work_tree.set_parent_trees([(self.rev_id, rev_tree)])
341
365
self.reporter.completed(new_revno, self.rev_id)
342
self._process_hooks(old_revno, new_revno)
366
self._process_post_hooks(old_revno, new_revno)
345
369
return self.rev_id
466
490
return old_revno,new_revno
468
def _process_hooks(self, old_revno, new_revno):
469
"""Process any registered commit hooks."""
492
def _process_pre_hooks(self, old_revno, new_revno):
493
"""Process any registered pre commit hooks."""
494
self._set_progress_stage("Running pre_commit hooks")
495
self._process_hooks("pre_commit", old_revno, new_revno)
497
def _process_post_hooks(self, old_revno, new_revno):
498
"""Process any registered post commit hooks."""
470
499
# Process the post commit hooks, if any
471
self._set_progress_stage("Running post commit hooks")
500
self._set_progress_stage("Running post_commit hooks")
472
501
# old style commit hooks - should be deprecated ? (obsoleted in
474
503
if self.config.post_commit() is not None:
479
508
{'branch':self.branch,
481
510
'rev_id':self.rev_id})
511
# process new style post commit hooks
512
self._process_hooks("post_commit", old_revno, new_revno)
514
def _process_hooks(self, hook_name, old_revno, new_revno):
515
if not Branch.hooks[hook_name]:
482
518
# new style commit hooks:
483
519
if not self.bound_branch:
484
520
hook_master = self.branch
493
529
old_revid = self.parents[0]
495
531
old_revid = bzrlib.revision.NULL_REVISION
496
for hook in Branch.hooks['post_commit']:
533
if hook_name == "pre_commit":
534
future_tree = self.builder.revision_tree()
535
tree_delta = future_tree.changes_from(self.basis_tree,
538
for hook in Branch.hooks[hook_name]:
497
539
# show the running hook in the progress bar. As hooks may
498
540
# end up doing nothing (e.g. because they are not configured by
499
541
# the user) this is still showing progress, not showing overall
500
542
# actions - its up to each plugin to show a UI if it want's to
501
543
# (such as 'Emailing diff to foo@example.com').
502
self.pb_stage_name = "Running post commit hooks [%s]" % \
503
Branch.hooks.get_hook_name(hook)
544
self.pb_stage_name = "Running %s hooks [%s]" % \
545
(hook_name, Branch.hooks.get_hook_name(hook))
504
546
self._emit_progress()
505
547
if 'hooks' in debug.debug_flags:
506
548
mutter("Invoking commit hook: %r", hook)
507
hook(hook_local, hook_master, old_revno, old_revid, new_revno,
549
if hook_name == "post_commit":
550
hook(hook_local, hook_master, old_revno, old_revid, new_revno,
552
elif hook_name == "pre_commit":
553
hook(hook_local, hook_master,
554
old_revno, old_revid, new_revno, self.rev_id,
555
tree_delta, future_tree)
510
557
def _cleanup(self):
511
558
"""Cleanup any open locks, progress bars etc."""