From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>,
Junio C Hamano <gitster@pobox.com>,
Karthik Nayak <karthik.188@gmail.com>,
Toon Claes <toon@iotcl.com>
Subject: [PATCH v2 07/16] object-file: get rid of `the_repository` in `finalize_object_file()`
Date: Thu, 17 Jul 2025 06:56:33 +0200 [thread overview]
Message-ID: <20250717-pks-object-file-wo-the-repository-v2-7-36d2cd6c700e@pks.im> (raw)
In-Reply-To: <20250717-pks-object-file-wo-the-repository-v2-0-36d2cd6c700e@pks.im>
We implicitly depend on `the_repository` when moving an object file into
place in `finalize_object_file()`. Get rid of this global dependency by
passing in a repository.
Note that one might be pressed to inject an object database instead of a
repository. But the function doesn't really care about the ODB at all.
All it does is to move a file into place while checking whether there is
any collision. As such, the functionality it provides is independent of
the object database and only needs the repository as parameter so that
it can adjust permissions of the file we are about to finalize.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 4 ++--
builtin/index-pack.c | 2 +-
builtin/pack-objects.c | 2 +-
bulk-checkin.c | 2 +-
http.c | 4 ++--
midx-write.c | 2 +-
object-file.c | 14 ++++++++------
object-file.h | 6 ++++--
pack-write.c | 16 +++++++++-------
pack.h | 3 ++-
tmp-objdir.c | 2 +-
11 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b1389c59211..89f57898b15 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -821,11 +821,11 @@ static char *keep_pack(const char *curr_index_name)
die_errno("failed to write keep file");
odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
- if (finalize_object_file(pack_data->pack_name, name.buf))
+ if (finalize_object_file(pack_data->repo, pack_data->pack_name, name.buf))
die("cannot store pack file");
odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx");
- if (finalize_object_file(curr_index_name, name.buf))
+ if (finalize_object_file(pack_data->repo, curr_index_name, name.buf))
die("cannot store index file");
free((void *)curr_index_name);
return strbuf_detach(&name, NULL);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 19c67a85344..dabeb825a6c 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1598,7 +1598,7 @@ static void rename_tmp_packfile(const char **final_name,
if (!*final_name || strcmp(*final_name, curr_name)) {
if (!*final_name)
*final_name = odb_pack_name(the_repository, name, hash, ext);
- if (finalize_object_file(curr_name, *final_name))
+ if (finalize_object_file(the_repository, curr_name, *final_name))
die(_("unable to rename temporary '*.%s' file to '%s'"),
ext, *final_name);
} else if (make_read_only_if_same) {
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a44f0ce1c78..e8e85d8278b 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1449,7 +1449,7 @@ static void write_pack_file(void)
strbuf_setlen(&tmpname, tmpname_len);
}
- rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
+ rename_tmp_packfile_idx(the_repository, &tmpname, &idx_tmp_name);
free(idx_tmp_name);
strbuf_release(&tmpname);
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 16df86c0ba8..b2809ab0398 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -46,7 +46,7 @@ static void finish_tmp_packfile(struct strbuf *basename,
stage_tmp_packfiles(the_repository, basename, pack_tmp_name,
written_list, nr_written, NULL, pack_idx_opts, hash,
&idx_tmp_name);
- rename_tmp_packfile_idx(basename, &idx_tmp_name);
+ rename_tmp_packfile_idx(the_repository, basename, &idx_tmp_name);
free(idx_tmp_name);
}
diff --git a/http.c b/http.c
index 9b62f627dc5..7cc797116bb 100644
--- a/http.c
+++ b/http.c
@@ -2331,7 +2331,7 @@ int http_get_file(const char *url, const char *filename,
ret = http_request_reauth(url, result, HTTP_REQUEST_FILE, options);
fclose(result);
- if (ret == HTTP_OK && finalize_object_file(tmpfile.buf, filename))
+ if (ret == HTTP_OK && finalize_object_file(the_repository, tmpfile.buf, filename))
ret = HTTP_ERROR;
cleanup:
strbuf_release(&tmpfile);
@@ -2815,7 +2815,7 @@ int finish_http_object_request(struct http_object_request *freq)
return -1;
}
odb_loose_path(the_repository->objects->sources, &filename, &freq->oid);
- freq->rename = finalize_object_file(freq->tmpfile.buf, filename.buf);
+ freq->rename = finalize_object_file(the_repository, freq->tmpfile.buf, filename.buf);
strbuf_release(&filename);
return freq->rename;
diff --git a/midx-write.c b/midx-write.c
index f2cfb85476e..effacade2d3 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -667,7 +667,7 @@ static void write_midx_reverse_index(struct write_midx_context *ctx,
tmp_file = write_rev_file_order(ctx->repo, NULL, ctx->pack_order,
ctx->entries_nr, midx_hash, WRITE_REV);
- if (finalize_object_file(tmp_file, buf.buf))
+ if (finalize_object_file(ctx->repo, tmp_file, buf.buf))
die(_("cannot store reverse index file"));
strbuf_release(&buf);
diff --git a/object-file.c b/object-file.c
index 800eeae85af..6a7049a9e98 100644
--- a/object-file.c
+++ b/object-file.c
@@ -584,12 +584,14 @@ static int check_collision(const char *source, const char *dest)
/*
* Move the just written object into its final resting place.
*/
-int finalize_object_file(const char *tmpfile, const char *filename)
+int finalize_object_file(struct repository *repo,
+ const char *tmpfile, const char *filename)
{
- return finalize_object_file_flags(tmpfile, filename, 0);
+ return finalize_object_file_flags(repo, tmpfile, filename, 0);
}
-int finalize_object_file_flags(const char *tmpfile, const char *filename,
+int finalize_object_file_flags(struct repository *repo,
+ const char *tmpfile, const char *filename,
enum finalize_object_file_flags flags)
{
unsigned retries = 0;
@@ -649,7 +651,7 @@ int finalize_object_file_flags(const char *tmpfile, const char *filename,
}
out:
- if (adjust_shared_perm(the_repository, filename))
+ if (adjust_shared_perm(repo, filename))
return error(_("unable to set permission to '%s'"), filename);
return 0;
}
@@ -889,7 +891,7 @@ static int write_loose_object(const struct object_id *oid, char *hdr,
warning_errno(_("failed utime() on %s"), tmp_file.buf);
}
- return finalize_object_file_flags(tmp_file.buf, filename.buf,
+ return finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf,
FOF_SKIP_COLLISION_CHECK);
}
@@ -1020,7 +1022,7 @@ int stream_loose_object(struct input_stream *in_stream, size_t len,
strbuf_release(&dir);
}
- err = finalize_object_file_flags(tmp_file.buf, filename.buf,
+ err = finalize_object_file_flags(the_repository, tmp_file.buf, filename.buf,
FOF_SKIP_COLLISION_CHECK);
if (!err && compat)
err = repo_add_loose_object_map(the_repository, oid, &compat_oid);
diff --git a/object-file.h b/object-file.h
index 5b63a05ab51..370139e0762 100644
--- a/object-file.h
+++ b/object-file.h
@@ -218,8 +218,10 @@ enum finalize_object_file_flags {
FOF_SKIP_COLLISION_CHECK = 1,
};
-int finalize_object_file(const char *tmpfile, const char *filename);
-int finalize_object_file_flags(const char *tmpfile, const char *filename,
+int finalize_object_file(struct repository *repo,
+ const char *tmpfile, const char *filename);
+int finalize_object_file_flags(struct repository *repo,
+ const char *tmpfile, const char *filename,
enum finalize_object_file_flags flags);
void hash_object_file(const struct git_hash_algo *algo, const void *buf,
diff --git a/pack-write.c b/pack-write.c
index eccdc798e36..83eaf88541e 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -538,22 +538,24 @@ struct hashfile *create_tmp_packfile(struct repository *repo,
return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
-static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,
+static void rename_tmp_packfile(struct repository *repo,
+ struct strbuf *name_prefix, const char *source,
const char *ext)
{
size_t name_prefix_len = name_prefix->len;
strbuf_addstr(name_prefix, ext);
- if (finalize_object_file(source, name_prefix->buf))
+ if (finalize_object_file(repo, source, name_prefix->buf))
die("unable to rename temporary file to '%s'",
name_prefix->buf);
strbuf_setlen(name_prefix, name_prefix_len);
}
-void rename_tmp_packfile_idx(struct strbuf *name_buffer,
+void rename_tmp_packfile_idx(struct repository *repo,
+ struct strbuf *name_buffer,
char **idx_tmp_name)
{
- rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
+ rename_tmp_packfile(repo, name_buffer, *idx_tmp_name, "idx");
}
void stage_tmp_packfiles(struct repository *repo,
@@ -586,11 +588,11 @@ void stage_tmp_packfiles(struct repository *repo,
hash);
}
- rename_tmp_packfile(name_buffer, pack_tmp_name, "pack");
+ rename_tmp_packfile(repo, name_buffer, pack_tmp_name, "pack");
if (rev_tmp_name)
- rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
+ rename_tmp_packfile(repo, name_buffer, rev_tmp_name, "rev");
if (mtimes_tmp_name)
- rename_tmp_packfile(name_buffer, mtimes_tmp_name, "mtimes");
+ rename_tmp_packfile(repo, name_buffer, mtimes_tmp_name, "mtimes");
free(rev_tmp_name);
free(mtimes_tmp_name);
diff --git a/pack.h b/pack.h
index 5d4393eaffe..ec76472e49b 100644
--- a/pack.h
+++ b/pack.h
@@ -145,7 +145,8 @@ void stage_tmp_packfiles(struct repository *repo,
struct pack_idx_option *pack_idx_opts,
unsigned char hash[],
char **idx_tmp_name);
-void rename_tmp_packfile_idx(struct strbuf *basename,
+void rename_tmp_packfile_idx(struct repository *repo,
+ struct strbuf *basename,
char **idx_tmp_name);
#endif
diff --git a/tmp-objdir.c b/tmp-objdir.c
index ae01eae9c41..9f5a1788cd7 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -227,7 +227,7 @@ static int migrate_one(struct tmp_objdir *t,
return -1;
return migrate_paths(t, src, dst, flags);
}
- return finalize_object_file_flags(src->buf, dst->buf, flags);
+ return finalize_object_file_flags(t->repo, src->buf, dst->buf, flags);
}
static int is_loose_object_shard(const char *name)
--
2.50.1.465.gcb3da1c9e6.dirty
next prev parent reply other threads:[~2025-07-17 4:56 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-09 11:17 [PATCH 00/19] object-file: get rid of `the_repository` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 01/19] object-file: fix -Wsign-compare warnings Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 02/19] object-file: stop using `the_hash_algo` Patrick Steinhardt
2025-07-11 9:52 ` Karthik Nayak
2025-07-09 11:17 ` [PATCH 03/19] object-file: get rid of `the_repository` in `has_loose_object()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 04/19] object-file: inline `check_and_freshen()` functions Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 05/19] object-file: get rid of `the_repository` when freshening objects Patrick Steinhardt
2025-07-11 9:59 ` Karthik Nayak
2025-07-09 11:17 ` [PATCH 06/19] object-file: get rid of `the_repository` in `loose_object_info()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 07/19] object-file: get rid of `the_repository` in `finalize_object_file()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 08/19] loose: write loose objects map via their source Patrick Steinhardt
2025-07-11 10:25 ` Karthik Nayak
2025-07-15 10:50 ` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 09/19] odb: introduce `odb_write_object()` Patrick Steinhardt
2025-07-10 18:39 ` Toon Claes
2025-07-15 10:50 ` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 10/19] object-file: get rid of `the_repository` when writing objects Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 11/19] object-file: inline `for_each_loose_file_in_objdir_buf()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 12/19] object-file: remove declaration for `for_each_file_in_obj_subdir()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 13/19] object-file: get rid of `the_repository` in loose object iterators Patrick Steinhardt
2025-07-10 18:41 ` Toon Claes
2025-07-09 11:17 ` [PATCH 14/19] object-file: get rid of `the_repository` in `read_loose_object()` Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 15/19] object-file: get rid of `the_repository` in `force_object_loose()` Patrick Steinhardt
2025-07-10 18:42 ` Toon Claes
2025-07-11 10:38 ` Karthik Nayak
2025-07-15 10:50 ` Patrick Steinhardt
2025-07-15 11:36 ` Toon Claes
2025-07-09 11:17 ` [PATCH 16/19] object-file: get rid of `the_repository` in index-related functions Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 17/19] environment: move compression level into repo settings Patrick Steinhardt
2025-07-09 15:26 ` Phillip Wood
2025-07-11 18:55 ` Junio C Hamano
2025-07-15 10:50 ` Patrick Steinhardt
2025-07-15 11:27 ` Patrick Steinhardt
2025-07-15 15:51 ` Phillip Wood
2025-07-15 16:12 ` Patrick Steinhardt
2025-07-16 12:56 ` Patrick Steinhardt
2025-07-17 15:19 ` Phillip Wood
2025-07-17 15:56 ` Junio C Hamano
2025-07-15 18:50 ` Junio C Hamano
2025-07-17 8:00 ` Ayush Chandekar
2025-07-09 11:17 ` [PATCH 18/19] environment: move object creation mode " Patrick Steinhardt
2025-07-09 11:17 ` [PATCH 19/19] object-file: drop USE_THE_REPOSITORY_VARIABLE Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 00/16] object-file: get rid of `the_repository` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 01/16] object-file: fix -Wsign-compare warnings Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 02/16] object-file: stop using `the_hash_algo` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 03/16] object-file: get rid of `the_repository` in `has_loose_object()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 04/16] object-file: inline `check_and_freshen()` functions Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 05/16] object-file: get rid of `the_repository` when freshening objects Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 06/16] object-file: get rid of `the_repository` in `loose_object_info()` Patrick Steinhardt
2025-07-17 4:56 ` Patrick Steinhardt [this message]
2025-07-17 4:56 ` [PATCH v2 08/16] loose: write loose objects map via their source Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 09/16] odb: introduce `odb_write_object()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 10/16] object-file: get rid of `the_repository` when writing objects Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 11/16] object-file: inline `for_each_loose_file_in_objdir_buf()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 12/16] object-file: remove declaration for `for_each_file_in_obj_subdir()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 13/16] object-file: get rid of `the_repository` in loose object iterators Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 14/16] object-file: get rid of `the_repository` in `read_loose_object()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 15/16] object-file: get rid of `the_repository` in `force_object_loose()` Patrick Steinhardt
2025-07-17 4:56 ` [PATCH v2 16/16] object-file: get rid of `the_repository` in index-related functions Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250717-pks-object-file-wo-the-repository-v2-7-36d2cd6c700e@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=toon@iotcl.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).