Thread (9 messages) flat view 9 messages, 1 author, 2016-06-15
STALE3720d

Revision v1 of 2 in this series.

Revisions (2)
  1. v1 current
  2. v2 [diff vs current]

[PATCH 2/4] hooks: support variable number of parameters

From: Aaron Schrab <hidden>
Date: 2016-06-15 22:55:36
Subsystem: the rest · Maintainer: Linus Torvalds

Define the run_hook_argv() function to allow hooks to be created where
the number of parameters to be passed is variable.  The existing
run_hook() function uses stdarg to allow it to receive a variable number
of arguments, but the number of arguments that a given caller is passing
is fixed at compile time.  This function will allow the caller of a hook
to determine the number of arguments to pass when preparing to call the
hook.

The first use of this function will be for a pre-push hook which will
add an argument for every reference which is to be pushed.

Signed-off-by: Aaron Schrab <redacted>
---
 run-command.c |   20 +++++++++++++-------
 run-command.h |    2 ++
 2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/run-command.c b/run-command.c
index 49c8fa0..e07202b 100644
--- a/run-command.c
+++ b/run-command.c
@@ -2,7 +2,6 @@
 #include "run-command.h"
 #include "exec_cmd.h"
 #include "sigchain.h"
-#include "argv-array.h"
 
 #ifndef SHELL_PATH
 # define SHELL_PATH "/bin/sh"
@@ -746,10 +745,8 @@ char *find_hook(const char *name)
 
 int run_hook(const char *index_file, const char *name, ...)
 {
-	struct child_process hook;
 	struct argv_array argv = ARGV_ARRAY_INIT;
-	const char *p, *env[2];
-	char index[PATH_MAX];
+	const char *p;
 	va_list args;
 	int ret;
 
@@ -764,6 +761,17 @@ int run_hook(const char *index_file, const char *name, ...)
 		argv_array_push(&argv, p);
 	va_end(args);
 
+	ret = run_hook_argv(index_file, argv);
+	argv_array_clear(&argv);
+	return ret;
+}
+
+int run_hook_argv(const char *index_file, struct argv_array argv)
+{
+	struct child_process hook;
+	char index[PATH_MAX];
+	const char *env[2];
+
 	memset(&hook, 0, sizeof(hook));
 	hook.argv = argv.argv;
 	hook.no_stdin = 1;
@@ -775,7 +783,5 @@ int run_hook(const char *index_file, const char *name, ...)
 		hook.env = env;
 	}
 
-	ret = run_command(&hook);
-	argv_array_clear(&argv);
-	return ret;
+	return run_command(&hook);
 }
diff --git a/run-command.h b/run-command.h
index 221ce33..12faa5b 100644
--- a/run-command.h
+++ b/run-command.h
@@ -1,6 +1,7 @@
 #ifndef RUN_COMMAND_H
 #define RUN_COMMAND_H
 
+#include "argv-array.h"
 #ifndef NO_PTHREADS
 #include <pthread.h>
 #endif
@@ -47,6 +48,7 @@ int run_command(struct child_process *);
 
 extern char *find_hook(const char *name);
 extern int run_hook(const char *index_file, const char *name, ...);
+extern int run_hook_argv(const char *index_file, struct argv_array);
 
 #define RUN_COMMAND_NO_STDIN 1
 #define RUN_GIT_CMD	     2	/*If this is to be git sub-command */
-- 
1.7.10.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help