aboutsummaryrefslogtreecommitdiffstats
path: root/setup.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2024-03-29 11:45:01 +0100
committerJohannes Schindelin <johannes.schindelin@gmx.de>2024-04-17 22:30:10 +0200
commitdf93e407f0618e4a8265ac619dc7f4c7005155bc (patch)
tree9df998e25c0a6341e7221677bfebca19463fc870 /setup.c
parent48c171d927407132875283db3afb05b08b98a078 (diff)
downloadgit-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.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/setup.c b/setup.c
index 9d401ae4c8..e6e749ec4b 100644
--- a/setup.c
+++ b/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;
+}