Skip to content

Commit ab1c6e1

Browse files
pks-tgitster
authored andcommitted
odb: introduce odb_write_object()
We do not have a backend-agnostic way to write objects into an object database. While there is `write_object_file()`, this function is rather specific to the loose object format. Introduce `odb_write_object()` to plug this gap. For now, this function is a simple wrapper around `write_object_file()` and doesn't even use the passed-in object database yet. This will change in subsequent commits, where `write_object_file()` is converted so that it works on top of an `odb_source`. `odb_write_object()` will then become responsible for deciding which source an object shall be written to. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0f9b189 commit ab1c6e1

21 files changed

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

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

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);

builtin/mktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static void write_tree(struct object_id *oid)
6363
strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
6464
}
6565

66-
write_object_file(buf.buf, buf.len, OBJ_TREE, oid);
66+
odb_write_object(the_repository->objects, buf.buf, buf.len, OBJ_TREE, oid);
6767
strbuf_release(&buf);
6868
}
6969

builtin/notes.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
229229

230230
static void write_note_data(struct note_data *d, struct object_id *oid)
231231
{
232-
if (write_object_file(d->buf.buf, d->buf.len, OBJ_BLOB, oid)) {
232+
if (odb_write_object(the_repository->objects, d->buf.buf,
233+
d->buf.len, OBJ_BLOB, oid)) {
233234
int status = die_message(_("unable to write note object"));
234235

235236
if (d->edit_path)

builtin/receive-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,8 +760,8 @@ static void prepare_push_cert_sha1(struct child_process *proc)
760760
int bogs /* beginning_of_gpg_sig */;
761761

762762
already_done = 1;
763-
if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
764-
&push_cert_oid))
763+
if (odb_write_object(the_repository->objects, push_cert.buf,
764+
push_cert.len, OBJ_BLOB, &push_cert_oid))
765765
oidclr(&push_cert_oid, the_repository->hash_algo);
766766

767767
memset(&sigcheck, '\0', sizeof(sigcheck));

builtin/replace.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
488488
return -1;
489489
}
490490

491-
if (write_object_file(buf.buf, buf.len, OBJ_COMMIT, &new_oid)) {
491+
if (odb_write_object(the_repository->objects, buf.buf,
492+
buf.len, OBJ_COMMIT, &new_oid)) {
492493
strbuf_release(&buf);
493494
return error(_("could not write replacement commit for: '%s'"),
494495
old_ref);

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
271271
struct object_id *compat_oid = NULL, compat_oid_buf;
272272
if (sign && do_sign(buf, &compat_oid, &compat_oid_buf) < 0)
273273
return error(_("unable to sign the tag"));
274-
if (write_object_file_flags(buf->buf, buf->len, OBJ_TAG, result,
275-
compat_oid, 0) < 0)
274+
if (odb_write_object_ext(the_repository->objects, buf->buf,
275+
buf->len, OBJ_TAG, result, compat_oid, 0) < 0)
276276
return error(_("unable to write tag file"));
277277
return 0;
278278
}

builtin/unpack-objects.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
204204
{
205205
struct object_id oid;
206206

207-
if (write_object_file(obj_buf->buffer, obj_buf->size,
208-
obj->type, &oid) < 0)
207+
if (odb_write_object(the_repository->objects, obj_buf->buffer, obj_buf->size,
208+
obj->type, &oid) < 0)
209209
die("failed to write object %s", oid_to_hex(&obj->oid));
210210
obj->flags |= FLAG_WRITTEN;
211211
}
@@ -272,16 +272,16 @@ static void write_object(unsigned nr, enum object_type type,
272272
void *buf, unsigned long size)
273273
{
274274
if (!strict) {
275-
if (write_object_file(buf, size, type,
276-
&obj_list[nr].oid) < 0)
275+
if (odb_write_object(the_repository->objects, buf, size, type,
276+
&obj_list[nr].oid) < 0)
277277
die("failed to write object");
278278
added_object(nr, type, buf, size);
279279
free(buf);
280280
obj_list[nr].obj = NULL;
281281
} else if (type == OBJ_BLOB) {
282282
struct blob *blob;
283-
if (write_object_file(buf, size, type,
284-
&obj_list[nr].oid) < 0)
283+
if (odb_write_object(the_repository->objects, buf, size, type,
284+
&obj_list[nr].oid) < 0)
285285
die("failed to write object");
286286
added_object(nr, type, buf, size);
287287
free(buf);

0 commit comments

Comments
 (0)