Skip to content

Commit d81712c

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

File tree

10 files changed

+31
-31
lines changed

10 files changed

+31
-31
lines changed

builtin/cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ static void batch_each_object(struct batch_options *opt,
848848
};
849849
struct bitmap_index *bitmap = prepare_bitmap_git(the_repository);
850850

851-
for_each_loose_object(batch_one_object_loose, &payload, 0);
851+
for_each_loose_object(the_repository->objects, batch_one_object_loose, &payload, 0);
852852

853853
if (bitmap && !for_each_bitmapped_object(bitmap, &opt->objects_filter,
854854
batch_one_object_bitmapped, &payload)) {

builtin/count-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int cmd_count_objects(int argc,
117117
report_linked_checkout_garbage(the_repository);
118118
}
119119

120-
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
120+
for_each_loose_file_in_source(the_repository->objects->sources,
121121
count_loose, count_cruft, NULL, NULL);
122122

123123
if (verbose) {

builtin/fsck.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,8 @@ static void check_connectivity(void)
393393
* and ignore any that weren't present in our earlier
394394
* traversal.
395395
*/
396-
for_each_loose_object(mark_loose_unreachable_referents, NULL, 0);
396+
for_each_loose_object(the_repository->objects,
397+
mark_loose_unreachable_referents, NULL, 0);
397398
for_each_packed_object(the_repository,
398399
mark_packed_unreachable_referents,
399400
NULL,
@@ -687,7 +688,7 @@ static int fsck_subdir(unsigned int nr, const char *path UNUSED, void *data)
687688
return 0;
688689
}
689690

690-
static void fsck_object_dir(const char *path)
691+
static void fsck_source(struct odb_source *source)
691692
{
692693
struct progress *progress = NULL;
693694
struct for_each_loose_cb cb_data = {
@@ -701,8 +702,8 @@ static void fsck_object_dir(const char *path)
701702
progress = start_progress(the_repository,
702703
_("Checking object directories"), 256);
703704

704-
for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
705-
&cb_data);
705+
for_each_loose_file_in_source(source, fsck_loose,
706+
fsck_cruft, fsck_subdir, &cb_data);
706707
display_progress(progress, 256);
707708
stop_progress(&progress);
708709
}
@@ -994,13 +995,14 @@ int cmd_fsck(int argc,
994995
fsck_refs(the_repository);
995996

996997
if (connectivity_only) {
997-
for_each_loose_object(mark_loose_for_connectivity, NULL, 0);
998+
for_each_loose_object(the_repository->objects,
999+
mark_loose_for_connectivity, NULL, 0);
9981000
for_each_packed_object(the_repository,
9991001
mark_packed_for_connectivity, NULL, 0);
10001002
} else {
10011003
odb_prepare_alternates(the_repository->objects);
10021004
for (source = the_repository->objects->sources; source; source = source->next)
1003-
fsck_object_dir(source->path);
1005+
fsck_source(source);
10041006

10051007
if (check_full) {
10061008
struct packed_git *p;

builtin/gc.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
13011301
if (loose_object_auto_limit < 0)
13021302
return 1;
13031303

1304-
return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
1304+
return for_each_loose_file_in_source(the_repository->objects->sources,
13051305
loose_object_count,
13061306
NULL, NULL, &count);
13071307
}
@@ -1336,7 +1336,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13361336
* Do not start pack-objects process
13371337
* if there are no loose objects.
13381338
*/
1339-
if (!for_each_loose_file_in_objdir(r->objects->sources->path,
1339+
if (!for_each_loose_file_in_source(r->objects->sources,
13401340
bail_on_loose,
13411341
NULL, NULL, NULL))
13421342
return 0;
@@ -1376,11 +1376,9 @@ static int pack_loose(struct maintenance_run_opts *opts)
13761376
else if (data.batch_size > 0)
13771377
data.batch_size--; /* Decrease for equality on limit. */
13781378

1379-
for_each_loose_file_in_objdir(r->objects->sources->path,
1379+
for_each_loose_file_in_source(r->objects->sources,
13801380
write_loose_object_to_stdin,
1381-
NULL,
1382-
NULL,
1383-
&data);
1381+
NULL, NULL, &data);
13841382

13851383
fclose(data.in);
13861384

builtin/pack-objects.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4342,9 +4342,8 @@ static int add_loose_object(const struct object_id *oid, const char *path,
43424342
*/
43434343
static void add_unreachable_loose_objects(void)
43444344
{
4345-
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
4346-
add_loose_object,
4347-
NULL, NULL, NULL);
4345+
for_each_loose_file_in_source(the_repository->objects->sources,
4346+
add_loose_object, NULL, NULL, NULL);
43484347
}
43494348

43504349
static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid)

builtin/prune.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ int cmd_prune(int argc,
200200
revs.exclude_promisor_objects = 1;
201201
}
202202

203-
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
203+
for_each_loose_file_in_source(the_repository->objects->sources,
204204
prune_object, prune_cruft, prune_subdir, &revs);
205205

206206
prune_packed_objects(show_only ? PRUNE_PACKED_DRY_RUN : 0);

object-file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ static int for_each_file_in_obj_subdir(unsigned int subdir_nr,
13881388
return r;
13891389
}
13901390

1391-
int for_each_loose_file_in_objdir(const char *path,
1391+
int for_each_loose_file_in_source(struct odb_source *source,
13921392
each_loose_object_fn obj_cb,
13931393
each_loose_cruft_fn cruft_cb,
13941394
each_loose_subdir_fn subdir_cb,
@@ -1397,11 +1397,10 @@ int for_each_loose_file_in_objdir(const char *path,
13971397
struct strbuf buf = STRBUF_INIT;
13981398
int r;
13991399

1400-
strbuf_addstr(&buf, path);
1400+
strbuf_addstr(&buf, source->path);
14011401
for (int i = 0; i < 256; i++) {
1402-
r = for_each_file_in_obj_subdir(i, &buf, the_repository->hash_algo,
1403-
obj_cb, cruft_cb,
1404-
subdir_cb, data);
1402+
r = for_each_file_in_obj_subdir(i, &buf, source->odb->repo->hash_algo,
1403+
obj_cb, cruft_cb, subdir_cb, data);
14051404
if (r)
14061405
break;
14071406
}
@@ -1410,14 +1409,15 @@ int for_each_loose_file_in_objdir(const char *path,
14101409
return r;
14111410
}
14121411

1413-
int for_each_loose_object(each_loose_object_fn cb, void *data,
1412+
int for_each_loose_object(struct object_database *odb,
1413+
each_loose_object_fn cb, void *data,
14141414
enum for_each_object_flags flags)
14151415
{
14161416
struct odb_source *source;
14171417

1418-
odb_prepare_alternates(the_repository->objects);
1419-
for (source = the_repository->objects->sources; source; source = source->next) {
1420-
int r = for_each_loose_file_in_objdir(source->path, cb, NULL,
1418+
odb_prepare_alternates(odb);
1419+
for (source = odb->sources; source; source = source->next) {
1420+
int r = for_each_loose_file_in_source(source, cb, NULL,
14211421
NULL, data);
14221422
if (r)
14231423
return r;

object-file.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ typedef int each_loose_cruft_fn(const char *basename,
8686
typedef int each_loose_subdir_fn(unsigned int nr,
8787
const char *path,
8888
void *data);
89-
int for_each_loose_file_in_objdir(const char *path,
89+
int for_each_loose_file_in_source(struct odb_source *source,
9090
each_loose_object_fn obj_cb,
9191
each_loose_cruft_fn cruft_cb,
9292
each_loose_subdir_fn subdir_cb,
@@ -99,7 +99,8 @@ int for_each_loose_file_in_objdir(const char *path,
9999
*
100100
* Any flags specific to packs are ignored.
101101
*/
102-
int for_each_loose_object(each_loose_object_fn, void *,
102+
int for_each_loose_object(struct object_database *odb,
103+
each_loose_object_fn, void *,
103104
enum for_each_object_flags flags);
104105

105106

prune-packed.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void prune_packed_objects(int opts)
4040
progress = start_delayed_progress(the_repository,
4141
_("Removing duplicate objects"), 256);
4242

43-
for_each_loose_file_in_objdir(repo_get_object_directory(the_repository),
43+
for_each_loose_file_in_source(the_repository->objects->sources,
4444
prune_object, NULL, prune_subdir, &opts);
4545

4646
/* Ensure we show 100% before finishing progress */

reachable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ int add_unseen_recent_objects_to_traversal(struct rev_info *revs,
319319
oidset_init(&data.extra_recent_oids, 0);
320320
data.extra_recent_oids_loaded = 0;
321321

322-
r = for_each_loose_object(add_recent_loose, &data,
322+
r = for_each_loose_object(the_repository->objects, add_recent_loose, &data,
323323
FOR_EACH_OBJECT_LOCAL_ONLY);
324324
if (r)
325325
goto done;

0 commit comments

Comments
 (0)