diff mbox series

[v3,03/13] rebase: convert pre-rebase to use hook.h

Message ID patch-v3-03.13-cbbfd77a4f6-20211019T231647Z-avarab@gmail.com (mailing list archive)
State Superseded
Headers show
Series hook.[ch]: new library to run hooks + simple hook conversion | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 19, 2021, 11:20 p.m. UTC
From: Emily Shaffer <emilyshaffer@google.com>

Move the pre-rebase hook away from run-command.h to and over to the
new hook.h library.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 builtin/rebase.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Junio C Hamano Oct. 29, 2021, 5:48 a.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> From: Emily Shaffer <emilyshaffer@google.com>
>
> Move the pre-rebase hook away from run-command.h to and over to the
> new hook.h library.
>
> Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  builtin/rebase.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/rebase.c b/builtin/rebase.c
> index 34b4744e5f3..758b5dfabe2 100644
> --- a/builtin/rebase.c
> +++ b/builtin/rebase.c
> @@ -28,6 +28,7 @@
>  #include "sequencer.h"
>  #include "rebase-interactive.h"
>  #include "reset.h"
> +#include "hook.h"
>  
>  #define DEFAULT_REFLOG_ACTION "rebase"
>  
> @@ -1017,6 +1018,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  	int reschedule_failed_exec = -1;
>  	int allow_preemptive_ff = 1;
>  	int preserve_merges_selected = 0;
> +	struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
>  	struct option builtin_rebase_options[] = {
>  		OPT_STRING(0, "onto", &options.onto_name,
>  			   N_("revision"),
> @@ -1711,9 +1713,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
>  	}
>  
>  	/* If a hook exists, give it a chance to interrupt*/
> +	strvec_push(&hook_opt.args, options.upstream_arg);
> +	if (argc)
> +		strvec_push(&hook_opt.args, argv[0]);
>  	if (!ok_to_skip_pre_rebase &&
> -	    run_hook_le(NULL, "pre-rebase", options.upstream_arg,
> -			argc ? argv[0] : NULL, NULL))
> +	    run_hooks_oneshot("pre-rebase", &hook_opt))
>  		die(_("The pre-rebase hook refused to rebase."));
>  
>  	if (options.flags & REBASE_DIFFSTAT) {


OK, so the convention is

 * if there is no extra args the hook takes, you only give hook_name
   and NULL;

 * if there is even one arg the hook takes, you have to prepare the
   opt struct and strvec_push() the arg yourself.

That would work, and it might be merely the matter of taste, but it
would have been nicer if the calling sequence to run_hooks_oneshot()
were more like run_hook_le().

But patches were already written, so let's keep reading.
diff mbox series

Patch

diff --git a/builtin/rebase.c b/builtin/rebase.c
index 34b4744e5f3..758b5dfabe2 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -28,6 +28,7 @@ 
 #include "sequencer.h"
 #include "rebase-interactive.h"
 #include "reset.h"
+#include "hook.h"
 
 #define DEFAULT_REFLOG_ACTION "rebase"
 
@@ -1017,6 +1018,7 @@  int cmd_rebase(int argc, const char **argv, const char *prefix)
 	int reschedule_failed_exec = -1;
 	int allow_preemptive_ff = 1;
 	int preserve_merges_selected = 0;
+	struct run_hooks_opt hook_opt = RUN_HOOKS_OPT_INIT;
 	struct option builtin_rebase_options[] = {
 		OPT_STRING(0, "onto", &options.onto_name,
 			   N_("revision"),
@@ -1711,9 +1713,11 @@  int cmd_rebase(int argc, const char **argv, const char *prefix)
 	}
 
 	/* If a hook exists, give it a chance to interrupt*/
+	strvec_push(&hook_opt.args, options.upstream_arg);
+	if (argc)
+		strvec_push(&hook_opt.args, argv[0]);
 	if (!ok_to_skip_pre_rebase &&
-	    run_hook_le(NULL, "pre-rebase", options.upstream_arg,
-			argc ? argv[0] : NULL, NULL))
+	    run_hooks_oneshot("pre-rebase", &hook_opt))
 		die(_("The pre-rebase hook refused to rebase."));
 
 	if (options.flags & REBASE_DIFFSTAT) {