@matheusbsbs / matheus-bagliano / commits / 2de9de5e4a
Fork 0

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 <prohaska@zib.de> Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Steffen Prohaska committed Jul 13, 2008 at 22:31 UTC 2de9de5e4ae1353f1552f61cf8cf532e3f1dc5f6
4 files changed +15 -22
builtin-init-db.c
+2 -12
@@ -115,18 +115,8 @@ static void copy_templates(const char *template_dir)
115
116 if (!template_dir)
117 template_dir = getenv(TEMPLATE_DIR_ENVIRONMENT);
118 - if (!template_dir) {
119 - /*
120 - * if the hard-coded template is relative, it is
121 - * interpreted relative to the exec_dir
122 - */
123 - template_dir = DEFAULT_GIT_TEMPLATE_DIR;
124 - if (!is_absolute_path(template_dir)) {
125 - struct strbuf d = STRBUF_INIT;
126 - strbuf_addf(&d, "%s/%s", git_exec_path(), template_dir);
127 - template_dir = strbuf_detach(&d, NULL);
128 - }
129 - }
118 + if (!template_dir)
119 + template_dir = system_path(DEFAULT_GIT_TEMPLATE_DIR);
120 strcpy(template_path, template_dir);
121 template_len = strlen(template_path);
122 if (template_path[template_len-1] != '/') {
config.c
+2 -9
@@ -581,15 +581,8 @@ int git_config_from_file(config_fn_t fn, const char *filename, void *data)
581 const char *git_etc_gitconfig(void)
582 {
583 static const char *system_wide;
584 - if (!system_wide) {
585 - system_wide = ETC_GITCONFIG;
586 - if (!is_absolute_path(system_wide)) {
587 - /* interpret path relative to exec-dir */
588 - struct strbuf d = STRBUF_INIT;
589 - strbuf_addf(&d, "%s/%s", git_exec_path(), system_wide);
590 - system_wide = strbuf_detach(&d, NULL);
591 - }
592 - }
584 + if (!system_wide)
585 + system_wide = system_path(ETC_GITCONFIG);
586 return system_wide;
587 }
588
exec_cmd.c
+10
@@ -40,6 +40,16 @@ static const char *builtin_exec_path(void)
40 #endif
41 }
42
43 +const char *system_path(const char *path)
44 +{
45 + if (!is_absolute_path(path)) {
46 + struct strbuf d = STRBUF_INIT;
47 + strbuf_addf(&d, "%s/%s", git_exec_path(), path);
48 + path = strbuf_detach(&d, NULL);
49 + }
50 + return path;
51 +}
52 +
53 void git_set_argv_exec_path(const char *exec_path)
54 {
55 argv_exec_path = exec_path;
exec_cmd.h
+1 -1
@@ -6,6 +6,6 @@ extern const char* git_exec_path(void);
6 extern void setup_path(const char *);
7 extern int execv_git_cmd(const char **argv); /* NULL terminated */
8 extern int execl_git_cmd(const char *cmd, ...);
9 -
9 +extern const char *system_path(const char *path);
10
11 #endif /* GIT_EXEC_CMD_H */