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 <peff@peff.net>

Jeff King committed Mar 28, 2017 at 15:47 UTC 07af88913662f1179ba34b92370a6df24263ae5f
1 file changed +1 -7
builtin/gc.c
+1 -7
@@ -135,8 +135,6 @@ static int too_many_loose_objects(void)
135 * distributed, we can check only one and get a reasonable
136 * estimate.
137 */
138 - char path[PATH_MAX];
139 - const char *objdir = get_object_directory();
138 DIR *dir;
139 struct dirent *ent;
140 int auto_threshold;
@@ -146,11 +144,7 @@ static int too_many_loose_objects(void)
144 if (gc_auto_threshold <= 0)
145 return 0;
146
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"));
148 if (!dir)
149 return 0;
150