cloudstorage: some cleanup of cloud url handling

We know the preference is never empty, so stop testing for this. But
don't maintain two different preferences with basically the same
content. Instead add the '/git' suffix where needed and keep this all in
one place.

Simplify the extraction of the branch name from the cloud URL.

Also a typo fix and a new comment.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2021-04-10 17:40:30 -07:00
parent da6395a4a8
commit c5eb806adb
12 changed files with 14 additions and 41 deletions

View file

@ -19,6 +19,7 @@ CheckCloudConnection::CheckCloudConnection(QObject *parent) :
}
// our own madeup API to make sure we are talking to a Subsurface cloud server
#define TEAPOT "/make-latte?number-of-shots=3"
#define HTTP_I_AM_A_TEAPOT 418
#define MILK "Linus does not like non-fat milk"

View file

@ -284,9 +284,7 @@ int check_git_sha(const char *filename, struct git_repository **git_p, const cha
*git_p = git;
if (branch_p)
*branch_p = branch;
if (prefs.cloud_git_url &&
strstr(filename, prefs.cloud_git_url)
&& git == dummy_git_repository) {
if (strstr(filename, prefs.cloud_base_url) && git == dummy_git_repository) {
/* opening the cloud storage repository failed for some reason,
* so we don't know if there is additional data in the remote */
free(current_sha);
@ -317,13 +315,11 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
int ret;
git = is_git_repository(filename, &branch, NULL, false);
if (prefs.cloud_git_url &&
strstr(filename, prefs.cloud_git_url)
&& git == dummy_git_repository) {
if (strstr(filename, prefs.cloud_base_url) && git == dummy_git_repository)
/* opening the cloud storage repository failed for some reason
* give up here and don't send errors about git repositories */
return -1;
}
if (git)
return git_load_dives(git, branch, table, trips, sites, devices, filter_presets);

View file

@ -1023,7 +1023,7 @@ static struct git_repository *is_remote_git_repository(char *remote, const char
/* remember if the current git storage we are working on is our cloud storage
* this is used to create more user friendly error message and warnings */
is_subsurface_cloud = strstr(remote, prefs.cloud_git_url) != NULL;
is_subsurface_cloud = strstr(remote, prefs.cloud_base_url) != NULL;
return get_remote_repo(localdir, remote, branch);
}

View file

@ -103,7 +103,6 @@ void copy_prefs(struct preferences *src, struct preferences *dest)
dest->default_filename = copy_string(src->default_filename);
dest->default_cylinder = copy_string(src->default_cylinder);
dest->cloud_base_url = copy_string(src->cloud_base_url);
dest->cloud_git_url = copy_string(src->cloud_git_url);
dest->proxy_host = copy_string(src->proxy_host);
dest->proxy_user = copy_string(src->proxy_user);
dest->proxy_pass = copy_string(src->proxy_pass);

View file

@ -82,7 +82,6 @@ struct preferences {
// ********** CloudStorage **********
bool cloud_auto_sync;
const char *cloud_base_url;
const char *cloud_git_url;
const char *cloud_storage_email;
const char *cloud_storage_email_encoded;
const char *cloud_storage_password;

View file

@ -1442,9 +1442,9 @@ int getCloudURL(QString &filename)
free((void *)prefs.cloud_storage_email_encoded);
prefs.cloud_storage_email_encoded = copy_qstring(email);
}
filename = QString(QString(prefs.cloud_git_url) + "/%1[%1]").arg(email);
filename = QString(QString(prefs.cloud_base_url) + "git/%1[%1]").arg(email);
if (verbose)
qDebug() << "cloud URL set as" << filename;
qDebug() << "returning cloud URL" << filename;
return 0;
}

View file

@ -31,7 +31,6 @@ void qPrefCloudStorage::set_cloud_base_url(const QString &value)
// only free and set if not default
if (prefs.cloud_base_url != default_prefs.cloud_base_url) {
qPrefPrivate::copy_txt(&prefs.cloud_base_url, value);
qPrefPrivate::copy_txt(&prefs.cloud_git_url, value + "/git");
}
disk_cloud_base_url(true);
@ -44,7 +43,6 @@ void qPrefCloudStorage::disk_cloud_base_url(bool doSync)
qPrefPrivate::propSetValue(keyFromGroupAndName(group, "cloud_base_url"), prefs.cloud_base_url, default_prefs.cloud_base_url);
} else {
prefs.cloud_base_url = copy_qstring(qPrefPrivate::propValue(keyFromGroupAndName(group, "cloud_base_url"), default_prefs.cloud_base_url).toString());
qPrefPrivate::copy_txt(&prefs.cloud_git_url, QString(prefs.cloud_base_url) + "/git");
}
}

View file

@ -9,7 +9,6 @@ class qPrefCloudStorage : public QObject {
Q_OBJECT
Q_PROPERTY(bool cloud_auto_sync READ cloud_auto_sync WRITE set_cloud_auto_sync NOTIFY cloud_auto_syncChanged)
Q_PROPERTY(QString cloud_base_url READ cloud_base_url WRITE set_cloud_base_url NOTIFY cloud_base_urlChanged)
Q_PROPERTY(QString cloud_git_url READ cloud_git_url)
Q_PROPERTY(QString cloud_storage_email READ cloud_storage_email WRITE set_cloud_storage_email NOTIFY cloud_storage_emailChanged)
Q_PROPERTY(QString cloud_storage_email_encoded READ cloud_storage_email_encoded WRITE set_cloud_storage_email_encoded NOTIFY cloud_storage_email_encodedChanged)
Q_PROPERTY(QString cloud_storage_password READ cloud_storage_password WRITE set_cloud_storage_password NOTIFY cloud_storage_passwordChanged)
@ -43,7 +42,6 @@ public:
static bool cloud_auto_sync() { return prefs.cloud_auto_sync; }
static QString cloud_base_url() { return prefs.cloud_base_url; }
static QString cloud_git_url() { return prefs.cloud_git_url; }
static QString cloud_storage_email() { return prefs.cloud_storage_email; }
static QString cloud_storage_email_encoded() { return prefs.cloud_storage_email_encoded; }
static QString cloud_storage_password() { return prefs.cloud_storage_password; }