setup_git_env: use git_pathdup instead of xmalloc + sprintf
This is shorter, harder to get wrong, and more clearly captures the intent. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jun 19, 2014 at 17:28 UTC
a0279e1865c7ce7417c0134e2ab32b20531f502a
1 file changed
+4
-8
environment.c
+4
-8
@@ -135,15 +135,11 @@ static void setup_git_env(void)
135
gitfile = read_gitfile(git_dir);
136
git_dir = xstrdup(gitfile ? gitfile : git_dir);
137
git_object_dir = getenv(DB_ENVIRONMENT);
138
- if (!git_object_dir) {
139
- git_object_dir = xmalloc(strlen(git_dir) + 9);
140
- sprintf(git_object_dir, "%s/objects", git_dir);
141
- }
138
+ if (!git_object_dir)
139
+ git_object_dir = git_pathdup("objects");
140
git_index_file = getenv(INDEX_ENVIRONMENT);
143
- if (!git_index_file) {
144
- git_index_file = xmalloc(strlen(git_dir) + 7);
145
- sprintf(git_index_file, "%s/index", git_dir);
146
- }
141
+ if (!git_index_file)
142
+ git_index_file = git_pathdup("index");
143
git_graft_file = getenv(GRAFT_ENVIRONMENT);
144
if (!git_graft_file)
145
git_graft_file = git_pathdup("info/grafts");