core: make get_sha() return std::string

This was crazy: it returned a local static buffer, i.e. was
inherently non-reentrant.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-29 13:57:26 +01:00 committed by Michael Keller
parent 2f3d8d83f5
commit 2f4dbf1848
3 changed files with 7 additions and 7 deletions

View file

@ -1906,14 +1906,14 @@ static int do_git_load(git_repository *repo, const char *branch, struct git_pars
return ret;
}
extern "C" const char *get_sha(git_repository *repo, const char *branch)
std::string get_sha(git_repository *repo, const char *branch)
{
static char git_id_buffer[GIT_OID_HEXSZ + 1];
char git_id_buffer[GIT_OID_HEXSZ + 1];
git_commit *commit;
if (find_commit(repo, branch, &commit))
return NULL;
return std::string();
git_oid_tostr(git_id_buffer, sizeof(git_id_buffer), (const git_oid *)commit);
return git_id_buffer;
return std::string(git_id_buffer);
}
/*