diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-12 12:32:12 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-12 13:56:23 -0700 |
commit | e21cae2d46db8148dc294c2dff08d9321274f815 (patch) | |
tree | 3c96b90a46cc43534bc332aa1157cdb62c8a5ec5 /git-access.c | |
parent | 492369b3125b2c1c91f134c360110440b03d33b6 (diff) | |
download | subsurface-e21cae2d46db8148dc294c2dff08d9321274f815.tar.gz |
Cloud storage: sync the remote after save
This change once again tests if the remote can be reached. Even with a
fairly big data file and a medium speed internet connection the remote
sync is fast enough to call it nearly instantaneous. Maybe a couple of
seconds.
We may need more checks / different heuristics / warnings if the sync
didn't happen, etc. But for now this should allow more reasonable testing.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'git-access.c')
-rw-r--r-- | git-access.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/git-access.c b/git-access.c index e6fa4b966..32091e585 100644 --- a/git-access.c +++ b/git-access.c @@ -216,21 +216,14 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c git_reference_free(remote_ref); } -static git_repository *update_local_repo(const char *localdir, const char *remote, const char *branch) +int sync_with_remote(git_repository *repo, const char *remote, const char *branch) { int error; - git_repository *repo = NULL; git_remote *origin; enum remote_type rt; char *proxy_string; git_config *conf; - error = git_repository_open(&repo, localdir); - if (error) { - report_error("Unable to open git cache repository at %s: %s", - localdir, giterr_last()->message); - return NULL; - } if (strncmp(remote, "ssh://", 6) == 0) rt = SSH; else if (strncmp(remote, "https://", 8) == 0) @@ -254,11 +247,11 @@ static git_repository *update_local_repo(const char *localdir, const char *remot if (error) { report_error("Repository '%s' origin lookup failed (%s)", remote, giterr_last()->message); - return repo; + return 0; } if (rt == HTTPS && !canReachCloudServer()) - return repo; + return 0; #if USE_LIBGIT23_API git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; if (rt == SSH) @@ -276,6 +269,20 @@ static git_repository *update_local_repo(const char *localdir, const char *remot check_remote_status(repo, origin, branch, rt); git_remote_free(origin); +} + +static git_repository *update_local_repo(const char *localdir, const char *remote, const char *branch) +{ + int error; + git_repository *repo = NULL; + + error = git_repository_open(&repo, localdir); + if (error) { + report_error("Unable to open git cache repository at %s: %s", + localdir, giterr_last()->message); + return NULL; + } + sync_with_remote(repo, remote, branch); return repo; } @@ -393,7 +400,7 @@ static struct git_repository *is_remote_git_repository(char *remote, const char /* * If it's not a git repo, return NULL. Be very conservative. */ -struct git_repository *is_git_repository(const char *filename, const char **branchp) +struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote) { int flen, blen, ret; int offset = 1; @@ -446,7 +453,10 @@ struct git_repository *is_git_repository(const char *filename, const char **bran repo = is_remote_git_repository(loc, branch); if (repo) { - free(loc); + if (remote) + *remote = loc; + else + free(loc); *branchp = branch; return repo; } |