diff options
author | Johannes Schindelin <johannes.schindelin@gmx.de> | 2024-03-29 11:45:01 +0100 |
---|---|---|
committer | Johannes Schindelin <johannes.schindelin@gmx.de> | 2024-04-17 22:30:10 +0200 |
commit | df93e407f0618e4a8265ac619dc7f4c7005155bc (patch) | |
tree | 9df998e25c0a6341e7221677bfebca19463fc870 /setup.c | |
parent | 48c171d927407132875283db3afb05b08b98a078 (diff) | |
download | git-df93e407f0618e4a8265ac619dc7f4c7005155bc.tar.gz |
init: refactor the template directory discovery into its own function
We will need to call this function from `hook.c` to be able to prevent
hooks from running that were written as part of a `clone` but did not
originate from the template directory.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'setup.c')
-rw-r--r-- | setup.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -6,6 +6,7 @@ #include "chdir-notify.h" #include "promisor-remote.h" #include "quote.h" +#include "exec-cmd.h" static int inside_git_dir = -1; static int inside_work_tree = -1; @@ -1720,3 +1721,34 @@ int daemonize(void) return 0; #endif } + +#ifndef DEFAULT_GIT_TEMPLATE_DIR +#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates" +#endif + +const char *get_template_dir(const char *option_template) +{ + const char *template_dir = option_template; + + if (!template_dir) + template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT); + if (!template_dir) { + static const char *init_template_dir; + static int initialized; + + if (!initialized) { + git_config_get_pathname("init.templatedir", + &init_template_dir); + initialized = 1; + } + template_dir = init_template_dir; + } + if (!template_dir) { + static char *dir; + + if (!dir) + dir = system_path(DEFAULT_GIT_TEMPLATE_DIR); + template_dir = dir; + } + return template_dir; +} |