Skip to content

Commit 4ce0caa

Browse files
committed
Merge branch 'ps/object-file-wo-the-repository'
Reduce implicit assumption and dependence on the_repository in the object-file subsystem. * ps/object-file-wo-the-repository: object-file: get rid of `the_repository` in index-related functions object-file: get rid of `the_repository` in `force_object_loose()` object-file: get rid of `the_repository` in `read_loose_object()` object-file: get rid of `the_repository` in loose object iterators object-file: remove declaration for `for_each_file_in_obj_subdir()` object-file: inline `for_each_loose_file_in_objdir_buf()` object-file: get rid of `the_repository` when writing objects odb: introduce `odb_write_object()` loose: write loose objects map via their source object-file: get rid of `the_repository` in `finalize_object_file()` object-file: get rid of `the_repository` in `loose_object_info()` object-file: get rid of `the_repository` when freshening objects object-file: inline `check_and_freshen()` functions object-file: get rid of `the_repository` in `has_loose_object()` object-file: stop using `the_hash_algo` object-file: fix -Wsign-compare warnings
2 parents 112648d + 5f2e994 commit 4ce0caa

39 files changed

+332
-293
lines changed

apply.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,7 +3621,7 @@ static int try_threeway(struct apply_state *state,
36213621

36223622
/* Preimage the patch was prepared for */
36233623
if (patch->is_new)
3624-
write_object_file("", 0, OBJ_BLOB, &pre_oid);
3624+
odb_write_object(the_repository->objects, "", 0, OBJ_BLOB, &pre_oid);
36253625
else if (repo_get_oid(the_repository, patch->old_oid_prefix, &pre_oid) ||
36263626
read_blob_object(&buf, &pre_oid, patch->old_mode))
36273627
return error(_("repository lacks the necessary blob to perform 3-way merge."));
@@ -3637,7 +3637,8 @@ static int try_threeway(struct apply_state *state,
36373637
return -1;
36383638
}
36393639
/* post_oid is theirs */
3640-
write_object_file(tmp_image.buf.buf, tmp_image.buf.len, OBJ_BLOB, &post_oid);
3640+
odb_write_object(the_repository->objects, tmp_image.buf.buf,
3641+
tmp_image.buf.len, OBJ_BLOB, &post_oid);
36413642
image_clear(&tmp_image);
36423643

36433644
/* our_oid is ours */
@@ -3650,7 +3651,8 @@ static int try_threeway(struct apply_state *state,
36503651
return error(_("cannot read the current contents of '%s'"),
36513652
patch->old_name);
36523653
}
3653-
write_object_file(tmp_image.buf.buf, tmp_image.buf.len, OBJ_BLOB, &our_oid);
3654+
odb_write_object(the_repository->objects, tmp_image.buf.buf,
3655+
tmp_image.buf.len, OBJ_BLOB, &our_oid);
36543656
image_clear(&tmp_image);
36553657

36563658
/* in-core three-way merge between post and our using pre as base */
@@ -4360,7 +4362,8 @@ static int add_index_file(struct apply_state *state,
43604362
}
43614363
fill_stat_cache_info(state->repo->index, ce, &st);
43624364
}
4363-
if (write_object_file(buf, size, OBJ_BLOB, &ce->oid) < 0) {
4365+
if (odb_write_object(the_repository->objects, buf, size,
4366+
OBJ_BLOB, &ce->oid) < 0) {
43644367
discard_cache_entry(ce);
43654368
return error(_("unable to create backing store "
43664369
"for newly created file %s"), path);

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/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ static int checkout_merged(int pos, const struct checkout *state,
327327
* (it also writes the merge result to the object database even
328328
* when it may contain conflicts).
329329
*/
330-
if (write_object_file(result_buf.ptr, result_buf.size, OBJ_BLOB, &oid))
330+
if (odb_write_object(the_repository->objects, result_buf.ptr, result_buf.size, OBJ_BLOB, &oid))
331331
die(_("Unable to add merge result for '%s'"), path);
332332
free(result_buf.ptr);
333333
ce = make_transient_cache_entry(mode, &oid, path, 2, ce_mem_pool);

builtin/count-objects.c

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

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

124124
if (verbose) {

builtin/fast-import.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,11 @@ static char *keep_pack(const char *curr_index_name)
822822
die_errno("failed to write keep file");
823823

824824
odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
825-
if (finalize_object_file(pack_data->pack_name, name.buf))
825+
if (finalize_object_file(pack_data->repo, pack_data->pack_name, name.buf))
826826
die("cannot store pack file");
827827

828828
odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx");
829-
if (finalize_object_file(curr_index_name, name.buf))
829+
if (finalize_object_file(pack_data->repo, curr_index_name, name.buf))
830830
die("cannot store index file");
831831
free((void *)curr_index_name);
832832
return strbuf_detach(&name, NULL);

builtin/fsck.c

Lines changed: 9 additions & 7 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,
@@ -632,7 +633,7 @@ static int fsck_loose(const struct object_id *oid, const char *path,
632633
oi.sizep = &size;
633634
oi.typep = &type;
634635

635-
if (read_loose_object(path, oid, &real_oid, &contents, &oi) < 0) {
636+
if (read_loose_object(the_repository, path, oid, &real_oid, &contents, &oi) < 0) {
636637
if (contents && !oideq(&real_oid, oid))
637638
err = error(_("%s: hash-path mismatch, found at: %s"),
638639
oid_to_hex(&real_oid), path);
@@ -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
@@ -1309,7 +1309,7 @@ static int loose_object_auto_condition(struct gc_config *cfg UNUSED)
13091309
if (loose_object_auto_limit < 0)
13101310
return 1;
13111311

1312-
return for_each_loose_file_in_objdir(the_repository->objects->sources->path,
1312+
return for_each_loose_file_in_source(the_repository->objects->sources,
13131313
loose_object_count,
13141314
NULL, NULL, &count);
13151315
}
@@ -1344,7 +1344,7 @@ static int pack_loose(struct maintenance_run_opts *opts)
13441344
* Do not start pack-objects process
13451345
* if there are no loose objects.
13461346
*/
1347-
if (!for_each_loose_file_in_objdir(r->objects->sources->path,
1347+
if (!for_each_loose_file_in_source(r->objects->sources,
13481348
bail_on_loose,
13491349
NULL, NULL, NULL))
13501350
return 0;
@@ -1384,11 +1384,9 @@ static int pack_loose(struct maintenance_run_opts *opts)
13841384
else if (data.batch_size > 0)
13851385
data.batch_size--; /* Decrease for equality on limit. */
13861386

1387-
for_each_loose_file_in_objdir(r->objects->sources->path,
1387+
for_each_loose_file_in_source(r->objects->sources,
13881388
write_loose_object_to_stdin,
1389-
NULL,
1390-
NULL,
1391-
&data);
1389+
NULL, NULL, &data);
13921390

13931391
fclose(data.in);
13941392

builtin/index-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,7 @@ static void rename_tmp_packfile(const char **final_name,
15981598
if (!*final_name || strcmp(*final_name, curr_name)) {
15991599
if (!*final_name)
16001600
*final_name = odb_pack_name(the_repository, name, hash, ext);
1601-
if (finalize_object_file(curr_name, *final_name))
1601+
if (finalize_object_file(the_repository, curr_name, *final_name))
16021602
die(_("unable to rename temporary '*.%s' file to '%s'"),
16031603
ext, *final_name);
16041604
} else if (make_read_only_if_same) {

builtin/merge-file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ int cmd_merge_file(int argc,
155155
if (object_id && !to_stdout) {
156156
struct object_id oid;
157157
if (result.size) {
158-
if (write_object_file(result.ptr, result.size, OBJ_BLOB, &oid) < 0)
158+
if (odb_write_object(the_repository->objects, result.ptr,
159+
result.size, OBJ_BLOB, &oid) < 0)
159160
ret = error(_("Could not write object file"));
160161
} else {
161162
oidcpy(&oid, the_hash_algo->empty_blob);

builtin/mktag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ int cmd_mktag(int argc,
106106
if (verify_object_in_tag(&tagged_oid, &tagged_type) < 0)
107107
die(_("tag on stdin did not refer to a valid object"));
108108

109-
if (write_object_file(buf.buf, buf.len, OBJ_TAG, &result) < 0)
109+
if (odb_write_object(the_repository->objects, buf.buf, buf.len, OBJ_TAG, &result) < 0)
110110
die(_("unable to write tag file"));
111111

112112
strbuf_release(&buf);

0 commit comments

Comments
 (0)