summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorVicent Marti <tanoku@gmail.com>2011-03-23 18:44:53 +0200
committerVicent Marti <tanoku@gmail.com>2011-03-23 18:44:53 +0200
commitf6f72d7ef8091bf1fcf19f284e1db62a43f93381 (patch)
tree24b7f1fa9bc18ab2bce72e337c3b7f6ca3b51e51 /src/odb.c
parent08db1efd3d64bda358071612ff3662f4bf1aea61 (diff)
downloadlibgit2-f6f72d7ef8091bf1fcf19f284e1db62a43f93381.tar.gz
Improve the ODB writing backend
Temporary files when doing streaming writes are now stored inside the Objects folder, to prevent issues when moving files between disks/partitions. Add support for block writes to the ODB again (for those backends that cannot implement streaming).
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/odb.c b/src/odb.c
index d825fd95c..33d5468d9 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -415,6 +415,41 @@ int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id)
return error;
}
+int git_odb_write(git_oid *oid, git_odb *db, const void *data, size_t len, git_otype type)
+{
+ unsigned int i;
+ int error = GIT_ERROR;
+
+ assert(oid && db);
+
+ for (i = 0; i < db->backends.length && error < 0; ++i) {
+ backend_internal *internal = git_vector_get(&db->backends, i);
+ git_odb_backend *b = internal->backend;
+
+ /* we don't write in alternates! */
+ if (internal->is_alternate)
+ continue;
+
+ if (b->write != NULL)
+ error = b->write(oid, b, data, len, type);
+ }
+
+ /* if no backends were able to write the object directly, we try a streaming
+ * write to the backends; just write the whole object into the stream in one
+ * push */
+ if (error < GIT_SUCCESS) {
+ git_odb_stream *stream;
+
+ if ((error = git_odb_open_wstream(&stream, db, len, type)) == GIT_SUCCESS) {
+ stream->write(stream, data, len);
+ error = stream->finalize_write(oid, stream);
+ stream->free(stream);
+ }
+ }
+
+ return error;
+}
+
int git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type)
{
unsigned int i;