Skip to content

Commit 7a1d811

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4c8180 commit 7a1d811

File tree

7 files changed

+22
-15
lines changed

7 files changed

+22
-15
lines changed

builtin/fast-import.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ static void start_packfile(void)
763763
struct packed_git *p;
764764
int pack_fd;
765765

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");
767768
FLEX_ALLOC_STR(p, pack_name, tmp_file.buf);
768769
strbuf_release(&tmp_file);
769770

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static const char *open_pack_file(const char *pack_name)
362362
input_fd = 0;
363363
if (!pack_name) {
364364
struct strbuf tmp_file = STRBUF_INIT;
365-
output_fd = odb_mkstemp(&tmp_file,
365+
output_fd = odb_mkstemp(the_repository->objects, &tmp_file,
366366
"pack/tmp_pack_XXXXXX");
367367
pack_name = strbuf_detach(&tmp_file, NULL);
368368
} else {

bundle-uri.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,8 @@ static char *find_temp_filename(void)
278278
* Find a temporary filename that is available. This is briefly
279279
* racy, but unlikely to collide.
280280
*/
281-
fd = odb_mkstemp(&name, "bundles/tmp_uri_XXXXXX");
281+
fd = odb_mkstemp(the_repository->objects, &name,
282+
"bundles/tmp_uri_XXXXXX");
282283
if (fd < 0) {
283284
warning(_("failed to create temporary file"));
284285
return NULL;

odb.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,24 @@ static const struct cached_object *find_cached_object(struct object_database *ob
6363
return NULL;
6464
}
6565

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)
6768
{
6869
int fd;
6970
/*
7071
* we let the umask do its job, don't try to be more
7172
* restrictive except to remove write permission.
7273
*/
7374
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);
7576
fd = git_mkstemp_mode(temp_filename->buf, mode);
7677
if (0 <= fd)
7778
return fd;
7879

7980
/* slow path */
8081
/* 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);
8384
return xmkstemp_mode(temp_filename->buf, mode);
8485
}
8586

odb.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ void odb_clear(struct object_database *o);
201201
struct odb_source *odb_find_source(struct object_database *odb, const char *obj_dir);
202202

203203
/*
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
206206
* usual "XXXXXX" trailer, and the resulting filename is written into the
207207
* "template" buffer. Returns the open descriptor.
208208
*/
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);
210211

211212
void *repo_read_object_file(struct repository *r,
212213
const struct object_id *oid,

pack-bitmap-write.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,8 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
10521052

10531053
struct bitmap_disk_header header;
10541054

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");
10561057

10571058
if (writer->pseudo_merges_nr)
10581059
options |= BITMAP_OPT_PSEUDO_MERGES;

pack-write.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ const char *write_idx_file(struct repository *repo,
8484
} else {
8585
if (!index_name) {
8686
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");
8889
index_name = strbuf_detach(&tmp_file, NULL);
8990
} else {
9091
unlink(index_name);
@@ -259,7 +260,8 @@ char *write_rev_file_order(struct repository *repo,
259260
if (flags & WRITE_REV) {
260261
if (!rev_name) {
261262
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");
263265
path = strbuf_detach(&tmp_file, NULL);
264266
} else {
265267
unlink(rev_name);
@@ -342,7 +344,7 @@ static char *write_mtimes_file(struct repository *repo,
342344
if (!to_pack)
343345
BUG("cannot call write_mtimes_file with NULL packing_data");
344346

345-
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
347+
fd = odb_mkstemp(repo->objects, &tmp_file, "pack/tmp_mtimes_XXXXXX");
346348
mtimes_name = strbuf_detach(&tmp_file, NULL);
347349
f = hashfd(repo->hash_algo, fd, mtimes_name);
348350

@@ -531,7 +533,7 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
531533
struct strbuf tmpname = STRBUF_INIT;
532534
int fd;
533535

534-
fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
536+
fd = odb_mkstemp(repo->objects, &tmpname, "pack/tmp_pack_XXXXXX");
535537
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
536538
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
537539
}

0 commit comments

Comments
 (0)