odb: get rid of `the_repository` in `odb_mkstemp()`

Get rid of our dependency on `the_repository` in `odb_mkstemp()` by passing in the object database as a parameter and adjusting all callers. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC 1b1679c6883f948b19599f11229ff61124b51733
7 files changed +22 -15
builtin/fast-import.c
+2 -1
@@ -763,7 +763,8 @@ static void start_packfile(void)
763 struct packed_git *p;
764 int pack_fd;
765
766 - pack_fd = odb_mkstemp(&tmp_file, "pack/tmp_pack_XXXXXX");
766 + pack_fd = odb_mkstemp(the_repository->objects, &tmp_file,
767 + "pack/tmp_pack_XXXXXX");
768 FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
769 strbuf_release(&tmp_file);
770
builtin/index-pack.c
+1 -1
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
362 input_fd = 0;
363 if (!pack_name) {
364 struct strbuf tmp_file = STRBUF_INIT;
365 - output_fd = odb_mkstemp(&tmp_file,
365 + output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
366 "pack/tmp_pack_XXXXXX");
367 pack_name = strbuf_detach(&tmp_file, NULL);
368 } else {
bundle-uri.c
+2 -1
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
278 * Find a temporary filename that is available. This is briefly
279 * racy, but unlikely to collide.
280 */
281 - fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
281 + fd = odb_mkstemp(the_repository->objects, &name,
282 + "bundles/tmp_uri_XXXXXX");
283 if (fd < 0) {
284 warning(_("failed to create temporary file"));
285 return NULL;
odb.c
+5 -4
@@ -63,7 +63,8 @@ static const struct cached_object *find_cached_object(struct object_database *ob
63 return NULL;
64 }
65
66 -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
66 +int odb_mkstemp(struct object_database *odb,
67 + struct strbuf *temp_filename, const char *pattern)
68 {
69 int fd;
70 /*
@@ -71,15 +72,15 @@ int odb_mkstemp(struct strbuf *temp_filename, const char *pattern)
72 * restrictive except to remove write permission.
73 */
74 int mode = 0444;
74 - repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
75 + repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
76 fd = git_mkstemp_mode(temp_filename->buf, mode);
77 if (0 <= fd)
78 return fd;
79
80 /* slow path */
81 /* some mkstemp implementations erase temp_filename on failure */
81 - repo_git_path_replace(the_repository, temp_filename, "objects/%s", pattern);
82 - safe_create_leading_directories(the_repository, temp_filename->buf);
82 + repo_git_path_replace(odb->repo, temp_filename, "objects/%s", pattern);
83 + safe_create_leading_directories(odb->repo, temp_filename->buf);
84 return xmkstemp_mode(temp_filename->buf, mode);
85 }
86
odb.h
+4 -3
@@ -201,12 +201,13 @@ void odb_clear(struct object_database *o);
201 struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
202
203 /*
204 - * Create a temporary file rooted in the object database directory, or
205 - * die on failure. The filename is taken from "pattern", which should have the
204 + * Create a temporary file rooted in the primary alternate's directory, or die
205 + * on failure. The filename is taken from "pattern", which should have the
206 * usual "XXXXXX" trailer, and the resulting filename is written into the
207 * "template" buffer. Returns the open descriptor.
208 */
209 -int odb_mkstemp(struct strbuf *temp_filename, const char *pattern);
209 +int odb_mkstemp(struct object_database *odb,
210 + struct strbuf *temp_filename, const char *pattern);
211
212 void *repo_read_object_file(struct repository *r,
213 const struct object_id *oid,
pack-bitmap-write.c
+2 -1
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
1052
1053 struct bitmap_disk_header header;
1054
1055 - int fd = odb_mkstemp(&tmp_file, "pack/tmp_bitmap_XXXXXX");
1055 + int fd = odb_mkstemp(writer->repo->objects, &tmp_file,
1056 + "pack/tmp_bitmap_XXXXXX");
1057
1058 if (writer->pseudo_merges_nr)
1059 options |= BITMAP_OPT_PSEUDO_MERGES;
pack-write.c
+6 -4
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
84 } else {
85 if (!index_name) {
86 struct strbuf tmp_file = STRBUF_INIT;
87 - fd = odb_mkstemp(&tmp_file, "pack/tmp_idx_XXXXXX");
87 + fd = odb_mkstemp(repo->objects, &tmp_file,
88 + "pack/tmp_idx_XXXXXX");
89 index_name = strbuf_detach(&tmp_file, NULL);
90 } else {
91 unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
260 if (flags & WRITE_REV) {
261 if (!rev_name) {
262 struct strbuf tmp_file = STRBUF_INIT;
262 - fd = odb_mkstemp(&tmp_file, "pack/tmp_rev_XXXXXX");
263 + fd = odb_mkstemp(repo->objects, &tmp_file,
264 + "pack/tmp_rev_XXXXXX");
265 path = strbuf_detach(&tmp_file, NULL);
266 } else {
267 unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
344 if (!to_pack)
345 BUG("cannot call write_mtimes_file with NULL packing_data");
346
345 - fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
347 + fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
348 mtimes_name = strbuf_detach(&tmp_file, NULL);
349 f = hashfd(repo->hash_algo, fd, mtimes_name);
350
@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
533 struct strbuf tmpname = STRBUF_INIT;
534 int fd;
535
534 - fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
536 + fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
537 *pack_tmp_name = strbuf_detach(&tmpname, NULL);
538 return hashfd(repo->hash_algo, fd, *pack_tmp_name);
539 }