diff --git a/file.c b/file.c index a7b407f6d..c4032c1f2 100644 --- a/file.c +++ b/file.c @@ -436,7 +436,7 @@ int parse_file(const char *filename) char *fmt; int ret; - git = is_git_repository(filename, &branch, NULL); + git = is_git_repository(filename, &branch, NULL, false); if (prefs.cloud_git_url && strstr(filename, prefs.cloud_git_url) && git == dummy_git_repository) diff --git a/git-access.c b/git-access.c index 25f1d9e8a..eee066007 100644 --- a/git-access.c +++ b/git-access.c @@ -806,7 +806,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, const char **remote) +struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote, bool dry_run) { int flen, blen, ret; int offset = 1; @@ -857,6 +857,9 @@ struct git_repository *is_git_repository(const char *filename, const char **bran return dummy_git_repository; } + if (dry_run) + return dummy_git_repository; + repo = is_remote_git_repository(loc, branch); if (repo) { if (remote) diff --git a/git-access.h b/git-access.h index beb764e7e..a2a9ba3ae 100644 --- a/git-access.h +++ b/git-access.h @@ -14,7 +14,7 @@ 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 struct git_repository *is_git_repository(const char *filename, const char **branchp, const char **remote, bool dry_run); 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 *); @@ -23,7 +23,7 @@ extern const char *saved_git_id; extern void clear_git_id(void); extern void set_git_id(const struct git_oid *); void set_git_update_cb(int(*cb)(int)); - +char *get_local_dir(const char *remote, const char *branch); #ifdef __cplusplus } #endif diff --git a/main.cpp b/main.cpp index 747d2b27d..c288f68dc 100644 --- a/main.cpp +++ b/main.cpp @@ -74,6 +74,8 @@ int main(int argc, char **argv) m->setLoadedWithFiles(!files.isEmpty() || !importedFiles.isEmpty()); m->loadFiles(files); m->importFiles(importedFiles); + if (verbose > 0) + print_files(); if (!quit) run_ui(); exit_ui(); diff --git a/qthelper.cpp b/qthelper.cpp index 31ec43df7..ed23948ea 100644 --- a/qthelper.cpp +++ b/qthelper.cpp @@ -1078,9 +1078,19 @@ extern "C" char * hashstring(char * filename) return hashOf[QString(filename)].toHex().data(); } +const QString hashfile_name() +{ + return QString(system_default_directory()).append("/hashes"); +} + +extern "C" char *hashfile_name_string() +{ + return strdup(hashfile_name().toUtf8().data()); +} + void read_hashes() { - QFile hashfile(QString(system_default_directory()).append("/hashes")); + QFile hashfile(hashfile_name()); if (hashfile.open(QIODevice::ReadOnly)) { QDataStream stream(&hashfile); stream >> localFilenameOf; @@ -1091,7 +1101,7 @@ void read_hashes() void write_hashes() { - QSaveFile hashfile(QString(system_default_directory()).append("/hashes")); + QSaveFile hashfile(hashfile_name()); if (hashfile.open(QIODevice::WriteOnly)) { QDataStream stream(&hashfile); stream << localFilenameOf; @@ -1210,13 +1220,22 @@ extern "C" bool picture_exists(struct picture *picture) return same_string(hash.toHex().data(), picture->hash); } +const QString picturedir() +{ + return QString(system_default_directory()).append("/picturedata/"); +} + +extern "C" char *picturedir_string() +{ + return strdup(picturedir().toUtf8().data()); +} + /* when we get a picture from git storage (local or remote) and can't find the picture * based on its hash, we create a local copy with the hash as filename and the appropriate * suffix */ extern "C" void savePictureLocal(struct picture *picture, const char *data, int len) { - QString dirname(system_default_directory()); - dirname += "/picturedata/"; + QString dirname = picturedir(); QDir localPictureDir(dirname); localPictureDir.mkpath(dirname); QString suffix(picture->filename); @@ -1386,6 +1405,13 @@ int getCloudURL(QString &filename) return 0; } +extern "C" char *cloud_url() +{ + QString filename; + getCloudURL(filename); + return strdup(filename.toUtf8().data()); +} + void loadPreferences() { QSettings s; diff --git a/qthelperfromc.h b/qthelperfromc.h index 21b2a6f80..d2e80144c 100644 --- a/qthelperfromc.h +++ b/qthelperfromc.h @@ -14,5 +14,8 @@ char *move_away(const char *path); const char *local_file_path(struct picture *picture); void savePictureLocal(struct picture *picture, const char *data, int len); void cache_picture(struct picture *picture); +char *cloud_url(); +char *hashfile_name_string(); +char *picturedir_string(); #endif // QTHELPERFROMC_H diff --git a/save-xml.c b/save-xml.c index 8aa5088af..0fdb39091 100644 --- a/save-xml.c +++ b/save-xml.c @@ -662,7 +662,7 @@ int save_dives_logic(const char *filename, const bool select_only) const char *branch, *remote; int error; - git = is_git_repository(filename, &branch, &remote); + git = is_git_repository(filename, &branch, &remote, false); if (git) return git_save_dives(git, branch, remote, select_only); diff --git a/subsurfacestartup.c b/subsurfacestartup.c index fd5df09ab..ef2eb2cd5 100644 --- a/subsurfacestartup.c +++ b/subsurfacestartup.c @@ -3,6 +3,9 @@ #include #include #include "gettext.h" +#include "qthelperfromc.h" +#include "git-access.h" + struct preferences prefs, informational_prefs; struct preferences default_prefs = { .cloud_base_url = "https://cloud.subsurface-divelog.org/", @@ -134,6 +137,22 @@ static void print_version() printf("built with libdivecomputer v%s\n", dc_version(NULL)); } +void print_files() +{ + const char *branchp, *remote; + const char *filename, *local_git; + + filename = cloud_url(); + + is_git_repository(filename, &branchp, &remote, true); + local_git = get_local_dir(remote, branchp); + printf("\nFile locations:\n\n"); + printf("Local git storage: %s\n", local_git); + printf("Cloud URL: %s\n", cloud_url()); + printf("Image hashes: %s\n", hashfile_name_string()); + printf("Local picture directory: %s\n\n", picturedir_string()); +} + static void print_help() { print_version(); diff --git a/subsurfacestartup.h b/subsurfacestartup.h index 44db42efe..8c70c1fe5 100644 --- a/subsurfacestartup.h +++ b/subsurfacestartup.h @@ -16,6 +16,7 @@ extern bool imported; void setup_system_prefs(void); void parse_argument(const char *arg); void free_prefs(void); +void print_files(void); #ifdef __cplusplus }