/* Preimage the patch was prepared for */
if (patch->is_new)
- write_object_file("", 0, OBJ_BLOB, &pre_oid);
+ odb_write_object(the_repository->objects, "", 0, OBJ_BLOB, &pre_oid);
else if (repo_get_oid(the_repository, patch->old_oid_prefix, &pre_oid) ||
read_blob_object(&buf, &pre_oid, patch->old_mode))
return error(_("repository lacks the necessary blob to perform 3-way merge."));
return -1;
}
/* post_oid is theirs */
- write_object_file(tmp_image.buf.buf, tmp_image.buf.len, OBJ_BLOB, &post_oid);
+ odb_write_object(the_repository->objects, tmp_image.buf.buf,
+ tmp_image.buf.len, OBJ_BLOB, &post_oid);
image_clear(&tmp_image);
/* our_oid is ours */
return error(_("cannot read the current contents of '%s'"),
patch->old_name);
}
- write_object_file(tmp_image.buf.buf, tmp_image.buf.len, OBJ_BLOB, &our_oid);
+ odb_write_object(the_repository->objects, tmp_image.buf.buf,
+ tmp_image.buf.len, OBJ_BLOB, &our_oid);
image_clear(&tmp_image);
/* in-core three-way merge between post and our using pre as base */
}
fill_stat_cache_info(state->repo->index, ce, &st);
}
- if (write_object_file(buf, size, OBJ_BLOB, &ce->oid) < 0) {
+ if (odb_write_object(the_repository->objects, buf, size,
+ OBJ_BLOB, &ce->oid) < 0) {
discard_cache_entry(ce);
return error(_("unable to create backing store "
"for newly created file %s"), path);
* (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);
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);
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);
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);
}
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)
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));
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);
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;
}
{
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;
}
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);
} else if (dryrun) {
hash_object_file(the_hash_algo, buffer.buf, buffer.len,
OBJ_TREE, &it->oid);
- } else if (write_object_file_flags(buffer.buf, buffer.len, OBJ_TREE,
- &it->oid, NULL, flags & WRITE_TREE_SILENT
- ? WRITE_OBJECT_FILE_SILENT : 0)) {
+ } else if (odb_write_object_ext(the_repository->objects, buffer.buf, buffer.len, OBJ_TREE,
+ &it->oid, NULL, flags & WRITE_TREE_SILENT ? WRITE_OBJECT_SILENT : 0)) {
strbuf_release(&buffer);
return -1;
}
compat_oid = &compat_oid_buf;
}
- result = write_object_file_flags(buffer.buf, buffer.len, OBJ_COMMIT,
- ret, compat_oid, 0);
+ result = odb_write_object_ext(the_repository->objects, buffer.buf, buffer.len,
+ OBJ_COMMIT, ret, compat_oid, 0);
out:
free(parent_buf);
strbuf_release(&buffer);
rewrite_with = oid2;
}
hashcpy(rewrite_here, rewrite_with->hash, r->hash_algo);
- status = write_object_file(buf, sz, OBJ_TREE, result);
+ status = odb_write_object(r->objects, buf, sz, OBJ_TREE, result);
free(buf);
return status;
}
}
if (!ret && record_object &&
- write_object_file(result_buf.ptr, result_buf.size,
- OBJ_BLOB, &result->oid)) {
+ odb_write_object(the_repository->objects, result_buf.ptr, result_buf.size,
+ OBJ_BLOB, &result->oid)) {
path_msg(opt, ERROR_OBJECT_WRITE_FAILED, 0,
pathnames[0], pathnames[1], pathnames[2], NULL,
_("error: unable to add %s to database"), path);
}
/* Write this object file out, and record in result_oid */
- if (write_object_file(buf.buf, buf.len, OBJ_TREE, result_oid))
+ if (odb_write_object(the_repository->objects, buf.buf,
+ buf.len, OBJ_TREE, result_oid))
ret = -1;
strbuf_release(&buf);
return ret;
{
struct object_id value_oid;
- if (write_object_file(data, size, OBJ_BLOB, &value_oid) < 0)
+ if (odb_write_object(the_repository->objects, data,
+ size, OBJ_BLOB, &value_oid) < 0)
return -1;
return add_note(&c->tree, key_oid, &value_oid, NULL);
}
ret = tree_write_stack_finish_subtree(n);
if (ret)
return ret;
- ret = write_object_file(n->buf.buf, n->buf.len, OBJ_TREE, &s);
+ ret = odb_write_object(the_repository->objects, n->buf.buf,
+ n->buf.len, OBJ_TREE, &s);
if (ret)
return ret;
strbuf_release(&n->buf);
free(new_msg);
/* create a new blob object from buf */
- ret = write_object_file(buf, buf_len, OBJ_BLOB, cur_oid);
+ ret = odb_write_object(the_repository->objects, buf,
+ buf_len, OBJ_BLOB, cur_oid);
free(buf);
return ret;
}
string_list_join_lines_helper, &buf))
goto out;
- ret = write_object_file(buf.buf, buf.len, OBJ_BLOB, cur_oid);
+ ret = odb_write_object(the_repository->objects, buf.buf,
+ buf.len, OBJ_BLOB, cur_oid);
out:
strbuf_release(&buf);
ret = for_each_note(t, flags, write_each_note, &cb_data) ||
write_each_non_note_until(NULL, &cb_data) ||
tree_write_stack_finish_subtree(&root) ||
- write_object_file(root.buf.buf, root.buf.len, OBJ_TREE, result);
+ odb_write_object(the_repository->objects, root.buf.buf,
+ root.buf.len, OBJ_TREE, result);
strbuf_release(&root.buf);
return ret;
}
fd = create_tmpfile(tmp_file, filename);
if (fd < 0) {
- if (flags & WRITE_OBJECT_FILE_SILENT)
+ if (flags & WRITE_OBJECT_SILENT)
return -1;
else if (errno == EACCES)
return error(_("insufficient permission for adding "
utb.actime = mtime;
utb.modtime = mtime;
if (utime(tmp_file.buf, &utb) < 0 &&
- !(flags & WRITE_OBJECT_FILE_SILENT))
+ !(flags & WRITE_OBJECT_SILENT))
warning_errno(_("failed utime() on %s"), tmp_file.buf);
}
return err;
}
-int write_object_file_flags(const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- struct object_id *compat_oid_in, unsigned flags)
+int write_object_file(const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ struct object_id *compat_oid_in, unsigned flags)
{
struct repository *repo = the_repository;
const struct git_hash_algo *algo = repo->hash_algo;
}
if (write_object)
- ret = write_object_file(buf, size, type, oid);
+ ret = odb_write_object(istate->repo->objects, buf, size, type, oid);
else
hash_object_file(istate->repo->hash_algo, buf, size, type, oid);
get_conv_flags(flags));
if (write_object)
- ret = write_object_file(sbuf.buf, sbuf.len, OBJ_BLOB,
- oid);
+ ret = odb_write_object(istate->repo->objects, sbuf.buf, sbuf.len, OBJ_BLOB,
+ oid);
else
hash_object_file(istate->repo->hash_algo, sbuf.buf, sbuf.len, OBJ_BLOB,
oid);
if (!(flags & INDEX_WRITE_OBJECT))
hash_object_file(istate->repo->hash_algo, sb.buf, sb.len,
OBJ_BLOB, oid);
- else if (write_object_file(sb.buf, sb.len, OBJ_BLOB, oid))
+ else if (odb_write_object(the_repository->objects, sb.buf, sb.len, OBJ_BLOB, oid))
rc = error(_("%s: failed to insert into database"), path);
strbuf_release(&sb);
break;
struct object_info;
int parse_loose_header(const char *hdr, struct object_info *oi);
-enum {
- /*
- * By default, `write_object_file()` does not actually write
- * anything into the object store, but only computes the object ID.
- * This flag changes that so that the object will be written as a loose
- * object and persisted.
- */
- WRITE_OBJECT_FILE_PERSIST = (1 << 0),
-
- /*
- * Do not print an error in case something gose wrong.
- */
- WRITE_OBJECT_FILE_SILENT = (1 << 1),
-};
-
-int write_object_file_flags(const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid,
- struct object_id *compat_oid_in, unsigned flags);
-static inline int write_object_file(const void *buf, unsigned long len,
- enum object_type type, struct object_id *oid)
-{
- return write_object_file_flags(buf, len, type, oid, NULL, 0);
-}
+int write_object_file(const void *buf, unsigned long len,
+ enum object_type type, struct object_id *oid,
+ struct object_id *compat_oid_in, unsigned flags);
struct input_stream {
const void *(*read)(struct input_stream *, unsigned long *len);
type_name(expect));
}
+int odb_write_object_ext(struct object_database *odb UNUSED,
+ const void *buf, unsigned long len,
+ enum object_type type,
+ struct object_id *oid,
+ struct object_id *compat_oid,
+ unsigned flags)
+{
+ return write_object_file(buf, len, type, oid, compat_oid, flags);
+}
+
struct object_database *odb_new(struct repository *repo)
{
struct object_database *o = xmalloc(sizeof(*o));
FOR_EACH_OBJECT_SKIP_ON_DISK_KEPT_PACKS = (1<<4),
};
+enum {
+ /*
+ * By default, `odb_write_object()` does not actually write anything
+ * into the object store, but only computes the object ID. This flag
+ * changes that so that the object will be written as a loose object
+ * and persisted.
+ */
+ WRITE_OBJECT_PERSIST = (1 << 0),
+
+ /*
+ * Do not print an error in case something goes wrong.
+ */
+ WRITE_OBJECT_SILENT = (1 << 1),
+};
+
+/*
+ * Write an object into the object database. The object is being written into
+ * the local alternate of the repository. If provided, the converted object ID
+ * as well as the compatibility object ID are written to the respective
+ * pointers.
+ *
+ * Returns 0 on success, a negative error code otherwise.
+ */
+int odb_write_object_ext(struct object_database *odb,
+ const void *buf, unsigned long len,
+ enum object_type type,
+ struct object_id *oid,
+ struct object_id *compat_oid,
+ unsigned flags);
+
+static inline int odb_write_object(struct object_database *odb,
+ const void *buf, unsigned long len,
+ enum object_type type,
+ struct object_id *oid)
+{
+ return odb_write_object_ext(odb, buf, len, type, oid, NULL, 0);
+}
+
/* Compatibility wrappers, to be removed once Git 2.51 has been released. */
#include "repository.h"
void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)
{
struct object_id oid;
- if (write_object_file("", 0, OBJ_BLOB, &oid))
+ if (odb_write_object(the_repository->objects, "", 0, OBJ_BLOB, &oid))
die(_("cannot create an empty blob in the object database"));
oidcpy(&ce->oid, &oid);
}