mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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:
parent
3e60f6c390
commit
615dd376f3
3 changed files with 7 additions and 7 deletions
|
@ -269,9 +269,9 @@ extern "C" bool remote_repo_uptodate(const char *filename, struct git_info *info
|
|||
std::string current_sha = saved_git_id;
|
||||
|
||||
if (is_git_repository(filename, info) && open_git_repository(info)) {
|
||||
const char *sha = get_sha(info->repo, info->branch);
|
||||
std::string sha = get_sha(info->repo, info->branch);
|
||||
if (!sha.empty() && current_sha == sha) {
|
||||
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
|
||||
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,6 @@ extern bool remote_repo_uptodate(const char *filename, struct git_info *info);
|
|||
extern int sync_with_remote(struct git_info *);
|
||||
extern int git_save_dives(struct git_info *, bool select_only);
|
||||
extern int git_load_dives(struct git_info *, struct divelog *log);
|
||||
extern const char *get_sha(git_repository *repo, const char *branch);
|
||||
extern int do_git_save(struct git_info *, bool select_only, bool create_empty);
|
||||
extern void cleanup_git_info(struct git_info *);
|
||||
extern bool git_local_only;
|
||||
|
@ -60,6 +59,7 @@ int get_authorship(git_repository *repo, git_signature **authorp);
|
|||
|
||||
#include <string>
|
||||
extern std::string saved_git_id;
|
||||
extern std::string get_sha(git_repository *repo, const char *branch);
|
||||
|
||||
#endif
|
||||
#endif // GITACCESS_H
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue