11#include "git-compat-util.h"
22#include "abspath.h"
33#include "advice.h"
4+ #include "config.h"
5+ #include "environment.h"
46#include "gettext.h"
57#include "hook.h"
6- #include "path.h"
78#include "parse.h"
9+ #include "path.h"
810#include "run-command.h"
9- #include "config .h"
11+ #include "setup .h"
1012#include "strbuf.h"
1113#include "strmap.h"
12- #include "environment.h"
13- #include "setup.h"
1414
1515const char * find_hook (struct repository * r , const char * name )
1616{
@@ -57,9 +57,9 @@ static void hook_clear(struct hook *h, cb_data_free_fn cb_data_free)
5757 if (!h )
5858 return ;
5959
60- if (h -> kind == HOOK_TRADITIONAL )
60+ if (h -> kind == HOOK_TRADITIONAL ) {
6161 free ((void * )h -> u .traditional .path );
62- else if (h -> kind == HOOK_CONFIGURED ) {
62+ } else if (h -> kind == HOOK_CONFIGURED ) {
6363 free ((void * )h -> u .configured .friendly_name );
6464 free ((void * )h -> u .configured .command );
6565 }
@@ -91,7 +91,7 @@ static void list_hooks_add_default(struct repository *r, const char *hookname,
9191 if (!hook_path )
9292 return ;
9393
94- h = xcalloc ( 1 , sizeof ( struct hook ) );
94+ CALLOC_ARRAY ( h , 1 );
9595
9696 /*
9797 * If the hook is to run in a specific dir, a relative path can
@@ -154,7 +154,7 @@ static int hook_config_lookup_all(const char *key, const char *value,
154154 strmap_get (& data -> event_hooks , value );
155155
156156 if (!hooks ) {
157- hooks = xcalloc ( 1 , sizeof ( * hooks ) );
157+ CALLOC_ARRAY ( hooks , 1 );
158158 string_list_init_dup (hooks );
159159 strmap_put (& data -> event_hooks , value , hooks );
160160 }
@@ -227,8 +227,9 @@ static void build_hook_config_map(struct repository *r, struct strmap *cache)
227227 /* Construct the cache from parsed configs. */
228228 strmap_for_each_entry (& cb_data .event_hooks , & iter , e ) {
229229 struct string_list * hook_names = e -> value ;
230- struct string_list * hooks = xcalloc ( 1 , sizeof ( * hooks )) ;
230+ struct string_list * hooks ;
231231
232+ CALLOC_ARRAY (hooks , 1 );
232233 string_list_init_dup (hooks );
233234
234235 for (size_t i = 0 ; i < hook_names -> nr ; i ++ ) {
@@ -281,17 +282,17 @@ static struct strmap *get_hook_config_cache(struct repository *r)
281282 * it just once on the first call.
282283 */
283284 if (!r -> hook_config_cache ) {
284- r -> hook_config_cache = xcalloc ( 1 , sizeof ( * cache ) );
285+ CALLOC_ARRAY ( r -> hook_config_cache , 1 );
285286 strmap_init (r -> hook_config_cache );
286287 build_hook_config_map (r , r -> hook_config_cache );
287288 }
288289 cache = r -> hook_config_cache ;
289290 } else {
290291 /*
291292 * 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.
293294 */
294- cache = xcalloc ( 1 , sizeof ( * cache ) );
295+ CALLOC_ARRAY ( cache , 1 );
295296 strmap_init (cache );
296297 build_hook_config_map (r , cache );
297298 }
@@ -311,7 +312,9 @@ static void list_hooks_add_configured(struct repository *r,
311312 for (size_t i = 0 ; configured_hooks && i < configured_hooks -> nr ; i ++ ) {
312313 const char * friendly_name = configured_hooks -> items [i ].string ;
313314 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 );
315318
316319 if (options && options -> feed_pipe_cb_data_alloc )
317320 hook -> feed_pipe_cb_data =
@@ -343,7 +346,7 @@ struct string_list *list_hooks(struct repository *r, const char *hookname,
343346 if (!hookname )
344347 BUG ("null hookname was provided to hook_list()!" );
345348
346- hook_head = xmalloc ( sizeof ( struct string_list ) );
349+ CALLOC_ARRAY ( hook_head , 1 );
347350 string_list_init_dup (hook_head );
348351
349352 /* Add hooks from the config, e.g. hook.myhook.event = pre-commit */
@@ -493,8 +496,7 @@ int run_hooks_opt(struct repository *r, const char *hook_name,
493496 * Ensure cb_data copy and free functions are either provided together,
494497 * or neither one is provided.
495498 */
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 )
498500 BUG ("feed_pipe_cb_data_alloc and feed_pipe_cb_data_free must be set together" );
499501
500502 if (options -> invoked_hook )
0 commit comments