From 4f4322be5574dcbb4f9e975b35300b34dd232368 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 29 Aug 2010 14:53:57 -0400 Subject: [PATCH] Added support for arbitrary pre and post hooks for all defined mr commands. For example, pre_commit is run before all commits; post_update is run after all updates. Closes: #481341 --- debian/changelog | 3 +++ mr | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 52249ed..d6dffc7 100644 --- a/debian/changelog +++ b/debian/changelog @@ -3,6 +3,9 @@ mr (0.50) UNRELEASED; urgency=low * Now supports the Fossil VCS. (Thanks, Jimmy Tang) * Added fixups hook, which can be used to run a command after a repository is checked out or updated. Closes: #590868 + * Added support for arbitrary pre and post hooks for all defined mr + commands. For example, pre_commit is run before all commits; post_update + is run after all updates. Closes: #481341 -- Joey Hess Sun, 15 Aug 2010 12:36:34 -0400 diff --git a/mr b/mr index 03cfdf3..e73f3c8 100755 --- a/mr +++ b/mr @@ -377,6 +377,13 @@ is checked out, or updated. This provides an easy way to do things like permissions fixups, or other tweaks to the repository content, whenever the repository is changed. +=item pre_ and post_ + +If a "pre_action" parameter is set, its command is run before mr performs the +specified action. Similarly, "post_action" parameters are run after mr +successfully performs the specified action. For example, "pre_commit" is +run before committing; "post_update" is run after updating. + =back When looking for a command to run for a given action, mr first looks for @@ -604,6 +611,10 @@ sub action { $s=~s/^\Q$topdir$subdir\E\/?//; print "mr $action: $topdir$subdir (in subdir $s)\n" unless $quiet; } + + my $hookret=hook("pre_$action", $topdir, $subdir); + return $hookret if $hookret != OK; + $command="set -e; ".$lib. "my_action(){ $command\n }; my_action ". join(" ", map { s/\//\/\//g; s/"/\"/g; '"'.$_.'"' } @ARGV); @@ -641,11 +652,14 @@ sub action { return FAILED; } + my $ret=hook("post_$action", $topdir, $subdir); + return $ret if $ret != OK; + if (($is_checkout || $is_update)) { my $ret=hook("fixups", $topdir, $subdir); return $ret if $ret != OK; } - + return OK; } } -- 2.39.2