1
#include "git-compat-util.h"
2
#include "abspath.h"
3
#include "advice.h"
4
+#include "config.h"
5
+#include "environment.h"
6
#include "gettext.h"
7
#include "hook.h"
6
-#include "path.h"
8
#include "parse.h"
9
+#include "path.h"
10
#include "run-command.h"
9
-#include "config.h"
11
+#include "setup.h"
12
#include "strbuf.h"
13
#include "strmap.h"
12
-#include "environment.h"
13
-#include "setup.h"
14
15
const char *find_hook(struct repository *r, const char *name)
16
{
57
if (!h)
58
return;
59
60
- if (h->kind == HOOK_TRADITIONAL)
60
+ if (h->kind == HOOK_TRADITIONAL) {
61
free((void *)h->u.traditional.path);
62
- else if (h->kind == HOOK_CONFIGURED) {
62
+ } else if (h->kind == HOOK_CONFIGURED) {
63
free((void *)h->u.configured.friendly_name);
64
free((void *)h->u.configured.command);
65
}
91
if (!hook_path)
92
return;
93
94
- h = xcalloc(1, sizeof(struct hook));
94
+ CALLOC_ARRAY(h, 1);
95
96
/*
97
* If the hook is to run in a specific dir, a relative path can
154
strmap_get(&data->event_hooks, value);
155
156
if (!hooks) {
157
- hooks = xcalloc(1, sizeof(*hooks));
157
+ CALLOC_ARRAY(hooks, 1);
158
string_list_init_dup(hooks);
159
strmap_put(&data->event_hooks, value, hooks);
160
}
227
/* Construct the cache from parsed configs. */
228
strmap_for_each_entry(&cb_data.event_hooks, &iter, e) {
229
struct string_list *hook_names = e->value;
230
- struct string_list *hooks = xcalloc(1, sizeof(*hooks));
230
+ struct string_list *hooks;
231
232
+ CALLOC_ARRAY(hooks, 1);
233
string_list_init_dup(hooks);
234
235
for (size_t i = 0; i < hook_names->nr; i++) {
282
* it just once on the first call.
283
*/
284
if (!r->hook_config_cache) {
284
- r->hook_config_cache = xcalloc(1, sizeof(*cache));
285
+ CALLOC_ARRAY(r->hook_config_cache, 1);
286
strmap_init(r->hook_config_cache);
287
build_hook_config_map(r, r->hook_config_cache);
288
}
290
} else {
291
/*
292
* Out-of-repo calls (no gitdir) allocate and return a temporary
292
- * map cache which gets free'd immediately by the caller.
293
+ * cache which gets freed immediately by the caller.
294
*/
294
- cache = xcalloc(1, sizeof(*cache));
295
+ CALLOC_ARRAY(cache, 1);
296
strmap_init(cache);
297
build_hook_config_map(r, cache);
298
}
312
for (size_t i = 0; configured_hooks && i < configured_hooks->nr; i++) {
313
const char *friendly_name = configured_hooks->items[i].string;
314
const char *command = configured_hooks->items[i].util;
314
- struct hook *hook = xcalloc(1, sizeof(struct hook));
315
+ struct hook *hook;
316
+
317
+ CALLOC_ARRAY(hook, 1);
318
319
if (options && options->feed_pipe_cb_data_alloc)
320
hook->feed_pipe_cb_data =
346
if (!hookname)
347
BUG("null hookname was provided to hook_list()!");
348
346
- hook_head = xmalloc(sizeof(struct string_list));
349
+ CALLOC_ARRAY(hook_head, 1);
350
string_list_init_dup(hook_head);
351
352
/* Add hooks from the config, e.g. hook.myhook.event = pre-commit */
496
* Ensure cb_data copy and free functions are either provided together,
497
* or neither one is provided.
498
*/
496
- if ((options->feed_pipe_cb_data_alloc && !options->feed_pipe_cb_data_free) ||
497
- (!options->feed_pipe_cb_data_alloc && options->feed_pipe_cb_data_free))
499
+ if (!options->feed_pipe_cb_data_alloc != !options->feed_pipe_cb_data_free)
500
BUG("feed_pipe_cb_data_alloc and feed_pipe_cb_data_free must be set together");
501
502
if (options->invoked_hook)