Allow a relative builtin template directory.
In order to make git relocatable (i.e. not have the prefix compiled-in) the template directory must depend on the location where this git instance is found, which is GIT_EXEC_DIR. The exec path is prepended only if the compiled-in default template directory is to be used and that is relative. Any relative directories that are specified via environment variable or the --exec-dir switch are taken as is. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Nov 13, 2007 at 21:05 UTC
a47d181380e70cba4e6f641e9485d202a0735c5a
1 file changed
+13
-3
builtin-init-db.c
+13
-3
@@ -5,6 +5,7 @@
5
*/
6
#include "cache.h"
7
#include "builtin.h"
8
+#include "exec_cmd.h"
9
10
#ifndef DEFAULT_GIT_TEMPLATE_DIR
11
#define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
@@ -131,10 +132,19 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
132
int template_len;
133
DIR *dir;
134
134
- if (!template_dir) {
135
+ if (!template_dir)
136
template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
136
- if (!template_dir)
137
- template_dir = DEFAULT_GIT_TEMPLATE_DIR;
137
+ if (!template_dir) {
138
+ /*
139
+ * if the hard-coded template is relative, it is
140
+ * interpreted relative to the exec_dir
141
+ */
142
+ template_dir = DEFAULT_GIT_TEMPLATE_DIR;
143
+ if (!is_absolute_path(template_dir)) {
144
+ const char *exec_path = git_exec_path();
145
+ template_dir = prefix_path(exec_path, strlen(exec_path),
146
+ template_dir);
147
+ }
148
}
149
strcpy(template_path, template_dir);
150
template_len = strlen(template_path);