254
256
self._check_bound_branch()
256
258
# Check that the working tree is up to date
257
old_revno,new_revno = self._check_out_of_date_tree()
259
old_revno, new_revno = self._check_out_of_date_tree()
259
261
if self.config is None:
260
262
self.config = self.branch.get_config()
315
317
# Add revision data to the local branch
316
318
self.rev_id = self.builder.commit(self.message)
320
self._process_pre_hooks(old_revno, new_revno)
318
322
# Upload revision data to the master.
319
323
# this will propagate merged revisions too if needed.
320
324
if self.bound_branch:
335
339
rev_tree = self.builder.revision_tree()
336
340
self.work_tree.set_parent_trees([(self.rev_id, rev_tree)])
337
341
self.reporter.completed(new_revno, self.rev_id)
338
self._process_hooks(old_revno, new_revno)
342
self._process_post_hooks(old_revno, new_revno)
341
345
return self.rev_id
462
466
return old_revno,new_revno
464
def _process_hooks(self, old_revno, new_revno):
465
"""Process any registered commit hooks."""
468
def _process_pre_hooks(self, old_revno, new_revno):
469
"""Process any registered pre commit hooks."""
470
self._set_progress_stage("Running pre commit hooks")
471
self._process_hooks("pre_commit", old_revno, new_revno)
473
def _process_post_hooks(self, old_revno, new_revno):
474
"""Process any registered post commit hooks."""
466
475
# Process the post commit hooks, if any
467
476
self._set_progress_stage("Running post commit hooks")
468
477
# old style commit hooks - should be deprecated ? (obsoleted in
475
484
{'branch':self.branch,
477
486
'rev_id':self.rev_id})
487
# process new style post commit hooks
488
self._process_hooks("post_commit", old_revno, new_revno)
490
def _process_hooks(self, hook_name, old_revno, new_revno):
478
491
# new style commit hooks:
479
492
if not self.bound_branch:
480
493
hook_master = self.branch
489
502
old_revid = self.parents[0]
491
504
old_revid = bzrlib.revision.NULL_REVISION
492
for hook in Branch.hooks['post_commit']:
505
for hook in Branch.hooks[hook_name]:
493
506
# show the running hook in the progress bar. As hooks may
494
507
# end up doing nothing (e.g. because they are not configured by
495
508
# the user) this is still showing progress, not showing overall
496
509
# actions - its up to each plugin to show a UI if it want's to
497
510
# (such as 'Emailing diff to foo@example.com').
498
self.pb_stage_name = "Running post commit hooks [%s]" % \
499
Branch.hooks.get_hook_name(hook)
511
self.pb_stage_name = "Running %s hooks [%s]" % \
512
(hook_name.replace('_', ' '), Branch.hooks.get_hook_name(hook))
500
513
self._emit_progress()
501
514
if 'hooks' in debug.debug_flags:
502
515
mutter("Invoking commit hook: %r", hook)
503
hook(hook_local, hook_master, old_revno, old_revid, new_revno,
516
if hook_name == "post_commit":
517
hook(hook_local, hook_master, old_revno, old_revid, new_revno,
519
elif hook_name == "pre_commit":
520
future_tree = self.builder.revision_tree()
521
added = list(self.added_paths)
523
deleted = list(self.deleted_paths)
525
hook(hook_local, hook_master,
526
old_revno, old_revid, new_revno, self.rev_id,
527
deleted, added, future_tree)
506
529
def _cleanup(self):
507
530
"""Cleanup any open locks, progress bars etc."""
614
637
ie.revision = None
615
638
self.builder.record_entry_contents(ie, self.parent_invs, path,
640
self.added_paths.add(path)
618
642
# Report what was deleted. We could skip this when no deletes are
619
643
# detected to gain a performance win, but it arguably serves as a
621
645
for path, ie in self.basis_inv.iter_entries():
622
646
if ie.file_id not in self.builder.new_inventory:
623
647
self.reporter.deleted(path)
648
self.deleted_paths.add(path)
625
650
def _populate_from_inventory(self, specific_files):
626
651
"""Populate the CommitBuilder by walking the working tree inventory."""
742
767
InventoryEntry.MODIFIED_AND_RENAMED):
743
768
old_path = self.basis_inv.id2path(ie.file_id)
744
769
self.reporter.renamed(change, old_path, path)
770
self.deleted_paths.add(old_path)
771
self.added_paths.add(path)
746
773
self.reporter.snapshot_change(change, path)
774
if change == 'added' and path != '':
775
self.added_paths.add(path)
748
777
def _set_progress_stage(self, name, entries_title=None):
749
778
"""Set the progress stage and emit an update to the progress bar."""