diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-06-13 13:41:09 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-06-14 13:35:33 -0700 |
commit | 8b478a969dbd10b3f07affd2f614886d27211c2a (patch) | |
tree | e6d4b6fc4b9b7754a4b2d45f5c5afbe6298ef304 /core | |
parent | fe9e33ccac5ec09e25dc0ea363b24a8b01ab2d88 (diff) | |
download | subsurface-8b478a969dbd10b3f07affd2f614886d27211c2a.tar.gz |
git-storage: add global flag to indicate successful cloud sync
This may seem like a bit heavy handed as it adds more global state, but given
the number of ways in which attempts to sync with the cloud can fail it seems
much more reliable to claim success in the spots where we actually know that we
have successfully synced with the remote server. Transporting that information
back through the various call chains turned out to be very disruptive and ugly,
so I went with global state instead.
Whenever we access cloud storage (or any git repo), we always first check if it
actually is a git repo by calling is_git_repository() - so this is the perfect
spot to initialize the variable to false.
And there are only two spots where we either clone the remote repo
(create_local_repo()) or update the remote with the (potentially merged) local
changes (check_remote_status()). So those are the two places where we set the
variable to true.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/git-access.c | 7 | ||||
-rw-r--r-- | core/git-access.h | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/core/git-access.c b/core/git-access.c index 846fcba96..be1f39120 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -37,6 +37,7 @@ bool git_local_only = true; #else bool git_local_only = false; #endif +bool git_remote_sync_successful = false; int (*update_progress_cb)(const char *) = NULL; @@ -606,6 +607,7 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c git_reference_free(remote_ref); } git_reference_free(local_ref); + git_remote_sync_successful = (error == 0); return error; } @@ -942,6 +944,8 @@ static struct git_repository *get_remote_repo(const char *localdir, const char * git_local_only = false; ret = create_local_repo(localdir, remote, branch, rt); git_local_only = glo; + if (ret) + git_remote_sync_successful = true; return ret; } @@ -1033,6 +1037,9 @@ struct git_repository *is_git_repository(const char *filename, const char **bran git_repository *repo; char *loc, *branch; + /* we are looking at a new potential remote, but we haven't synced with it */ + git_remote_sync_successful = false; + flen = strlen(filename); if (!flen || filename[--flen] != ']') return NULL; diff --git a/core/git-access.h b/core/git-access.h index 8e20395a4..b02bd3280 100644 --- a/core/git-access.h +++ b/core/git-access.h @@ -24,6 +24,7 @@ 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 bool git_local_only; +extern bool git_remote_sync_successful; extern void clear_git_id(void); extern void set_git_id(const struct git_oid *); extern enum remote_transport url_to_remote_transport(const char *remote); |