Skip to content

Commit 07af889

Browse files
peffgitster
authored andcommitted
gc: replace local buffer with git_path
We probe the "17/" loose object directory for auto-gc, and use a local buffer to format the path. We can just use git_path() for this. It handles paths of any length (reducing our error handling). And because we feed the result straight to a system call, we can just use the static variant. Note that git_path also knows the string "objects/" is special, and will replace it with git_object_directory() when necessary. Another alternative would be to use sha1_file_name() for the pretend object "170000...", but that ends up being more hassle for no gain, as we have to truncate the final path component. Signed-off-by: Jeff King <[email protected]>
1 parent 8c5acfb commit 07af889

File tree

1 file changed

+1
-7
lines changed

1 file changed

+1
-7
lines changed

builtin/gc.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ static int too_many_loose_objects(void)
135135
* distributed, we can check only one and get a reasonable
136136
* estimate.
137137
*/
138-
char path[PATH_MAX];
139-
const char *objdir = get_object_directory();
140138
DIR *dir;
141139
struct dirent *ent;
142140
int auto_threshold;
@@ -146,11 +144,7 @@ static int too_many_loose_objects(void)
146144
if (gc_auto_threshold <= 0)
147145
return 0;
148146

149-
if (sizeof(path) <= snprintf(path, sizeof(path), "%s/17", objdir)) {
150-
warning(_("insanely long object directory %.*s"), 50, objdir);
151-
return 0;
152-
}
153-
dir = opendir(path);
147+
dir = opendir(git_path("objects/17"));
154148
if (!dir)
155149
return 0;
156150

0 commit comments

Comments
 (0)