aboutsummaryrefslogtreecommitdiffstats
path: root/builtin
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-07-17 06:56:35 +0200
committerJunio C Hamano <gitster@pobox.com>2025-07-16 22:16:15 -0700
commitab1c6e1d12e869cbca3ea7f8a4e767e45fd14c49 (patch)
tree32a6815af9b9ec50578da260882e52ab9de8182f /builtin
parent0f9b18935745fcdebcad613a6e3e52db5b29b1d4 (diff)
downloadgit-ab1c6e1d12e869cbca3ea7f8a4e767e45fd14c49.tar.gz
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 <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/checkout.c2
-rw-r--r--builtin/merge-file.c3
-rw-r--r--builtin/mktag.c2
-rw-r--r--builtin/mktree.c2
-rw-r--r--builtin/notes.c3
-rw-r--r--builtin/receive-pack.c4
-rw-r--r--builtin/replace.c3
-rw-r--r--builtin/tag.c4
-rw-r--r--builtin/unpack-objects.c12
9 files changed, 19 insertions, 16 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 0a90b86a72..f95eb64ffb 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -320,7 +320,7 @@ static int checkout_merged(int pos, const struct checkout *state,
* (it also writes the merge result to the object database even
* when it may contain conflicts).
*/
- if (write_object_file(result_buf.ptr, result_buf.size, OBJ_BLOB, &oid))
+ if (odb_write_object(the_repository->objects, result_buf.ptr, result_buf.size, OBJ_BLOB, &oid))
die(_("Unable to add merge result for '%s'"), path);
free(result_buf.ptr);
ce = make_transient_cache_entry(mode, &oid, path, 2, ce_mem_pool);
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 9464f27562..b8b25a14e6 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -155,7 +155,8 @@ int cmd_merge_file(int argc,
if (object_id && !to_stdout) {
struct object_id oid;
if (result.size) {
- if (write_object_file(result.ptr, result.size, OBJ_BLOB, &oid) < 0)
+ if (odb_write_object(the_repository->objects, result.ptr,
+ result.size, OBJ_BLOB, &oid) < 0)
ret = error(_("Could not write object file"));
} else {
oidcpy(&oid, the_hash_algo->empty_blob);
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 27e649736c..12552bbb21 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -106,7 +106,7 @@ int cmd_mktag(int argc,
if (verify_object_in_tag(&tagged_oid, &tagged_type) < 0)
die(_("tag on stdin did not refer to a valid object"));
- if (write_object_file(buf.buf, buf.len, OBJ_TAG, &result) < 0)
+ if (odb_write_object(the_repository->objects, buf.buf, buf.len, OBJ_TAG, &result) < 0)
die(_("unable to write tag file"));
strbuf_release(&buf);
diff --git a/builtin/mktree.c b/builtin/mktree.c
index 81df7f6099..12772303f5 100644
--- a/builtin/mktree.c
+++ b/builtin/mktree.c
@@ -63,7 +63,7 @@ static void write_tree(struct object_id *oid)
strbuf_add(&buf, ent->oid.hash, the_hash_algo->rawsz);
}
- write_object_file(buf.buf, buf.len, OBJ_TREE, oid);
+ odb_write_object(the_repository->objects, buf.buf, buf.len, OBJ_TREE, oid);
strbuf_release(&buf);
}
diff --git a/builtin/notes.c b/builtin/notes.c
index a9529b1696..a3580b4aa3 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -229,7 +229,8 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
static void write_note_data(struct note_data *d, struct object_id *oid)
{
- if (write_object_file(d->buf.buf, d->buf.len, OBJ_BLOB, oid)) {
+ if (odb_write_object(the_repository->objects, d->buf.buf,
+ d->buf.len, OBJ_BLOB, oid)) {
int status = die_message(_("unable to write note object"));
if (d->edit_path)
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index dd1d1446e7..bd9baf81e5 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -760,8 +760,8 @@ static void prepare_push_cert_sha1(struct child_process *proc)
int bogs /* beginning_of_gpg_sig */;
already_done = 1;
- if (write_object_file(push_cert.buf, push_cert.len, OBJ_BLOB,
- &push_cert_oid))
+ if (odb_write_object(the_repository->objects, push_cert.buf,
+ push_cert.len, OBJ_BLOB, &push_cert_oid))
oidclr(&push_cert_oid, the_repository->hash_algo);
memset(&sigcheck, '\0', sizeof(sigcheck));
diff --git a/builtin/replace.c b/builtin/replace.c
index 5ff2ab723c..7c46d05ec1 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -488,7 +488,8 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
return -1;
}
- if (write_object_file(buf.buf, buf.len, OBJ_COMMIT, &new_oid)) {
+ if (odb_write_object(the_repository->objects, buf.buf,
+ buf.len, OBJ_COMMIT, &new_oid)) {
strbuf_release(&buf);
return error(_("could not write replacement commit for: '%s'"),
old_ref);
diff --git a/builtin/tag.c b/builtin/tag.c
index 46cbf892e3..8fbe9e7be0 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -271,8 +271,8 @@ static int build_tag_object(struct strbuf *buf, int sign, struct object_id *resu
struct object_id *compat_oid = NULL, compat_oid_buf;
if (sign && do_sign(buf, &compat_oid, &compat_oid_buf) < 0)
return error(_("unable to sign the tag"));
- if (write_object_file_flags(buf->buf, buf->len, OBJ_TAG, result,
- compat_oid, 0) < 0)
+ if (odb_write_object_ext(the_repository->objects, buf->buf,
+ buf->len, OBJ_TAG, result, compat_oid, 0) < 0)
return error(_("unable to write tag file"));
return 0;
}
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index a69d59eb50..1a4fbef36f 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -204,8 +204,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)
{
struct object_id oid;
- if (write_object_file(obj_buf->buffer, obj_buf->size,
- obj->type, &oid) < 0)
+ if (odb_write_object(the_repository->objects, obj_buf->buffer, obj_buf->size,
+ obj->type, &oid) < 0)
die("failed to write object %s", oid_to_hex(&obj->oid));
obj->flags |= FLAG_WRITTEN;
}
@@ -272,16 +272,16 @@ static void write_object(unsigned nr, enum object_type type,
void *buf, unsigned long size)
{
if (!strict) {
- if (write_object_file(buf, size, type,
- &obj_list[nr].oid) < 0)
+ if (odb_write_object(the_repository->objects, buf, size, type,
+ &obj_list[nr].oid) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);
obj_list[nr].obj = NULL;
} else if (type == OBJ_BLOB) {
struct blob *blob;
- if (write_object_file(buf, size, type,
- &obj_list[nr].oid) < 0)
+ if (odb_write_object(the_repository->objects, buf, size, type,
+ &obj_list[nr].oid) < 0)
die("failed to write object");
added_object(nr, type, buf, size);
free(buf);