diff options
author | Edward Thomson <ethomson@edwardthomson.com> | 2023-04-05 10:33:11 +0100 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2023-04-05 10:35:33 +0100 |
commit | f7fd9ce947fc2189ce80abc31fdc6077df94f73b (patch) | |
tree | 4a3317440d9ebb11e506f0944bf7fc24e13a6f1b /src/libgit2/index.c | |
parent | 389f9b10e6e71339fe28145098a37975c49a472d (diff) | |
download | libgit2-f7fd9ce947fc2189ce80abc31fdc6077df94f73b.tar.gz |
filebuf: configurable hash type
`git_filebuf` hashes contents as its written; allow for SHA1 or SHA256
as that hash. Currently, most callers simply use SHA1 as they do not yet
know about SHA256 themselves.
Diffstat (limited to 'src/libgit2/index.c')
-rw-r--r-- | src/libgit2/index.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/libgit2/index.c b/src/libgit2/index.c index d4532c005..6777f0358 100644 --- a/src/libgit2/index.c +++ b/src/libgit2/index.c @@ -3668,19 +3668,23 @@ int git_indexwriter_init( git_indexwriter *writer, git_index *index) { - int error; + int filebuf_hash, error; GIT_REFCOUNT_INC(index); writer->index = index; + filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(GIT_OID_SHA1)); + GIT_ASSERT(filebuf_hash); + if (!index->index_file_path) return create_index_error(-1, "failed to write index: The index is in-memory only"); - if ((error = git_filebuf_open( - &writer->file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS, GIT_INDEX_FILE_MODE)) < 0) { - + if ((error = git_filebuf_open(&writer->file, + index->index_file_path, + git_filebuf_hash_flags(filebuf_hash), + GIT_INDEX_FILE_MODE)) < 0) { if (error == GIT_ELOCKED) git_error_set(GIT_ERROR_INDEX, "the index is locked; this might be due to a concurrent or crashed process"); |