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>
This commit is contained in:
32
setup.c
32
setup.c
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user