mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Print paths to internal files in verbose mode
When run with -v option, this prints local file names like the path to the local git repository and the hash file. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3f900885df
commit
a241393e7b
9 changed files with 63 additions and 9 deletions
2
file.c
2
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
2
main.cpp
2
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();
|
||||
|
|
34
qthelper.cpp
34
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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#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();
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue