summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libgit2/odb.c10
-rw-r--r--src/libgit2/odb.h2
-rw-r--r--src/libgit2/odb_loose.c8
-rw-r--r--src/libgit2/odb_mempack.c3
-rw-r--r--src/libgit2/odb_pack.c4
5 files changed, 23 insertions, 4 deletions
diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c
index edf4f001f..d50c7df9b 100644
--- a/src/libgit2/odb.c
+++ b/src/libgit2/odb.c
@@ -587,6 +587,13 @@ static int add_backend_internal(
GIT_ERROR_CHECK_VERSION(backend, GIT_ODB_BACKEND_VERSION, "git_odb_backend");
+#ifdef GIT_EXPERIMENTAL_SHA256
+ if (!backend->oid_type) {
+ git_error_set(GIT_ERROR_ODB, "backend oid type is not set");
+ return -1;
+ }
+#endif
+
/* Check if the backend is already owned by another ODB */
GIT_ASSERT(!backend->odb || backend->odb == odb);
@@ -1704,7 +1711,6 @@ int git_odb_open_wstream(
(error = hash_header(ctx, size, type)) < 0)
goto done;
- (*stream)->oid_type = db->options.oid_type;
(*stream)->hash_ctx = ctx;
(*stream)->declared_size = size;
(*stream)->received_bytes = 0;
@@ -1750,7 +1756,7 @@ int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream)
git_hash_final(out->id, stream->hash_ctx);
#ifdef GIT_EXPERIMENTAL_SHA256
- out->type = stream->oid_type;
+ out->type = stream->backend->oid_type;
#endif
if (git_odb__freshen(stream->backend->odb, out))
diff --git a/src/libgit2/odb.h b/src/libgit2/odb.h
index 7a712e202..6bdacd384 100644
--- a/src/libgit2/odb.h
+++ b/src/libgit2/odb.h
@@ -180,7 +180,7 @@ int git_odb__hashfile(
git_object_t object_type,
git_oid_t oid_type);
-GIT_EXTERN(int) git_odb__backend_loose(
+int git_odb__backend_loose(
git_odb_backend **out,
const char *objects_dir,
git_odb_backend_loose_options *opts);
diff --git a/src/libgit2/odb_loose.c b/src/libgit2/odb_loose.c
index d1abbe233..306cbf9ad 100644
--- a/src/libgit2/odb_loose.c
+++ b/src/libgit2/odb_loose.c
@@ -1179,14 +1179,20 @@ int git_odb__backend_loose(
backend = git__calloc(1, alloclen);
GIT_ERROR_CHECK_ALLOC(backend);
+ normalize_options(&backend->options, opts);
+
backend->parent.version = GIT_ODB_BACKEND_VERSION;
+
+#ifdef GIT_EXPERIMENTAL_SHA256
+ backend->parent.oid_type = backend->options.oid_type;
+#endif
+
backend->objects_dirlen = objects_dirlen;
memcpy(backend->objects_dir, objects_dir, objects_dirlen);
if (backend->objects_dir[backend->objects_dirlen - 1] != '/')
backend->objects_dir[backend->objects_dirlen++] = '/';
- normalize_options(&backend->options, opts);
backend->oid_hexsize = git_oid_hexsize(backend->options.oid_type);
backend->parent.read = &loose_backend__read;
diff --git a/src/libgit2/odb_mempack.c b/src/libgit2/odb_mempack.c
index 6f27f45f8..8c83fcee6 100644
--- a/src/libgit2/odb_mempack.c
+++ b/src/libgit2/odb_mempack.c
@@ -178,6 +178,9 @@ int git_mempack_new(git_odb_backend **out)
return -1;
db->parent.version = GIT_ODB_BACKEND_VERSION;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ db->parent.oid_type = GIT_OID_SHA1;
+#endif
db->parent.read = &impl__read;
db->parent.write = &impl__write;
db->parent.read_header = &impl__read_header;
diff --git a/src/libgit2/odb_pack.c b/src/libgit2/odb_pack.c
index 1b1d122b0..b0a6ae097 100644
--- a/src/libgit2/odb_pack.c
+++ b/src/libgit2/odb_pack.c
@@ -883,6 +883,10 @@ static int pack_backend__alloc(
backend->parent.version = GIT_ODB_BACKEND_VERSION;
+#ifdef GIT_EXPERIMENTAL_SHA256
+ backend->parent.oid_type = backend->opts.oid_type;
+#endif
+
backend->parent.read = &pack_backend__read;
backend->parent.read_prefix = &pack_backend__read_prefix;
backend->parent.read_header = &pack_backend__read_header;