aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-07-17 06:56:39 +0200
committerJunio C Hamano <gitster@pobox.com>2025-07-16 22:16:17 -0700
commitd81712ce65f7ee59ce88c8b74f09b6e6456a6f3c (patch)
treec4489f5d836c944447042afe0b1c364b4bb81c4a /builtin
parent83439299f1326c7471f5c7595c96d14b65a71879 (diff)
downloadgit-d81712ce65f7ee59ce88c8b74f09b6e6456a6f3c.tar.gz
object-file: get rid of `the_repository` in loose object iterators
The iterators for loose objects still rely on `the_repository`. Refactor them: - `for_each_loose_file_in_objdir()` is refactored so that the caller is now expected to pass an `odb_source` as parameter instead of the path to that source. Furthermore, it is renamed accordingly to `for_each_loose_file_in_source()`. - `for_each_loose_object()` is refactored to take in an object database now and calls the above function in a loop. This allows us to get rid of the global dependency. Adjust callers accordingly. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/cat-file.c2
-rw-r--r--builtin/count-objects.c2
-rw-r--r--builtin/fsck.c14
-rw-r--r--builtin/gc.c10
-rw-r--r--builtin/pack-objects.c5
-rw-r--r--builtin/prune.c2
6 files changed, 17 insertions, 18 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 2492a0b6f3..aa1498aa60 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -848,7 +848,7 @@ static void batch_each_object(struct batch_options *opt,
};
struct bitmap_index *bitmap = prepare_bitmap_git(the_repository);
- for_each_loose_object(batch_one_object_loose, &payload, 0);
+ for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0);
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
batch_one_object_bitmapped, &payload)) {
diff --git a/builtin/count-objects.c b/builtin/count-objects.c
index f687647931..e70a01c628 100644
--- a/builtin/count-objects.c
+++ b/builtin/count-objects.c
@@ -117,7 +117,7 @@ int cmd_count_objects(int argc,
report_linked_checkout_garbage(the_repository);
}
- for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
+ for_each_loose_file_in_source(the_repository->objects->sources,
count_loose, count_cruft, NULL, NULL);
if (verbose) {
diff --git a/builtin/fsck.c b/builtin/fsck.c
index 0084cf7400..f0854ce5d8 100644
--- a/builtin/fsck.c
+++ b/builtin/fsck.c
@@ -393,7 +393,8 @@ static void check_connectivity(void)
* and ignore any that weren't present in our earlier
* traversal.
*/
- for_each_loose_object(mark_loose_unreachable_referents, NULL, 0);
+ for_each_loose_object(the_repository->objects,
+ mark_loose_unreachable_referents, NULL, 0);
for_each_packed_object(the_repository,
mark_packed_unreachable_referents,
NULL,
@@ -687,7 +688,7 @@ static int fsck_subdir(unsigned int nr, const char *path UNUSED, void *data)
return 0;
}
-static void fsck_object_dir(const char *path)
+static void fsck_source(struct odb_source *source)
{
struct progress *progress = NULL;
struct for_each_loose_cb cb_data = {
@@ -701,8 +702,8 @@ static void fsck_object_dir(const char *path)
progress = start_progress(the_repository,
_("Checking object directories"), 256);
- for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
- &cb_data);
+ for_each_loose_file_in_source(source, fsck_loose,
+ fsck_cruft, fsck_subdir, &cb_data);
display_progress(progress, 256);
stop_progress(&progress);
}
@@ -994,13 +995,14 @@ int cmd_fsck(int argc,
fsck_refs(the_repository);
if (connectivity_only) {
- for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
+ for_each_loose_object(the_repository->objects,
+ mark_loose_for_connectivity, NULL, 0);
for_each_packed_object(the_repository,
mark_packed_for_connectivity, NULL, 0);
} else {
odb_prepare_alternates(the_repository->objects);
for (source = the_repository->objects->sources; source; source = source->next)
- fsck_object_dir(source->path);
+ fsck_source(source);
if (check_full) {
struct packed_git *p;
diff --git a/builtin/gc.c b/builtin/gc.c
index 21bd44e164..6eefefc63d 100644
--- a/builtin/gc.c
+++ b/builtin/gc.c
@@ -1301,7 +1301,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
if (loose_object_auto_limit < 0)
return 1;
- return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
+ return for_each_loose_file_in_source(the_repository->objects->sources,
loose_object_count,
NULL, NULL, &count);
}
@@ -1336,7 +1336,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
* Do not start pack-objects process
* if there are no loose objects.
*/
- if (!for_each_loose_file_in_objdir(r->objects->sources->path,
+ if (!for_each_loose_file_in_source(r->objects->sources,
bail_on_loose,
NULL, NULL, NULL))
return 0;
@@ -1376,11 +1376,9 @@ static int pack_loose(struct maintenance_run_opts *opts)
else if (data.batch_size > 0)
data.batch_size--; /* Decrease for equality on limit. */
- for_each_loose_file_in_objdir(r->objects->sources->path,
+ for_each_loose_file_in_source(r->objects->sources,
write_loose_object_to_stdin,
- NULL,
- NULL,
- &data);
+ NULL, NULL, &data);
fclose(data.in);
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index e8e85d8278..9e85293730 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -4342,9 +4342,8 @@ static int add_loose_object(const struct object_id *oid, const char *path,
*/
static void add_unreachable_loose_objects(void)
{
- for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
- add_loose_object,
- NULL, NULL, NULL);
+ for_each_loose_file_in_source(the_repository->objects->sources,
+ add_loose_object, NULL, NULL, NULL);
}
static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)
diff --git a/builtin/prune.c b/builtin/prune.c
index 339017c7cc..bf5d3bb152 100644
--- a/builtin/prune.c
+++ b/builtin/prune.c
@@ -200,7 +200,7 @@ int cmd_prune(int argc,
revs.exclude_promisor_objects = 1;
}
- for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
+ for_each_loose_file_in_source(the_repository->objects->sources,
prune_object, prune_cruft, prune_subdir, &revs);
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);