From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Karthik Nayak <karthik.188@gmail.com>,
Justin Tobler <jltobler@gmail.com>
Subject: [PATCH v2 07/12] pack-bitmap-write: stop depending on `the_repository`
Date: Thu, 06 Mar 2025 16:10:31 +0100 [thread overview]
Message-ID: <20250306-b4-pks-objects-without-the-repository-v2-7-f3465327be69@pks.im> (raw)
In-Reply-To: <20250306-b4-pks-objects-without-the-repository-v2-0-f3465327be69@pks.im>
There are multiple sites in "pack-bitmap-write.c" where we use the
global `the_repository` variable, either explicitly or implicitly by
using `the_hash_algo`.
Refactor the code so that the `struct bitmap_writer` stores the
repository it is getting initialized with. Like this, we can adapt
callsites that use `the_repository` to instead use the repository
provided by the writer.
Remove the `USE_THE_REPOSITORY_VARIABLE` define.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
pack-bitmap-write.c | 36 ++++++++++++++++++------------------
pack-bitmap.h | 1 +
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
index 50e5c491ccb..6a97b52b36d 100644
--- a/pack-bitmap-write.c
+++ b/pack-bitmap-write.c
@@ -1,4 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
#define DISABLE_SIGN_COMPARE_WARNINGS
#include "git-compat-util.h"
@@ -48,6 +47,7 @@ void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r,
memset(writer, 0, sizeof(struct bitmap_writer));
if (writer->bitmaps)
BUG("bitmap writer already initialized");
+ writer->repo = r;
writer->bitmaps = kh_init_oid_map();
writer->pseudo_merge_commits = kh_init_oid_map();
writer->to_pack = pdata;
@@ -415,9 +415,9 @@ static void bitmap_builder_init(struct bitmap_builder *bb,
bb->commits[bb->commits_nr++] = r->item;
}
- trace2_data_intmax("pack-bitmap-write", the_repository,
+ trace2_data_intmax("pack-bitmap-write", writer->repo,
"num_selected_commits", writer->selected_nr);
- trace2_data_intmax("pack-bitmap-write", the_repository,
+ trace2_data_intmax("pack-bitmap-write", writer->repo,
"num_maximal_commits", num_maximal);
release_revisions(&revs);
@@ -460,7 +460,7 @@ static int fill_bitmap_tree(struct bitmap_writer *writer,
switch (object_type(entry.mode)) {
case OBJ_TREE:
if (fill_bitmap_tree(writer, bitmap,
- lookup_tree(the_repository, &entry.oid)) < 0)
+ lookup_tree(writer->repo, &entry.oid)) < 0)
return -1;
break;
case OBJ_BLOB:
@@ -536,7 +536,7 @@ static int fill_bitmap_commit(struct bitmap_writer *writer,
return -1;
bitmap_set(ent->bitmap, pos);
prio_queue_put(tree_queue,
- repo_get_commit_tree(the_repository, c));
+ repo_get_commit_tree(writer->repo, c));
}
for (p = c->parents; p; p = p->next) {
@@ -590,11 +590,11 @@ int bitmap_writer_build(struct bitmap_writer *writer)
int closed = 1; /* until proven otherwise */
if (writer->show_progress)
- writer->progress = start_progress(the_repository,
+ writer->progress = start_progress(writer->repo,
"Building bitmaps",
writer->selected_nr);
trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
- the_repository);
+ writer->repo);
old_bitmap = prepare_bitmap_git(writer->to_pack->repo);
if (old_bitmap)
@@ -645,10 +645,10 @@ int bitmap_writer_build(struct bitmap_writer *writer)
free(mapping);
trace2_region_leave("pack-bitmap-write", "building_bitmaps_total",
- the_repository);
- trace2_data_intmax("pack-bitmap-write", the_repository,
+ writer->repo);
+ trace2_data_intmax("pack-bitmap-write", writer->repo,
"building_bitmaps_reused", reused_bitmaps_nr);
- trace2_data_intmax("pack-bitmap-write", the_repository,
+ trace2_data_intmax("pack-bitmap-write", writer->repo,
"building_bitmaps_pseudo_merge_reused",
reused_pseudo_merge_bitmaps_nr);
@@ -711,7 +711,7 @@ void bitmap_writer_select_commits(struct bitmap_writer *writer,
}
if (writer->show_progress)
- writer->progress = start_progress(the_repository,
+ writer->progress = start_progress(writer->repo,
"Selecting bitmap commits", 0);
for (;;) {
@@ -960,7 +960,7 @@ static void write_lookup_table(struct bitmap_writer *writer, struct hashfile *f,
for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++)
table_inv[table[i]] = i;
- trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository);
+ trace2_region_enter("pack-bitmap-write", "writing_lookup_table", writer->repo);
for (i = 0; i < bitmap_writer_nr_selected_commits(writer); i++) {
struct bitmapped_commit *selected = &writer->selected[table[i]];
uint32_t xor_offset = selected->xor_offset;
@@ -987,7 +987,7 @@ static void write_lookup_table(struct bitmap_writer *writer, struct hashfile *f,
hashwrite_be64(f, (uint64_t)offsets[table[i]]);
hashwrite_be32(f, xor_row);
}
- trace2_region_leave("pack-bitmap-write", "writing_lookup_table", the_repository);
+ trace2_region_leave("pack-bitmap-write", "writing_lookup_table", writer->repo);
free(table);
free(table_inv);
@@ -1008,7 +1008,7 @@ static void write_hash_cache(struct hashfile *f,
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
const unsigned char *sha1)
{
- hashcpy(writer->pack_checksum, sha1, the_repository->hash_algo);
+ hashcpy(writer->pack_checksum, sha1, writer->repo->hash_algo);
}
void bitmap_writer_finish(struct bitmap_writer *writer,
@@ -1030,15 +1030,15 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
if (writer->pseudo_merges_nr)
options |= BITMAP_OPT_PSEUDO_MERGES;
- f = hashfd(the_repository->hash_algo, fd, tmp_file.buf);
+ f = hashfd(writer->repo->hash_algo, fd, tmp_file.buf);
memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
header.version = htons(default_version);
header.options = htons(flags | options);
header.entry_count = htonl(bitmap_writer_nr_selected_commits(writer));
- hashcpy(header.checksum, writer->pack_checksum, the_repository->hash_algo);
+ hashcpy(header.checksum, writer->pack_checksum, writer->repo->hash_algo);
- hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
+ hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + writer->repo->hash_algo->rawsz);
dump_bitmap(f, writer->commits);
dump_bitmap(f, writer->trees);
dump_bitmap(f, writer->blobs);
@@ -1072,7 +1072,7 @@ void bitmap_writer_finish(struct bitmap_writer *writer,
finalize_hashfile(f, NULL, FSYNC_COMPONENT_PACK_METADATA,
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
- if (adjust_shared_perm(the_repository, tmp_file.buf))
+ if (adjust_shared_perm(writer->repo, tmp_file.buf))
die_errno("unable to make temporary bitmap file readable");
if (rename(tmp_file.buf, filename))
diff --git a/pack-bitmap.h b/pack-bitmap.h
index d7f4b8b8e95..53cd42772f3 100644
--- a/pack-bitmap.h
+++ b/pack-bitmap.h
@@ -104,6 +104,7 @@ int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_i
off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
struct bitmap_writer {
+ struct repository *repo;
struct ewah_bitmap *commits;
struct ewah_bitmap *trees;
struct ewah_bitmap *blobs;
--
2.49.0.rc0.416.g627208d89d.dirty
next prev parent reply other threads:[~2025-03-06 15:10 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 ` [PATCH 03/12] pack-write: stop depending on `the_repository` and `the_hash_algo` Patrick Steinhardt
2025-03-04 18:46 ` 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 ` Patrick Steinhardt [this message]
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=20250306-b4-pks-objects-without-the-repository-v2-7-f3465327be69@pks.im \
--to=ps@pks.im \
--cc=git@vger.kernel.org \
--cc=jltobler@gmail.com \
--cc=karthik.188@gmail.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).