git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dennis Kaarsemaker <dennis@kaarsemaker.net>
To: git@vger.kernel.org
Cc: Dennis Kaarsemaker <dennis@kaarsemaker.net>
Subject: [PATCH 2/3] receive-pack: add a capability for hook options
Date: Sat, 30 Jan 2016 19:28:09 +0100	[thread overview]
Message-ID: <1454178490-17873-3-git-send-email-dennis@kaarsemaker.net> (raw)
In-Reply-To: <1454178490-17873-1-git-send-email-dennis@kaarsemaker.net>

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@vger.kernel.org>
---
 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

  parent reply	other threads:[~2016-01-30 18:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-30 18:28 [PATCH 0/3] Propagating push options to remote hooks Dennis Kaarsemaker
2016-01-30 18:28 ` [PATCH 1/3] connect.[ch]: make parse_feature_value non-static Dennis Kaarsemaker
2016-01-30 18:28 ` Dennis Kaarsemaker [this message]
2016-01-30 18:28 ` [PATCH 3/3] send-pack: propagate --force and --quiet to remote hooks Dennis Kaarsemaker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454178490-17873-3-git-send-email-dennis@kaarsemaker.net \
    --to=dennis@kaarsemaker.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).