summaryrefslogtreecommitdiff
path: root/src/libgit2/repository.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2023-04-23 00:07:06 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2023-04-25 10:34:31 +0100
commit72139ef289383dafeea355ace222359c48d98563 (patch)
tree9d853a64b31ef18a1dc1456b8b30a4e958c599d8 /src/libgit2/repository.c
parent3853ba8de64a0e774c6e73aacb5831707f841621 (diff)
downloadlibgit2-72139ef289383dafeea355ace222359c48d98563.tar.gz
shallow: don't assume SHA1
Diffstat (limited to 'src/libgit2/repository.c')
-rw-r--r--src/libgit2/repository.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/libgit2/repository.c b/src/libgit2/repository.c
index 3b6ecae24..a60fb23fa 100644
--- a/src/libgit2/repository.c
+++ b/src/libgit2/repository.c
@@ -3670,13 +3670,14 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro
{
git_filebuf file = GIT_FILEBUF_INIT;
git_str path = GIT_STR_INIT;
+ char oid_str[GIT_OID_MAX_HEXSIZE + 1];
size_t idx;
git_oid *oid;
int filebuf_hash, error = 0;
GIT_ASSERT_ARG(repo);
- filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(GIT_OID_SHA1));
+ filebuf_hash = git_filebuf_hash_flags(git_oid_algorithm(repo->oid_type));
GIT_ASSERT(filebuf_hash);
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
@@ -3686,7 +3687,8 @@ int git_repository__shallow_roots_write(git_repository *repo, git_array_oid_t ro
goto on_error;
git_array_foreach(roots, idx, oid) {
- git_filebuf_write(&file, git_oid_tostr_s(oid), GIT_OID_SHA1_HEXSIZE);
+ git_oid_tostr(oid_str, sizeof(oid_str), oid);
+ git_filebuf_write(&file, oid_str, git_oid_hexsize(repo->oid_type));
git_filebuf_write(&file, "\n", 1);
}