mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Cloud storage: check the top commit without loading dives
This way we can check if the local cache is in sync with the remote without always triggering a load of the dives from git. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
739d7d74e7
commit
bc200c3089
2 changed files with 27 additions and 4 deletions
|
@ -18,6 +18,7 @@ extern struct git_repository *is_git_repository(const char *filename, const char
|
||||||
extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch, enum remote_transport rt);
|
extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch, enum remote_transport rt);
|
||||||
extern int git_save_dives(struct git_repository *, const char *, const char *remote, bool select_only);
|
extern int git_save_dives(struct git_repository *, const char *, const char *remote, bool select_only);
|
||||||
extern int git_load_dives(struct git_repository *, const char *);
|
extern int git_load_dives(struct git_repository *, const char *);
|
||||||
|
extern const char *get_sha(git_repository *repo, const char *branch);
|
||||||
extern int do_git_save(git_repository *repo, const char *branch, const char *remote, bool select_only, bool create_empty);
|
extern int do_git_save(git_repository *repo, const char *branch, const char *remote, bool select_only, bool create_empty);
|
||||||
extern const char *saved_git_id;
|
extern const char *saved_git_id;
|
||||||
extern void clear_git_id(void);
|
extern void clear_git_id(void);
|
||||||
|
|
|
@ -1595,6 +1595,19 @@ void set_git_id(const struct git_oid * id)
|
||||||
saved_git_id = git_id_buffer;
|
saved_git_id = git_id_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int find_commit(git_repository *repo, const char *branch, git_commit **commit_p)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
git_object *object;
|
||||||
|
git_tree *tree;
|
||||||
|
|
||||||
|
if (git_revparse_single(&object, repo, branch))
|
||||||
|
return report_error("Unable to look up revision '%s'", branch);
|
||||||
|
if (git_object_peel((git_object **)commit_p, object, GIT_OBJ_COMMIT))
|
||||||
|
return report_error("Revision '%s' is not a valid commit", branch);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_git_load(git_repository *repo, const char *branch)
|
static int do_git_load(git_repository *repo, const char *branch)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -1602,10 +1615,9 @@ static int do_git_load(git_repository *repo, const char *branch)
|
||||||
git_commit *commit;
|
git_commit *commit;
|
||||||
git_tree *tree;
|
git_tree *tree;
|
||||||
|
|
||||||
if (git_revparse_single(&object, repo, branch))
|
ret = find_commit(repo, branch, &commit);
|
||||||
return report_error("Unable to look up revision '%s'", branch);
|
if (ret)
|
||||||
if (git_object_peel((git_object **)&commit, object, GIT_OBJ_COMMIT))
|
return ret;
|
||||||
return report_error("Revision '%s' is not a valid commit", branch);
|
|
||||||
if (git_commit_tree(&tree, commit))
|
if (git_commit_tree(&tree, commit))
|
||||||
return report_error("Could not look up tree of commit in branch '%s'", branch);
|
return report_error("Could not look up tree of commit in branch '%s'", branch);
|
||||||
ret = load_dives_from_tree(repo, tree);
|
ret = load_dives_from_tree(repo, tree);
|
||||||
|
@ -1615,6 +1627,16 @@ static int do_git_load(git_repository *repo, const char *branch)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *get_sha(git_repository *repo, const char *branch)
|
||||||
|
{
|
||||||
|
static char git_id_buffer[GIT_OID_HEXSZ+1];
|
||||||
|
git_commit *commit;
|
||||||
|
if (find_commit(repo, branch, &commit))
|
||||||
|
return NULL;
|
||||||
|
git_oid_tostr(git_id_buffer, sizeof(git_id_buffer), (const git_oid *)commit);
|
||||||
|
return git_id_buffer;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Like git_save_dives(), this silently returns a negative
|
* Like git_save_dives(), this silently returns a negative
|
||||||
* value if it's not a git repository at all (so that you
|
* value if it's not a git repository at all (so that you
|
||||||
|
|
Loading…
Add table
Reference in a new issue