aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-12-27 09:56:27 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-12-27 10:06:33 -0800
commitbc200c308933ec6e57700d1dfd5628cd26d1939c (patch)
tree28515797b95e587efa08b359aec16fb653b58116
parent739d7d74e767b181974226179c5f1a4b56146e4a (diff)
downloadsubsurface-bc200c308933ec6e57700d1dfd5628cd26d1939c.tar.gz
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>
-rw-r--r--subsurface-core/git-access.h1
-rw-r--r--subsurface-core/load-git.c28
2 files changed, 26 insertions, 3 deletions
diff --git a/subsurface-core/git-access.h b/subsurface-core/git-access.h
index a2a9ba3ae..7e57351fb 100644
--- a/subsurface-core/git-access.h
+++ b/subsurface-core/git-access.h
@@ -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 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 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 const char *saved_git_id;
extern void clear_git_id(void);
diff --git a/subsurface-core/load-git.c b/subsurface-core/load-git.c
index 39dab4367..f6b9f73aa 100644
--- a/subsurface-core/load-git.c
+++ b/subsurface-core/load-git.c
@@ -1595,17 +1595,29 @@ void set_git_id(const struct git_oid * id)
saved_git_id = git_id_buffer;
}
-static int do_git_load(git_repository *repo, const char *branch)
+static int find_commit(git_repository *repo, const char *branch, git_commit **commit_p)
{
int ret;
git_object *object;
- git_commit *commit;
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, object, GIT_OBJ_COMMIT))
+ 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)
+{
+ int ret;
+ git_object *object;
+ git_commit *commit;
+ git_tree *tree;
+
+ ret = find_commit(repo, branch, &commit);
+ if (ret)
+ return ret;
if (git_commit_tree(&tree, commit))
return report_error("Could not look up tree of commit in branch '%s'", branch);
ret = load_dives_from_tree(repo, tree);
@@ -1615,6 +1627,16 @@ static int do_git_load(git_repository *repo, const char *branch)
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
* value if it's not a git repository at all (so that you