Skip to content

Commit a0279e1

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b2724c8 commit a0279e1

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

environment.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,11 @@ static void setup_git_env(void)
135135
gitfile = read_gitfile(git_dir);
136136
git_dir = xstrdup(gitfile ? gitfile : git_dir);
137137
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");
142140
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");
147143
git_graft_file = getenv(GRAFT_ENVIRONMENT);
148144
if (!git_graft_file)
149145
git_graft_file = git_pathdup("info/grafts");

0 commit comments

Comments
 (0)