#include "gettext.h"
#include "hook.h"
#include "parse-options.h"
-#include "strvec.h"
-#include "abspath.h"
#define BUILTIN_HOOK_RUN_USAGE \
N_("git hook run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]")
* arguments later they probably should be caught by parse_options.
*/
if (argc != 1)
- usage_msg_opt(_("You must specify a hook event name to list."),
+ usage_msg_opt(_("you must specify a hook event name to list"),
builtin_hook_list_usage, list_options);
hookname = argv[0];
head = list_hooks(repo, hookname, NULL);
if (!head->nr) {
- warning(_("No hooks found for event '%s'"), hookname);
+ warning(_("no hooks found for event '%s'"), hookname);
ret = 1; /* no hooks found */
goto cleanup;
}
#include "builtin.h"
#include "abspath.h"
-
+#include "commit.h"
+#include "commit-reach.h"
#include "config.h"
+#include "connect.h"
+#include "connected.h"
#include "environment.h"
+#include "exec-cmd.h"
+#include "fsck.h"
#include "gettext.h"
+#include "gpg-interface.h"
#include "hex.h"
-#include "lockfile.h"
-#include "pack.h"
-#include "refs.h"
-#include "pkt-line.h"
-#include "sideband.h"
-#include "run-command.h"
#include "hook.h"
-#include "exec-cmd.h"
-#include "commit.h"
+#include "lockfile.h"
#include "object.h"
-#include "remote.h"
-#include "connect.h"
-#include "string-list.h"
-#include "oid-array.h"
-#include "connected.h"
-#include "strvec.h"
-#include "version.h"
-#include "gpg-interface.h"
-#include "sigchain.h"
-#include "fsck.h"
-#include "tmp-objdir.h"
-#include "oidset.h"
-#include "packfile.h"
#include "object-file.h"
#include "object-name.h"
#include "odb.h"
+#include "oid-array.h"
+#include "oidset.h"
+#include "pack.h"
+#include "packfile.h"
+#include "parse-options.h"
+#include "pkt-line.h"
#include "protocol.h"
-#include "commit-reach.h"
+#include "refs.h"
+#include "remote.h"
+#include "run-command.h"
#include "server-info.h"
+#include "setup.h"
+#include "shallow.h"
+#include "sideband.h"
+#include "sigchain.h"
+#include "string-list.h"
+#include "strvec.h"
+#include "tmp-objdir.h"
#include "trace.h"
#include "trace2.h"
+#include "version.h"
#include "worktree.h"
-#include "shallow.h"
-#include "setup.h"
-#include "parse-options.h"
static const char * const receive_pack_usage[] = {
N_("git receive-pack <git-dir>"),
static void *receive_hook_feed_state_alloc(void *feed_pipe_ctx)
{
struct receive_hook_feed_state *init_state = feed_pipe_ctx;
- struct receive_hook_feed_state *data = xcalloc(1, sizeof(*data));
+ struct receive_hook_feed_state *data;
+
+ CALLOC_ARRAY(data, 1);
data->report = init_state->report;
data->cmd = init_state->cmd;
data->skip_broken = init_state->skip_broken;
strbuf_init(&data->buf, 0);
+
return data;
}
{
struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT;
struct command *iter = commands;
- struct receive_hook_feed_state feed_init_state = { 0 };
+ struct receive_hook_feed_state feed_init_state = {
+ .cmd = commands,
+ .skip_broken = skip_broken,
+ .buf = STRBUF_INIT,
+ };
struct async sideband_async;
int sideband_async_started = 0;
int saved_stderr = -1;
prepare_sideband_async(&sideband_async, &saved_stderr, &sideband_async_started);
/* set up stdin callback */
- feed_init_state.cmd = commands;
- feed_init_state.skip_broken = skip_broken;
- strbuf_init(&feed_init_state.buf, 0);
opt.feed_pipe_ctx = &feed_init_state;
opt.feed_pipe = feed_receive_hook_cb;
opt.feed_pipe_cb_data_alloc = receive_hook_feed_state_alloc;
#include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
+#include "config.h"
+#include "environment.h"
#include "gettext.h"
#include "hook.h"
-#include "path.h"
#include "parse.h"
+#include "path.h"
#include "run-command.h"
-#include "config.h"
+#include "setup.h"
#include "strbuf.h"
#include "strmap.h"
-#include "environment.h"
-#include "setup.h"
const char *find_hook(struct repository *r, const char *name)
{
if (!h)
return;
- if (h->kind == HOOK_TRADITIONAL)
+ if (h->kind == HOOK_TRADITIONAL) {
free((void *)h->u.traditional.path);
- else if (h->kind == HOOK_CONFIGURED) {
+ } else if (h->kind == HOOK_CONFIGURED) {
free((void *)h->u.configured.friendly_name);
free((void *)h->u.configured.command);
}
if (!hook_path)
return;
- h = xcalloc(1, sizeof(struct hook));
+ CALLOC_ARRAY(h, 1);
/*
* If the hook is to run in a specific dir, a relative path can
strmap_get(&data->event_hooks, value);
if (!hooks) {
- hooks = xcalloc(1, sizeof(*hooks));
+ CALLOC_ARRAY(hooks, 1);
string_list_init_dup(hooks);
strmap_put(&data->event_hooks, value, hooks);
}
/* Construct the cache from parsed configs. */
strmap_for_each_entry(&cb_data.event_hooks, &iter, e) {
struct string_list *hook_names = e->value;
- struct string_list *hooks = xcalloc(1, sizeof(*hooks));
+ struct string_list *hooks;
+ CALLOC_ARRAY(hooks, 1);
string_list_init_dup(hooks);
for (size_t i = 0; i < hook_names->nr; i++) {
* it just once on the first call.
*/
if (!r->hook_config_cache) {
- r->hook_config_cache = xcalloc(1, sizeof(*cache));
+ CALLOC_ARRAY(r->hook_config_cache, 1);
strmap_init(r->hook_config_cache);
build_hook_config_map(r, r->hook_config_cache);
}
} else {
/*
* Out-of-repo calls (no gitdir) allocate and return a temporary
- * map cache which gets free'd immediately by the caller.
+ * cache which gets freed immediately by the caller.
*/
- cache = xcalloc(1, sizeof(*cache));
+ CALLOC_ARRAY(cache, 1);
strmap_init(cache);
build_hook_config_map(r, cache);
}
for (size_t i = 0; configured_hooks && i < configured_hooks->nr; i++) {
const char *friendly_name = configured_hooks->items[i].string;
const char *command = configured_hooks->items[i].util;
- struct hook *hook = xcalloc(1, sizeof(struct hook));
+ struct hook *hook;
+
+ CALLOC_ARRAY(hook, 1);
if (options && options->feed_pipe_cb_data_alloc)
hook->feed_pipe_cb_data =
if (!hookname)
BUG("null hookname was provided to hook_list()!");
- hook_head = xmalloc(sizeof(struct string_list));
+ CALLOC_ARRAY(hook_head, 1);
string_list_init_dup(hook_head);
/* Add hooks from the config, e.g. hook.myhook.event = pre-commit */
* Ensure cb_data copy and free functions are either provided together,
* or neither one is provided.
*/
- if ((options->feed_pipe_cb_data_alloc && !options->feed_pipe_cb_data_free) ||
- (!options->feed_pipe_cb_data_alloc && options->feed_pipe_cb_data_free))
+ if (!options->feed_pipe_cb_data_alloc != !options->feed_pipe_cb_data_free)
BUG("feed_pipe_cb_data_alloc and feed_pipe_cb_data_free must be set together");
if (options->invoked_hook)
#ifndef HOOK_H
#define HOOK_H
-#include "strvec.h"
#include "run-command.h"
#include "string-list.h"
#include "strmap.h"
+#include "strvec.h"
struct repository;
typedef void (*cb_data_free_fn)(void *data);
typedef void *(*cb_data_alloc_fn)(void *init_ctx);
-struct run_hooks_opt
-{
+struct run_hooks_opt {
/* Environment vars to be set for each hook */
struct strvec env;
static void *transaction_feed_cb_data_alloc(void *feed_pipe_ctx UNUSED)
{
- struct transaction_feed_cb_data *data = xmalloc(sizeof(*data));
+ struct transaction_feed_cb_data *data;
+ CALLOC_ARRAY(data, 1);
strbuf_init(&data->buf, 0);
data->index = 0;
return data;
test_expect_success 'git hook list: nonexistent hook' '
cat >stderr.expect <<-\EOF &&
- warning: No hooks found for event '\''test-hook'\''
+ warning: no hooks found for event '\''test-hook'\''
EOF
test_expect_code 1 git hook list test-hook 2>stderr.actual &&
test_cmp stderr.expect stderr.actual
static void *pre_push_hook_data_alloc(void *feed_pipe_ctx)
{
- struct feed_pre_push_hook_data *data = xmalloc(sizeof(*data));
+ struct feed_pre_push_hook_data *data;
+ CALLOC_ARRAY(data, 1);
strbuf_init(&data->buf, 0);
data->refs = (struct ref *)feed_pipe_ctx;
return data;