From 2de9de5e4ae1353f1552f61cf8cf532e3f1dc5f6 Mon Sep 17 00:00:00 2001 From: Steffen Prohaska Date: Sun, 13 Jul 2008 22:31:18 +0200 Subject: Move code interpreting path relative to exec-dir to new function system_path() Expanding system paths relative to git_exec_path can be used for creating an installation that can be moved to a different directory without re-compiling. We use this approach for template_dir and the system wide gitconfig. The Windows installer (msysgit) is an example for such a setup. This commit moves common code to a new function system_path(). System paths that are to be interpreted relative to git_exec_path are passed to system_path() and the return value is used instead of the original path. system_path() prefixes a relative path with git_exec_path and leaves absolute paths unmodified. For example, we now write template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR); [j6t: moved from path.c to exec_cmd.c] Signed-off-by: Steffen Prohaska Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- builtin-init-db.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'builtin-init-db.c') diff --git a/builtin-init-db.c b/builtin-init-db.c index e23b8438c7..5ba213a595 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -115,18 +115,8 @@ static void copy_templates(const char *template_dir) if (!template_dir) template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT); - if (!template_dir) { - /* - * if the hard-coded template is relative, it is - * interpreted relative to the exec_dir - */ - template_dir = DEFAULT_GIT_TEMPLATE_DIR; - if (!is_absolute_path(template_dir)) { - struct strbuf d = STRBUF_INIT; - strbuf_addf(&d, "%s/%s", git_exec_path(), template_dir); - template_dir = strbuf_detach(&d, NULL); - } - } + if (!template_dir) + template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR); strcpy(template_path, template_dir); template_len = strlen(template_path); if (template_path[template_len-1] != '/') { -- cgit v1.2.3