From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Subject: [PATCH 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo`
Date: Mon, 03 Mar 2025 09:47:32 +0100 [thread overview]
Message-ID: <20250303-b4-pks-objects-without-the-repository-v1-3-c5dd43f2476e@pks.im> (raw)
In-Reply-To: <20250303-b4-pks-objects-without-the-repository-v1-0-c5dd43f2476e@pks.im>
There are a couple of functions in "pack-write.c" that implicitly depend
on `the_repository` or `the_hash_algo`. Remove this dependency by
injecting the repository via a parameter and adapt callers accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
builtin/fast-import.c | 2 +-
builtin/index-pack.c | 4 ++--
builtin/pack-objects.c | 4 ++--
bulk-checkin.c | 4 ++--
midx-write.c | 2 +-
pack-write.c | 55 +++++++++++++++++++++++++-------------------------
pack.h | 11 +++++-----
7 files changed, 41 insertions(+), 41 deletions(-)
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index 86e6e754816..e1758aa9514 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -798,7 +798,7 @@ static const char *create_index(void)
if (c != last)
die("internal consistency error creating the index");
- tmpfile = write_idx_file(the_hash_algo, NULL, idx, object_count,
+ tmpfile = write_idx_file(the_repository, NULL, idx, object_count,
&pack_idx_opts, pack_data->hash);
free(idx);
return tmpfile;
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index b8bb0ac01de..e4f2aa01ed5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -2088,10 +2088,10 @@ int cmd_index_pack(int argc,
ALLOC_ARRAY(idx_objects, nr_objects);
for (i = 0; i < nr_objects; i++)
idx_objects[i] = &objects[i].idx;
- curr_index = write_idx_file(the_hash_algo, index_name, idx_objects,
+ curr_index = write_idx_file(the_repository, index_name, idx_objects,
nr_objects, &opts, pack_hash);
if (rev_index)
- curr_rev_index = write_rev_file(the_hash_algo, rev_index_name,
+ curr_rev_index = write_rev_file(the_repository, rev_index_name,
idx_objects, nr_objects,
pack_hash, opts.flags);
free(idx_objects);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index c3adbc94504..e05dfc4021e 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1314,7 +1314,7 @@ static void write_pack_file(void)
f = hashfd_throughput(the_repository->hash_algo, 1,
"<stdout>", progress_state);
else
- f = create_tmp_packfile(&pack_tmp_name);
+ f = create_tmp_packfile(the_repository, &pack_tmp_name);
offset = write_pack_header(f, nr_remaining);
@@ -1407,7 +1407,7 @@ static void write_pack_file(void)
if (cruft)
pack_idx_opts.flags |= WRITE_MTIMES;
- stage_tmp_packfiles(the_hash_algo, &tmpname,
+ stage_tmp_packfiles(the_repository, &tmpname,
pack_tmp_name, written_list,
nr_written, &to_pack,
&pack_idx_opts, hash,
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 20f2da67b93..23ac00ea0a6 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -44,7 +44,7 @@ static void finish_tmp_packfile(struct strbuf *basename,
{
char *idx_tmp_name = NULL;
- stage_tmp_packfiles(the_hash_algo, basename, pack_tmp_name,
+ 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);
@@ -244,7 +244,7 @@ static void prepare_to_stream(struct bulk_checkin_packfile *state,
if (!(flags & HASH_WRITE_OBJECT) || state->f)
return;
- state->f = create_tmp_packfile(&state->pack_tmp_name);
+ state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name);
reset_pack_idx_option(&state->pack_idx_opts);
/* Pretend we are going to write only one object */
diff --git a/midx-write.c b/midx-write.c
index ac80a8298ed..a628ac24dcb 100644
--- a/midx-write.c
+++ b/midx-write.c
@@ -658,7 +658,7 @@ static void write_midx_reverse_index(char *midx_name, unsigned char *midx_hash,
strbuf_addf(&buf, "%s-%s.rev", midx_name, hash_to_hex_algop(midx_hash,
ctx->repo->hash_algo));
- tmp_file = write_rev_file_order(ctx->repo->hash_algo, NULL, ctx->pack_order,
+ 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))
diff --git a/pack-write.c b/pack-write.c
index 5eb89f44cf4..6b06315f80a 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
#include "git-compat-util.h"
#include "environment.h"
#include "gettext.h"
@@ -56,7 +54,7 @@ static int need_large_offset(off_t offset, const struct pack_idx_option *opts)
* The *sha1 contains the pack content SHA1 hash.
* The objects array passed in will be sorted by SHA1 on exit.
*/
-const char *write_idx_file(const struct git_hash_algo *hash_algo,
+const char *write_idx_file(struct repository *repo,
const char *index_name, struct pack_idx_entry **objects,
int nr_objects, const struct pack_idx_option *opts,
const unsigned char *sha1)
@@ -82,7 +80,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
if (opts->flags & WRITE_IDX_VERIFY) {
assert(index_name);
- f = hashfd_check(the_repository->hash_algo, index_name);
+ f = hashfd_check(repo->hash_algo, index_name);
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
@@ -92,7 +90,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
unlink(index_name);
fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
}
- f = hashfd(the_repository->hash_algo, fd, index_name);
+ f = hashfd(repo->hash_algo, fd, index_name);
}
/* if last object's offset is >= 2^31 we should use index V2 */
@@ -131,7 +129,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
struct pack_idx_entry *obj = *list++;
if (index_version < 2)
hashwrite_be32(f, obj->offset);
- hashwrite(f, obj->oid.hash, hash_algo->rawsz);
+ hashwrite(f, obj->oid.hash, repo->hash_algo->rawsz);
if ((opts->flags & WRITE_IDX_STRICT) &&
(i && oideq(&list[-2]->oid, &obj->oid)))
die("The same object %s appears twice in the pack",
@@ -173,7 +171,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
}
}
- hashwrite(f, sha1, hash_algo->rawsz);
+ hashwrite(f, sha1, repo->hash_algo->rawsz);
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
CSUM_HASH_IN_STREAM | CSUM_CLOSE |
((opts->flags & WRITE_IDX_VERIFY) ? 0 : CSUM_FSYNC));
@@ -217,7 +215,7 @@ static void write_rev_trailer(const struct git_hash_algo *hash_algo,
hashwrite(f, hash, hash_algo->rawsz);
}
-char *write_rev_file(const struct git_hash_algo *hash_algo,
+char *write_rev_file(struct repository *repo,
const char *rev_name,
struct pack_idx_entry **objects,
uint32_t nr_objects,
@@ -236,7 +234,7 @@ char *write_rev_file(const struct git_hash_algo *hash_algo,
pack_order[i] = i;
QSORT_S(pack_order, nr_objects, pack_order_cmp, objects);
- ret = write_rev_file_order(hash_algo, rev_name, pack_order, nr_objects,
+ ret = write_rev_file_order(repo, rev_name, pack_order, nr_objects,
hash, flags);
free(pack_order);
@@ -244,7 +242,7 @@ char *write_rev_file(const struct git_hash_algo *hash_algo,
return ret;
}
-char *write_rev_file_order(const struct git_hash_algo *hash_algo,
+char *write_rev_file_order(struct repository *repo,
const char *rev_name,
uint32_t *pack_order,
uint32_t nr_objects,
@@ -268,7 +266,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
path = xstrdup(rev_name);
}
- f = hashfd(the_repository->hash_algo, fd, path);
+ f = hashfd(repo->hash_algo, fd, path);
} else if (flags & WRITE_REV_VERIFY) {
struct stat statbuf;
if (stat(rev_name, &statbuf)) {
@@ -278,18 +276,18 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
} else
die_errno(_("could not stat: %s"), rev_name);
}
- f = hashfd_check(the_repository->hash_algo, rev_name);
+ f = hashfd_check(repo->hash_algo, rev_name);
path = xstrdup(rev_name);
} else {
return NULL;
}
- write_rev_header(hash_algo, f);
+ write_rev_header(repo->hash_algo, f);
write_rev_index_positions(f, pack_order, nr_objects);
- write_rev_trailer(hash_algo, f, hash);
+ write_rev_trailer(repo->hash_algo, f, hash);
- if (adjust_shared_perm(the_repository, path) < 0)
+ if (adjust_shared_perm(repo, path) < 0)
die(_("failed to make %s readable"), path);
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -330,7 +328,7 @@ static void write_mtimes_trailer(const struct git_hash_algo *hash_algo,
hashwrite(f, hash, hash_algo->rawsz);
}
-static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
+static char *write_mtimes_file(struct repository *repo,
struct packing_data *to_pack,
struct pack_idx_entry **objects,
uint32_t nr_objects,
@@ -346,13 +344,13 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
- f = hashfd(the_repository->hash_algo, fd, mtimes_name);
+ f = hashfd(repo->hash_algo, fd, mtimes_name);
- write_mtimes_header(hash_algo, f);
+ write_mtimes_header(repo->hash_algo, f);
write_mtimes_objects(f, to_pack, objects, nr_objects);
- write_mtimes_trailer(hash_algo, f, hash);
+ write_mtimes_trailer(repo->hash_algo, f, hash);
- if (adjust_shared_perm(the_repository, mtimes_name) < 0)
+ if (adjust_shared_perm(repo, mtimes_name) < 0)
die(_("failed to make %s readable"), mtimes_name);
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
@@ -527,14 +525,15 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
return n;
}
-struct hashfile *create_tmp_packfile(char **pack_tmp_name)
+struct hashfile *create_tmp_packfile(struct repository *repo,
+ char **pack_tmp_name)
{
struct strbuf tmpname = STRBUF_INIT;
int fd;
fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
- return hashfd(the_repository->hash_algo, fd, *pack_tmp_name);
+ return hashfd(repo->hash_algo, fd, *pack_tmp_name);
}
static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,
@@ -555,7 +554,7 @@ void rename_tmp_packfile_idx(struct strbuf *name_buffer,
rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
}
-void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
+void stage_tmp_packfiles(struct repository *repo,
struct strbuf *name_buffer,
const char *pack_tmp_name,
struct pack_idx_entry **written_list,
@@ -568,19 +567,19 @@ void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
char *rev_tmp_name = NULL;
char *mtimes_tmp_name = NULL;
- if (adjust_shared_perm(the_repository, pack_tmp_name))
+ if (adjust_shared_perm(repo, pack_tmp_name))
die_errno("unable to make temporary pack file readable");
- *idx_tmp_name = (char *)write_idx_file(hash_algo, NULL, written_list,
+ *idx_tmp_name = (char *)write_idx_file(repo, NULL, written_list,
nr_written, pack_idx_opts, hash);
- if (adjust_shared_perm(the_repository, *idx_tmp_name))
+ if (adjust_shared_perm(repo, *idx_tmp_name))
die_errno("unable to make temporary index file readable");
- rev_tmp_name = write_rev_file(hash_algo, NULL, written_list, nr_written,
+ rev_tmp_name = write_rev_file(repo, NULL, written_list, nr_written,
hash, pack_idx_opts->flags);
if (pack_idx_opts->flags & WRITE_MTIMES) {
- mtimes_tmp_name = write_mtimes_file(hash_algo, to_pack,
+ mtimes_tmp_name = write_mtimes_file(repo, to_pack,
written_list, nr_written,
hash);
}
diff --git a/pack.h b/pack.h
index 9f1194ac13d..5d4393eaffe 100644
--- a/pack.h
+++ b/pack.h
@@ -87,7 +87,7 @@ struct progress;
/* Note, the data argument could be NULL if object type is blob */
typedef int (*verify_fn)(const struct object_id *, enum object_type, unsigned long, void*, int*);
-const char *write_idx_file(const struct git_hash_algo *hash_algo,
+const char *write_idx_file(struct repository *repo,
const char *index_name,
struct pack_idx_entry **objects,
int nr_objects,
@@ -106,13 +106,13 @@ struct ref;
void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought);
-char *write_rev_file(const struct git_hash_algo *hash_algo,
+char *write_rev_file(struct repository *repo,
const char *rev_name,
struct pack_idx_entry **objects,
uint32_t nr_objects,
const unsigned char *hash,
unsigned flags);
-char *write_rev_file_order(const struct git_hash_algo *hash_algo,
+char *write_rev_file_order(struct repository *repo,
const char *rev_name,
uint32_t *pack_order,
uint32_t nr_objects,
@@ -134,8 +134,9 @@ int read_pack_header(int fd, struct pack_header *);
struct packing_data;
-struct hashfile *create_tmp_packfile(char **pack_tmp_name);
-void stage_tmp_packfiles(const struct git_hash_algo *hash_algo,
+struct hashfile *create_tmp_packfile(struct repository *repo,
+ char **pack_tmp_name);
+void stage_tmp_packfiles(struct repository *repo,
struct strbuf *name_buffer,
const char *pack_tmp_name,
struct pack_idx_entry **written_list,
--
2.49.0.rc0.375.gae4b89d849.dirty
next prev parent reply other threads:[~2025-03-03 8:47 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-03 8:47 [PATCH 00/12] Stop depending on `the_repository` in object-related subsystems Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 10:37 ` Karthik Nayak
2025-03-03 8:47 ` [PATCH 02/12] object: " Patrick Steinhardt
2025-03-06 11:07 ` Karthik Nayak
2025-03-06 14:55 ` Patrick Steinhardt
2025-03-03 8:47 ` Patrick Steinhardt [this message]
2025-03-04 18:46 ` [PATCH 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Justin Tobler
2025-03-03 8:47 ` [PATCH 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-04 19:32 ` Justin Tobler
2025-03-06 14:54 ` Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 11:14 ` Karthik Nayak
2025-03-03 8:47 ` [PATCH 06/12] pack-revindex: " Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 08/12] object-file-convert: " Patrick Steinhardt
2025-03-04 19:45 ` Justin Tobler
2025-03-03 8:47 ` [PATCH 09/12] delta-islands: " Patrick Steinhardt
2025-03-04 19:48 ` Justin Tobler
2025-03-03 8:47 ` [PATCH 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-03 8:47 ` [PATCH 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-04 20:16 ` Justin Tobler
2025-03-06 11:20 ` [PATCH 00/12] Stop depending on `the_repository` in object-related subsystems Karthik Nayak
2025-03-06 15:10 ` [PATCH v2 " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 02/12] object: " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 06/12] pack-revindex: " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 08/12] object-file-convert: " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 09/12] delta-islands: " Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-06 15:10 ` [PATCH v2 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-06 19:14 ` Junio C Hamano
2025-03-07 9:08 ` Patrick Steinhardt
2025-03-07 16:53 ` Junio C Hamano
2025-03-06 15:29 ` [PATCH v2 00/12] Stop depending on `the_repository` in object-related subsystems Karthik Nayak
2025-03-07 14:18 ` [PATCH v3 " Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 02/12] object: " Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-07 14:18 ` [PATCH v3 06/12] pack-revindex: " Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 08/12] object-file-convert: " Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 09/12] delta-islands: " Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-07 14:19 ` [PATCH v3 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-08 16:05 ` Elijah Newren
2025-03-10 7:11 ` Patrick Steinhardt
2025-03-10 22:37 ` Elijah Newren
2025-03-10 15:38 ` Junio C Hamano
2025-03-08 16:11 ` [PATCH v3 00/12] Stop depending on `the_repository` in object-related subsystems Elijah Newren
2025-03-10 7:13 ` [PATCH v4 " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 01/12] csum-file: stop depending on `the_repository` Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 02/12] object: " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 04/12] environment: move access to "core.bigFileThreshold" into repo settings Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 05/12] pack-check: stop depending on `the_repository` Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 06/12] pack-revindex: " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 07/12] pack-bitmap-write: " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 08/12] object-file-convert: " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 09/12] delta-islands: " Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 10/12] object-file: split out logic regarding hash algorithms Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 11/12] hash: fix "-Wsign-compare" warnings Patrick Steinhardt
2025-03-10 7:13 ` [PATCH v4 12/12] hash: stop depending on `the_repository` in `null_oid()` Patrick Steinhardt
2025-03-10 22:39 ` [PATCH v4 00/12] Stop depending on `the_repository` in object-related subsystems Elijah Newren
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=20250303-b4-pks-objects-without-the-repository-v1-3-c5dd43f2476e@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
/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).