diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2022-01-26 13:02:49 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-06-20 17:05:30 -0400 |
| commit | 3eba9181cf74693d5906c799e08aba15b5745355 (patch) | |
| tree | 6051ebd18bc56deef4627c96fc819d6fa7e8f118 /src/libgit2/odb.c | |
| parent | 8444b6dce71d53a44f300d7c023cdd075faaa872 (diff) | |
| download | libgit2-3eba9181cf74693d5906c799e08aba15b5745355.tar.gz | |
odb: add git_odb_options
Users will need to be able to specify the object id type for the given
object database; add a new `git_odb_options` with that option.
Diffstat (limited to 'src/libgit2/odb.c')
| -rw-r--r-- | src/libgit2/odb.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/src/libgit2/odb.c b/src/libgit2/odb.c index 787189bc1..f9798597e 100644 --- a/src/libgit2/odb.c +++ b/src/libgit2/odb.c @@ -475,11 +475,25 @@ static int backend_sort_cmp(const void *a, const void *b) return (backend_b->priority - backend_a->priority); } -int git_odb_new(git_odb **out) +static void normalize_options( + git_odb_options *opts, + const git_odb_options *given_opts) +{ + git_odb_options init = GIT_ODB_OPTIONS_INIT; + + if (given_opts) + memcpy(opts, given_opts, sizeof(git_odb_options)); + else + memcpy(opts, &init, sizeof(git_odb_options)); +} + +int git_odb_new(git_odb **out, const git_odb_options *opts) { git_odb *db = git__calloc(1, sizeof(*db)); GIT_ERROR_CHECK_ALLOC(db); + normalize_options(&db->options, opts); + if (git_mutex_init(&db->lock) < 0) { git__free(db); return -1; @@ -740,7 +754,10 @@ int git_odb_set_commit_graph(git_odb *odb, git_commit_graph *cgraph) return error; } -int git_odb_open(git_odb **out, const char *objects_dir) +int git_odb_open( + git_odb **out, + const char *objects_dir, + const git_odb_options *opts) { git_odb *db; @@ -749,7 +766,7 @@ int git_odb_open(git_odb **out, const char *objects_dir) *out = NULL; - if (git_odb_new(&db) < 0) + if (git_odb_new(&db, opts) < 0) return -1; if (git_odb__add_default_backends(db, objects_dir, 0, 0) < 0) { |
