diff options
| author | Junio C Hamano <gitster@pobox.com> | 2014-07-09 11:34:05 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2014-07-09 11:34:05 -0700 |
| commit | 3b8e8af187cb86ed030432f1a067121fdd4b1c3b (patch) | |
| tree | dd8cdaa18cfd70d6cfe6b0a3120fccb5f0a971cd /environment.c | |
| parent | e91ae32a01ffe294b8510c1d8cd7138493a0712f (diff) | |
| parent | cb6c38d5cce7d8d48a57346b332a68cea1489df1 (diff) | |
| download | git-3b8e8af187cb86ed030432f1a067121fdd4b1c3b.tar.gz | |
Merge branch 'jk/xstrfmt'
* jk/xstrfmt:
setup_git_env(): introduce git_path_from_env() helper
unique_path: fix unlikely heap overflow
walker_fetch: fix minor memory leak
merge: use argv_array when spawning merge strategy
sequencer: use argv_array_pushf
setup_git_env: use git_pathdup instead of xmalloc + sprintf
use xstrfmt to replace xmalloc + strcpy/strcat
use xstrfmt to replace xmalloc + sprintf
use xstrdup instead of xmalloc + strcpy
use xstrfmt in favor of manual size calculations
strbuf: add xstrfmt helper
Diffstat (limited to 'environment.c')
| -rw-r--r-- | environment.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/environment.c b/environment.c index 4dac5e9edd..565f65293b 100644 --- a/environment.c +++ b/environment.c @@ -124,6 +124,12 @@ static char *expand_namespace(const char *raw_namespace) return strbuf_detach(&buf, NULL); } +static char *git_path_from_env(const char *envvar, const char *path) +{ + const char *value = getenv(envvar); + return value ? xstrdup(value) : git_pathdup("%s", path); +} + static void setup_git_env(void) { const char *gitfile; @@ -134,19 +140,9 @@ static void setup_git_env(void) git_dir = DEFAULT_GIT_DIR_ENVIRONMENT; gitfile = read_gitfile(git_dir); git_dir = xstrdup(gitfile ? gitfile : git_dir); - git_object_dir = getenv(DB_ENVIRONMENT); - if (!git_object_dir) { - git_object_dir = xmalloc(strlen(git_dir) + 9); - sprintf(git_object_dir, "%s/objects", git_dir); - } - git_index_file = getenv(INDEX_ENVIRONMENT); - if (!git_index_file) { - git_index_file = xmalloc(strlen(git_dir) + 7); - sprintf(git_index_file, "%s/index", git_dir); - } - git_graft_file = getenv(GRAFT_ENVIRONMENT); - if (!git_graft_file) - git_graft_file = git_pathdup("info/grafts"); + git_object_dir = git_path_from_env(DB_ENVIRONMENT, "objects"); + git_index_file = git_path_from_env(INDEX_ENVIRONMENT, "index"); + git_graft_file = git_path_from_env(GRAFT_ENVIRONMENT, "info/grafts"); if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) check_replace_refs = 0; namespace = expand_namespace(getenv(GIT_NAMESPACE_ENVIRONMENT)); |
