diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-13 08:01:06 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-13 09:14:48 -0700 |
commit | 9a22efb97b78da00dbc8fdfdc9fa5db9eac84708 (patch) | |
tree | 77f9b278b187bfeb0ac16863f6e434b8dec98c15 | |
parent | e21cae2d46db8148dc294c2dff08d9321274f815 (diff) | |
download | subsurface-9a22efb97b78da00dbc8fdfdc9fa5db9eac84708.tar.gz |
Move git related declarations into their own header file
Also change the name of the enum and make sure all the inner functions get
passed the remote transport information.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.h | 10 | ||||
-rw-r--r-- | file.c | 1 | ||||
-rw-r--r-- | git-access.c | 50 | ||||
-rw-r--r-- | git-access.h | 27 | ||||
-rw-r--r-- | load-git.c | 1 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 1 | ||||
-rw-r--r-- | save-git.c | 3 | ||||
-rw-r--r-- | save-xml.c | 1 |
8 files changed, 58 insertions, 36 deletions
@@ -668,16 +668,6 @@ extern int export_dives_xslt(const char *filename, const bool selected, const in struct membuffer; extern void save_one_dive_to_mb(struct membuffer *b, struct dive *dive); -struct git_oid; -struct git_repository; -#define dummy_git_repository ((git_repository *)3ul) /* Random bogus pointer, not NULL */ -extern struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote); -extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch); -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 *saved_git_id; -extern void clear_git_id(void); -extern void set_git_id(const struct git_oid *); int cylinderuse_from_text(const char *text); @@ -10,6 +10,7 @@ #include "dive.h" #include "file.h" +#include "git-access.h" /* For SAMPLE_* */ #include <libdivecomputer/parser.h> diff --git a/git-access.c b/git-access.c index 32091e585..1c43a1386 100644 --- a/git-access.c +++ b/git-access.c @@ -14,6 +14,7 @@ #include "membuffer.h" #include "strndup.h" #include "qthelperfromc.h" +#include "git-access.h" /* * The libgit2 people are incompetent at making libraries. They randomly change @@ -36,8 +37,6 @@ git_branch_create(out, repo, branch_name, target, force) #endif -enum remote_type { OTHER, HTTPS, SSH }; - static char *get_local_dir(const char *remote, const char *branch) { SHA_CTX ctx; @@ -126,7 +125,7 @@ int credential_https_cb(git_cred **out, } #endif -static int update_remote(git_repository *repo, git_remote *origin, git_reference *local, git_reference *remote, enum remote_type rt) +static int update_remote(git_repository *repo, git_remote *origin, git_reference *local, git_reference *remote, enum remote_transport rt) { git_push_options opts = GIT_PUSH_OPTIONS_INIT; git_strarray refspec; @@ -136,9 +135,9 @@ static int update_remote(git_repository *repo, git_remote *origin, git_reference refspec.strings = (char **)&name; #if USE_LIBGIT23_API - if (rt == SSH) + if (rt == RT_SSH) opts.callbacks.credentials = credential_ssh_cb; - else if (rt == HTTPS) + else if (rt == RT_HTTPS) opts.callbacks.credentials = credential_https_cb; #endif if (git_remote_push(origin, &refspec, &opts)) @@ -149,7 +148,7 @@ static int update_remote(git_repository *repo, git_remote *origin, git_reference return 0; } -static int try_to_update(git_repository *repo, git_remote *origin, git_reference *local, git_reference *remote, enum remote_type rt) +static int try_to_update(git_repository *repo, git_remote *origin, git_reference *local, git_reference *remote, enum remote_transport rt) { git_oid base; const git_oid *local_id, *remote_id; @@ -199,7 +198,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference return report_error("Local and remote have diverged, need to merge"); } -static int check_remote_status(git_repository *repo, git_remote *origin, const char *branch, enum remote_type rt) +static int check_remote_status(git_repository *repo, git_remote *origin, const char *branch, enum remote_transport rt) { git_reference *local_ref, *remote_ref; @@ -216,23 +215,15 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c git_reference_free(remote_ref); } -int sync_with_remote(git_repository *repo, const char *remote, const char *branch) +int sync_with_remote(git_repository *repo, const char *remote, const char *branch, enum remote_transport rt) { int error; git_remote *origin; - enum remote_type rt; char *proxy_string; git_config *conf; - if (strncmp(remote, "ssh://", 6) == 0) - rt = SSH; - else if (strncmp(remote, "https://", 8) == 0) - rt = HTTPS; - else - rt = OTHER; - git_repository_config(&conf, repo); - if (rt == HTTPS && getProxyString(&proxy_string)) { + if (rt == RT_HTTPS && getProxyString(&proxy_string)) { git_config_set_string(conf, "http.proxy", proxy_string); free(proxy_string); } else { @@ -250,13 +241,13 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc return 0; } - if (rt == HTTPS && !canReachCloudServer()) + if (rt == RT_HTTPS && !canReachCloudServer()) return 0; #if USE_LIBGIT23_API git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; - if (rt == SSH) + if (rt == RT_SSH) opts.callbacks.credentials = credential_ssh_cb; - else if (rt == HTTPS) + else if (rt == RT_HTTPS) opts.callbacks.credentials = credential_https_cb; error = git_remote_fetch(origin, NULL, &opts, NULL); #else @@ -271,7 +262,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc git_remote_free(origin); } -static git_repository *update_local_repo(const char *localdir, const char *remote, const char *branch) +static git_repository *update_local_repo(const char *localdir, const char *remote, const char *branch, enum remote_transport rt) { int error; git_repository *repo = NULL; @@ -282,11 +273,11 @@ static git_repository *update_local_repo(const char *localdir, const char *remot localdir, giterr_last()->message); return NULL; } - sync_with_remote(repo, remote, branch); + sync_with_remote(repo, remote, branch, rt); return repo; } -static git_repository *create_local_repo(const char *localdir, const char *remote, const char *branch) +static git_repository *create_local_repo(const char *localdir, const char *remote, const char *branch, enum remote_transport rt) { int error; git_repository *cloned_repo = NULL; @@ -309,6 +300,15 @@ static git_repository *create_local_repo(const char *localdir, const char *remot static struct git_repository *get_remote_repo(const char *localdir, const char *remote, const char *branch) { struct stat st; + enum remote_transport rt; + + /* figure out the remote transport */ + if (strncmp(remote, "ssh://", 6) == 0) + rt = RT_SSH; + else if (strncmp(remote, "https://", 8) == 0) + rt = RT_HTTPS; + else + rt = RT_OTHER; /* Do we already have a local cache? */ if (!stat(localdir, &st)) { @@ -316,9 +316,9 @@ static struct git_repository *get_remote_repo(const char *localdir, const char * report_error("local git cache at '%s' is corrupt"); return NULL; } - return update_local_repo(localdir, remote, branch); + return update_local_repo(localdir, remote, branch, rt); } - return create_local_repo(localdir, remote, branch); + return create_local_repo(localdir, remote, branch, rt); } /* diff --git a/git-access.h b/git-access.h new file mode 100644 index 000000000..c0ff93d40 --- /dev/null +++ b/git-access.h @@ -0,0 +1,27 @@ +#ifndef GITACCESS_H +#define GITACCESS_H + +#ifdef __cplusplus +extern "C" { +#else +#include <stdbool.h> +#endif + +enum remote_transport { RT_OTHER, RT_HTTPS, RT_SSH }; + +struct git_oid; +struct git_repository; +#define dummy_git_repository ((git_repository *)3ul) /* Random bogus pointer, not NULL */ +extern struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote); +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 *saved_git_id; +extern void clear_git_id(void); +extern void set_git_id(const struct git_oid *); + +#ifdef __cplusplus +} +#endif +#endif // GITACCESS_H + diff --git a/load-git.c b/load-git.c index d8052a550..59bb8adc6 100644 --- a/load-git.c +++ b/load-git.c @@ -15,6 +15,7 @@ #include "dive.h" #include "device.h" #include "membuffer.h" +#include "git-access.h" const char *saved_git_id = NULL; diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 08c8e1711..ec39cc151 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -43,6 +43,7 @@ #include "usermanual.h" #endif #include "divepicturemodel.h" +#include "git-access.h" #include <QNetworkProxy> #include <QUndoStack> #include <qthelper.h> diff --git a/save-git.c b/save-git.c index 662ec408f..c918f012f 100644 --- a/save-git.c +++ b/save-git.c @@ -13,6 +13,7 @@ #include "dive.h" #include "device.h" #include "membuffer.h" +#include "git-access.h" #include "version.h" /* @@ -1140,7 +1141,7 @@ static int do_git_save(git_repository *repo, const char *branch, const char *rem if (prefs.cloud_background_sync) { /* now sync the tree with the cloud server */ if (strstr(remote, "https://cloud.subsurface-divelog.org")) { - sync_with_remote(repo, remote, branch); + sync_with_remote(repo, remote, branch, RT_HTTPS); } } } diff --git a/save-xml.c b/save-xml.c index fdcaccc94..8ff133122 100644 --- a/save-xml.c +++ b/save-xml.c @@ -11,6 +11,7 @@ #include "device.h" #include "membuffer.h" #include "strndup.h" +#include "git-access.h" /* * We're outputting utf8 in xml. |