Skip to content

Commit

Permalink
setup_git_env: use git_pathdup instead of xmalloc + sprintf
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jun 19, 2014
1 parent b2724c8 commit a0279e1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,11 @@ static void setup_git_env(void)
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);
}
if (!git_object_dir)
git_object_dir = git_pathdup("objects");
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);
}
if (!git_index_file)
git_index_file = git_pathdup("index");
git_graft_file = getenv(GRAFT_ENVIRONMENT);
if (!git_graft_file)
git_graft_file = git_pathdup("info/grafts");
Expand Down

0 comments on commit a0279e1

Please sign in to comment.