[PATCH 2/3] receive-pack: add a capability for hook options

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow the client to specify options to influence the behaviour of hooks
run by receive-pack. This can be used to e.g. tell hooks to be quiet or
verbose, or to ignore errors.

These options are passed on to the hooks in the environment variable
GIT_HOOK_OPTIONS, which hooks can choose to respect to or ignore. The
default hooks do not respect these options.

Signed-off-by: Dennis Kaarsemaker <git@xxxxxxxxxxxxxxx>
---
 Documentation/technical/protocol-capabilities.txt |  9 +++++++++
 builtin/receive-pack.c                            | 19 +++++++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/Documentation/technical/protocol-capabilities.txt b/Documentation/technical/protocol-capabilities.txt
index eaab6b4..dea47e6 100644
--- a/Documentation/technical/protocol-capabilities.txt
+++ b/Documentation/technical/protocol-capabilities.txt
@@ -275,3 +275,12 @@ to accept a signed push certificate, and asks the <nonce> to be
 included in the push certificate.  A send-pack client MUST NOT
 send a push-cert packet unless the receive-pack server advertises
 this capability.
+
+hook-options
+------------
+
+The receive-pack server that advertises this capability can accept hook
+options in the capabilities sent by the client. The hook options string is
+a string of characters in the set [0-9a-zA-Z,=_] and is made available to
+all hooks executed by the receive pack process as environment variable
+GIT_HOOK_OPTIONS
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index f2d6761..120d9b3 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -73,6 +73,8 @@ static long nonce_stamp_slop;
 static unsigned long nonce_stamp_slop_limit;
 static struct ref_transaction *transaction;
 
+static const char *hook_options;
+
 static enum deny_action parse_deny_action(const char *var, const char *value)
 {
 	if (value) {
@@ -201,7 +203,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
 		struct strbuf cap = STRBUF_INIT;
 
 		strbuf_addstr(&cap,
-			      "report-status delete-refs side-band-64k quiet");
+			      "report-status delete-refs side-band-64k quiet hook-options");
 		if (advertise_atomic_push)
 			strbuf_addstr(&cap, " atomic");
 		if (prefer_ofs_delta)
@@ -561,6 +563,9 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, void *feed_sta
 
 	argv[1] = NULL;
 
+	if (hook_options)
+		argv_array_pushf(&proc.env_array, "GIT_HOOK_OPTIONS=%s", hook_options);
+
 	proc.argv = argv;
 	proc.in = -1;
 	proc.stdout_to_stderr = 1;
@@ -663,6 +668,9 @@ static int run_update_hook(struct command *cmd)
 	argv[3] = sha1_to_hex(cmd->new_sha1);
 	argv[4] = NULL;
 
+	if (hook_options)
+		argv_array_pushf(&proc.env_array, "GIT_HOOK_OPTIONS=%s", hook_options);
+
 	proc.no_stdin = 1;
 	proc.stdout_to_stderr = 1;
 	proc.err = use_sideband ? -1 : 0;
@@ -1055,6 +1063,9 @@ static void run_update_post_hook(struct command *commands)
 	}
 	argv[argc] = NULL;
 
+	if (hook_options)
+		argv_array_pushf(&proc.env_array, "GIT_HOOK_OPTIONS=%s", hook_options);
+
 	proc.no_stdin = 1;
 	proc.stdout_to_stderr = 1;
 	proc.err = use_sideband ? -1 : 0;
@@ -1415,7 +1426,8 @@ static struct command *read_head_info(struct sha1_array *shallow)
 	struct command **p = &commands;
 	for (;;) {
 		char *line;
-		int len, linelen;
+		const char *feature;
+		int len, linelen, featurelen;
 
 		line = packet_read_line(0, &len);
 		if (!line)
@@ -1442,6 +1454,9 @@ static struct command *read_head_info(struct sha1_array *shallow)
 			if (advertise_atomic_push
 			    && parse_feature_request(feature_list, "atomic"))
 				use_atomic = 1;
+			if ((feature =
+				parse_feature_value(feature_list, "hook-options", &featurelen)))
+				hook_options = xmemdupz(feature, featurelen);
 		}
 
 		if (!strcmp(line, "push-cert")) {
-- 
2.7.0-91-gf04ef09

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]