summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a9a3e82)
raw | patch | inline | side by side (parent: a9a3e82)
author | Steffen Prohaska <prohaska@zib.de> | |
Sun, 13 Jul 2008 20:31:18 +0000 (22:31 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Sun, 13 Jul 2008 21:41:28 +0000 (14:41 -0700) |
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 <prohaska@zib.de>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 <prohaska@zib.de>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-init-db.c | patch | blob | history | |
config.c | patch | blob | history | |
exec_cmd.c | patch | blob | history | |
exec_cmd.h | patch | blob | history |
diff --git a/builtin-init-db.c b/builtin-init-db.c
index e23b8438c741651f48bbf529f89d0336cc718fed..5ba213a595fb9d7de4d36ff5cab888bde2035722 100644 (file)
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
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] != '/') {
diff --git a/config.c b/config.c
index 2862cc45cbb1752153bb6050b4e6bd53f6660724..1e066c71e0fbc4b172ef548663e660e636d6a916 100644 (file)
--- a/config.c
+++ b/config.c
const char *git_etc_gitconfig(void)
{
static const char *system_wide;
- if (!system_wide) {
- system_wide = ETC_GITCONFIG;
- if (!is_absolute_path(system_wide)) {
- /* interpret path relative to exec-dir */
- struct strbuf d = STRBUF_INIT;
- strbuf_addf(&d, "%s/%s", git_exec_path(), system_wide);
- system_wide = strbuf_detach(&d, NULL);
- }
- }
+ if (!system_wide)
+ system_wide = system_path(ETC_GITCONFIG);
return system_wide;
}
diff --git a/exec_cmd.c b/exec_cmd.c
index da04efe951e5b8dc4e7b72246212d8ebabc09ec6..8899e31b3b9edb528a339df394f891f76b8de594 100644 (file)
--- a/exec_cmd.c
+++ b/exec_cmd.c
#endif
}
+const char *system_path(const char *path)
+{
+ if (!is_absolute_path(path)) {
+ struct strbuf d = STRBUF_INIT;
+ strbuf_addf(&d, "%s/%s", git_exec_path(), path);
+ path = strbuf_detach(&d, NULL);
+ }
+ return path;
+}
+
void git_set_argv_exec_path(const char *exec_path)
{
argv_exec_path = exec_path;
diff --git a/exec_cmd.h b/exec_cmd.h
index a892355c8212298130fb3925c6cba352ed6999b6..7eb94e5e11c07dd269cf59fa5c85845c787d86dd 100644 (file)
--- a/exec_cmd.h
+++ b/exec_cmd.h
extern void setup_path(const char *);
extern int execv_git_cmd(const char **argv); /* NULL terminated */
extern int execl_git_cmd(const char *cmd, ...);
-
+extern const char *system_path(const char *path);
#endif /* GIT_EXEC_CMD_H */