odb_mkstemp: use git_path_buf

Since git_path_buf() is smart enough to replace "objects/" with the correct object path, we can use it instead of manually assembling the path. That's slightly shorter, and will clean up any non-canonical bits in the path. Signed-off-by: Jeff King <peff@peff.net>

Jeff King committed Mar 28, 2017 at 15:45 UTC 4aa7d75e48250026fce9b496cb5405c269331c31
1 file changed +2 -4
environment.c
+2 -4
@@ -282,16 +282,14 @@ int odb_mkstemp(struct strbuf *template, const char *pattern)
282 * restrictive except to remove write permission.
283 */
284 int mode = 0444;
285 - strbuf_reset(template);
286 - strbuf_addf(template, "%s/%s", get_object_directory(), pattern);
285 + git_path_buf(template, "objects/%s", pattern);
286 fd = git_mkstemp_mode(template->buf, mode);
287 if (0 <= fd)
288 return fd;
289
290 /* slow path */
291 /* some mkstemp implementations erase template on failure */
293 - strbuf_reset(template);
294 - strbuf_addf(template, "%s/%s", get_object_directory(), pattern);
292 + git_path_buf(template, "objects/%s", pattern);
293 safe_create_leading_directories(template->buf);
294 return xmkstemp_mode(template->buf, mode);
295 }