From: Emily Shaffer <emilyshaffer@google.com>
To: git@vger.kernel.org
Cc: Emily Shaffer <emilyshaffer@google.com>
Subject: [PATCH 11/17] transport: convert pre-push hook to use config
Date: Fri, 4 Dec 2020 17:49:39 -0800 [thread overview]
Message-ID: <20201205014945.1502660-12-emilyshaffer@google.com> (raw)
In-Reply-To: <20201205014945.1502660-1-emilyshaffer@google.com>
By using the hook.h:run_hooks API, pre-push hooks can be specified in
the config as well as in the hookdir.
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
Documentation/githooks.txt | 2 ++
transport.c | 55 +++++++++-----------------------------
2 files changed, 14 insertions(+), 43 deletions(-)
diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
index db290984f6..8f5524055b 100644
--- a/Documentation/githooks.txt
+++ b/Documentation/githooks.txt
@@ -271,6 +271,8 @@ If this hook exits with a non-zero status, `git push` will abort without
pushing anything. Information about why the push is rejected may be sent
to the user by writing to standard error.
+Hooks executed during 'pre-push' will run in parallel by default.
+
[[pre-receive]]
pre-receive
~~~~~~~~~~~
diff --git a/transport.c b/transport.c
index 47da955e4f..6c67bc0fea 100644
--- a/transport.c
+++ b/transport.c
@@ -22,6 +22,7 @@
#include "protocol.h"
#include "object-store.h"
#include "color.h"
+#include "hook.h"
static int transport_use_color = -1;
static char transport_colors[][COLOR_MAXLEN] = {
@@ -1162,31 +1163,13 @@ static void die_with_unpushed_submodules(struct string_list *needs_pushing)
static int run_pre_push_hook(struct transport *transport,
struct ref *remote_refs)
{
- int ret = 0, x;
+ int ret = 0;
+ struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_ASYNC;
+ struct strbuf tmp = STRBUF_INIT;
struct ref *r;
- struct child_process proc = CHILD_PROCESS_INIT;
- struct strbuf buf;
- const char *argv[4];
-
- if (!(argv[0] = find_hook("pre-push")))
- return 0;
-
- argv[1] = transport->remote->name;
- argv[2] = transport->url;
- argv[3] = NULL;
-
- proc.argv = argv;
- proc.in = -1;
- proc.trace2_hook_name = "pre-push";
-
- if (start_command(&proc)) {
- finish_command(&proc);
- return -1;
- }
- sigchain_push(SIGPIPE, SIG_IGN);
-
- strbuf_init(&buf, 256);
+ strvec_push(&opt.args, transport->remote->name);
+ strvec_push(&opt.args, transport->url);
for (r = remote_refs; r; r = r->next) {
if (!r->peer_ref) continue;
@@ -1195,30 +1178,16 @@ static int run_pre_push_hook(struct transport *transport,
if (r->status == REF_STATUS_REJECT_REMOTE_UPDATED) continue;
if (r->status == REF_STATUS_UPTODATE) continue;
- strbuf_reset(&buf);
- strbuf_addf( &buf, "%s %s %s %s\n",
+ strbuf_reset(&tmp);
+ strbuf_addf(&tmp, "%s %s %s %s",
r->peer_ref->name, oid_to_hex(&r->new_oid),
r->name, oid_to_hex(&r->old_oid));
-
- if (write_in_full(proc.in, buf.buf, buf.len) < 0) {
- /* We do not mind if a hook does not read all refs. */
- if (errno != EPIPE)
- ret = -1;
- break;
- }
+ string_list_append(&opt.str_stdin, tmp.buf);
}
- strbuf_release(&buf);
-
- x = close(proc.in);
- if (!ret)
- ret = x;
-
- sigchain_pop(SIGPIPE);
-
- x = finish_command(&proc);
- if (!ret)
- ret = x;
+ ret = run_hooks("pre-push", &opt);
+ run_hooks_opt_clear(&opt);
+ strbuf_release(&tmp);
return ret;
}
--
2.28.0.rc0.142.g3c755180ce-goog
next prev parent reply other threads:[~2020-12-05 1:57 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-14 23:25 [PATCH] commit: use config-based hooks (config-based hooks part II) Emily Shaffer
2020-10-16 18:34 ` Junio C Hamano
2020-12-05 1:49 ` [PATCH 00/17] use config-based hooks (config-based hooks part Emily Shaffer
2020-12-05 1:49 ` [PATCH 01/17] commit: use config-based hooks Emily Shaffer
2020-12-05 1:49 ` [PATCH 02/17] am: convert applypatch hooks to use config Emily Shaffer
2020-12-05 1:49 ` [PATCH 03/17] merge: use config-based hooks for post-merge hook Emily Shaffer
2020-12-05 1:49 ` [PATCH 04/17] gc: use hook library for pre-auto-gc hook Emily Shaffer
2020-12-05 1:49 ` [PATCH 05/17] rebase: teach pre-rebase to use hook.h Emily Shaffer
2020-12-05 1:49 ` [PATCH 06/17] read-cache: convert post-index-change hook to use config Emily Shaffer
2020-12-05 1:49 ` [PATCH 07/17] receive-pack: convert push-to-checkout hook to hook.h Emily Shaffer
2020-12-05 1:49 ` [PATCH 08/17] git-p4: use 'git hook' to run hooks Emily Shaffer
2020-12-16 0:27 ` Josh Steadmon
2020-12-16 20:19 ` Emily Shaffer
2020-12-05 1:49 ` [PATCH 09/17] hooks: convert 'post-checkout' hook to hook library Emily Shaffer
2020-12-05 1:49 ` [PATCH 10/17] hook: convert 'post-rewrite' hook to config Emily Shaffer
2020-12-08 23:02 ` Josh Steadmon
2020-12-15 23:42 ` Emily Shaffer
2020-12-05 1:49 ` Emily Shaffer [this message]
2020-12-05 1:49 ` [PATCH 12/17] reference-transaction: look for hooks in config Emily Shaffer
2020-12-05 1:49 ` [PATCH 13/17] receive-pack: convert 'update' hook to hook.h Emily Shaffer
2020-12-05 1:49 ` [PATCH 14/17] proc-receive: acquire hook list from hook.h Emily Shaffer
2020-12-05 1:49 ` [PATCH 15/17] post-update: use hook.h library Emily Shaffer
2020-12-05 1:49 ` [PATCH 16/17] receive-pack: convert receive hooks to hook.h Emily Shaffer
2020-12-05 1:49 ` [PATCH 17/17] run-command: stop thinking about hooks Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 00/17] use config-based hooks (config-based hooks part II) Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 01/17] commit: use config-based hooks Emily Shaffer
2021-02-01 22:08 ` Junio C Hamano
2021-03-10 19:51 ` Emily Shaffer
2021-03-10 22:36 ` Junio C Hamano
2021-02-01 23:02 ` Junio C Hamano
2021-03-10 19:39 ` Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 02/17] am: convert applypatch hooks to use config Emily Shaffer
2021-02-01 22:05 ` Junio C Hamano
2020-12-22 0:04 ` [PATCH v3 03/17] merge: use config-based hooks for post-merge hook Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 04/17] gc: use hook library for pre-auto-gc hook Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 05/17] rebase: teach pre-rebase to use hook.h Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 06/17] read-cache: convert post-index-change hook to use config Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 07/17] receive-pack: convert push-to-checkout hook to hook.h Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 08/17] git-p4: use 'git hook' to run hooks Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 09/17] hooks: convert 'post-checkout' hook to hook library Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 10/17] hook: convert 'post-rewrite' hook to config Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 11/17] transport: convert pre-push hook to use config Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 12/17] reference-transaction: look for hooks in config Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 13/17] receive-pack: convert 'update' hook to hook.h Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 14/17] proc-receive: acquire hook list from hook.h Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 15/17] post-update: use hook.h library Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 16/17] receive-pack: convert receive hooks to hook.h Emily Shaffer
2020-12-22 0:04 ` [PATCH v3 17/17] run-command: stop thinking about hooks Emily Shaffer
2020-12-28 19:59 ` [PATCH v3 00/17] use config-based hooks (config-based hooks part II) Emily Shaffer
2020-12-28 22:40 ` [PATCH v3 18/17] doc: make git-hook.txt point of truth Emily Shaffer
2020-12-28 23:15 ` Emily Shaffer
2021-02-18 22:32 ` [PATCH v3 00/17] use config-based hooks (config-based hooks part II) Josh Steadmon
2020-12-16 0:31 ` [PATCH] commit: " Josh Steadmon
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201205014945.1502660-12-emilyshaffer@google.com \
--to=emilyshaffer@google.com \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).