mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +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
2f3d8d83f5
commit
2f4dbf1848
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;
|
std::string current_sha = saved_git_id;
|
||||||
|
|
||||||
if (is_git_repository(filename, info) && open_git_repository(info)) {
|
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) {
|
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;
|
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 sync_with_remote(struct git_info *);
|
||||||
extern int git_save_dives(struct git_info *, bool select_only);
|
extern int git_save_dives(struct git_info *, bool select_only);
|
||||||
extern int git_load_dives(struct git_info *, struct divelog *log);
|
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 int do_git_save(struct git_info *, bool select_only, bool create_empty);
|
||||||
extern void cleanup_git_info(struct git_info *);
|
extern void cleanup_git_info(struct git_info *);
|
||||||
extern bool git_local_only;
|
extern bool git_local_only;
|
||||||
|
@ -60,6 +59,7 @@ int get_authorship(git_repository *repo, git_signature **authorp);
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
extern std::string saved_git_id;
|
extern std::string saved_git_id;
|
||||||
|
extern std::string get_sha(git_repository *repo, const char *branch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif // GITACCESS_H
|
#endif // GITACCESS_H
|
||||||
|
|
|
@ -1906,14 +1906,14 @@ static int do_git_load(git_repository *repo, const char *branch, struct git_pars
|
||||||
return ret;
|
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;
|
git_commit *commit;
|
||||||
if (find_commit(repo, branch, &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);
|
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…
Add table
Add a link
Reference in a new issue