* Return the hook config map for `r`, populating it first if needed. * * Out-of-repo calls (r->gitdir == NULL) allocate and return a temporary * cache map; the caller is responsible for freeing it with * hook_cache_clear() + free(). */
| 451 | * hook_cache_clear() + free(). |
| 452 | */ |
| 453 | static struct strmap *get_hook_config_cache(struct repository *r) |
| 454 | { |
| 455 | struct strmap *cache = NULL; |
| 456 | |
| 457 | if (r && r->gitdir) { |
| 458 | /* |
| 459 | * For in-repo calls, the map is stored in r->hook_config_cache, |
| 460 | * so repeated invocations don't parse the configs, so allocate |
| 461 | * it just once on the first call. |
| 462 | */ |
| 463 | if (!r->hook_config_cache) { |
| 464 | CALLOC_ARRAY(r->hook_config_cache, 1); |
| 465 | strmap_init(r->hook_config_cache); |
| 466 | build_hook_config_map(r, r->hook_config_cache); |
| 467 | } |
| 468 | cache = r->hook_config_cache; |
| 469 | } else { |
| 470 | /* |
| 471 | * Out-of-repo calls (no gitdir) allocate and return a temporary |
| 472 | * cache which gets freed immediately by the caller. |
| 473 | */ |
| 474 | CALLOC_ARRAY(cache, 1); |
| 475 | strmap_init(cache); |
| 476 | build_hook_config_map(r, cache); |
| 477 | } |
| 478 | |
| 479 | return cache; |
| 480 | } |
| 481 | |
| 482 | static void list_hooks_add_configured(struct repository *r, |
| 483 | const char *hookname, |
no test coverage detected