summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
Diffstat (limited to 'save-git.c')
-rw-r--r--save-git.c113
1 files changed, 40 insertions, 73 deletions
diff --git a/save-git.c b/save-git.c
index 6c2587bf8..a7b51446a 100644
--- a/save-git.c
+++ b/save-git.c
@@ -13,7 +13,7 @@
#include "dive.h"
#include "device.h"
#include "membuffer.h"
-#include "ssrf-version.h"
+#include "version.h"
/*
* handle libgit2 revision 0.20 and earlier
@@ -104,8 +104,6 @@ static void show_utf8(struct membuffer *b, const char *prefix, const char *value
static void save_overview(struct membuffer *b, struct dive *dive)
{
- show_gps(b, dive->latitude, dive->longitude);
- show_utf8(b, "location ", dive->location, "\n");
show_utf8(b, "divemaster ", dive->divemaster, "\n");
show_utf8(b, "buddy ", dive->buddy, "\n");
show_utf8(b, "suit ", dive->suit, "\n");
@@ -390,6 +388,7 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b)
SAVE("visibility", visibility);
cond_put_format(dive->tripflag == NO_TRIP, b, "notrip\n");
save_tags(b, dive->tag_list);
+ cond_put_format(dive->dive_site_uuid, b, "divesiteid %08x\n", dive->dive_site_uuid);
save_overview(b, dive);
save_cylinder_info(b, dive);
@@ -586,6 +585,7 @@ static int save_one_picture(git_repository *repo, struct dir *dir, struct pictur
show_utf8(&buf, "filename ", pic->filename, "\n");
show_gps(&buf, pic->latitude, pic->longitude);
+ show_utf8(&buf, "hash ", pic->hash, "\n");
/* Picture loading will load even negative offsets.. */
if (offset < 0) {
@@ -804,7 +804,7 @@ static void save_one_device(void *_b, const char *model, uint32_t deviceid,
put_string(b, "\n");
}
-#define VERSION 2
+#define VERSION 3
static void save_settings(git_repository *repo, struct dir *tree)
{
@@ -818,6 +818,38 @@ static void save_settings(git_repository *repo, struct dir *tree)
blob_insert(repo, tree, &b, "00-Subsurface");
}
+static void save_divesites(git_repository *repo, struct dir *tree)
+{
+ struct dir *subdir;
+ struct membuffer dirname = { 0 };
+ put_format(&dirname, "01-Divesites");
+ subdir = new_directory(repo, tree, &dirname);
+
+ for (int i = 0; i < dive_site_table.nr; i++) {
+ struct membuffer b = { 0 };
+ struct dive_site *ds = get_dive_site(i);
+ if (dive_site_is_empty(ds)) {
+ int j;
+ struct dive *d;
+ for_each_dive(j, d) {
+ if (d->dive_site_uuid == ds->uuid)
+ d->dive_site_uuid = 0;
+ }
+ delete_dive_site(get_dive_site(i)->uuid);
+ i--; // since we just deleted that one
+ continue;
+ }
+ int size = sizeof("Site-012345678");
+ char name[size];
+ snprintf(name, size, "Site-%08x", ds->uuid);
+ show_utf8(&b, "name ", ds->name, "\n");
+ show_utf8(&b, "description ", ds->description, "\n");
+ show_utf8(&b, "notes ", ds->notes, "\n");
+ show_gps(&b, ds->latitude, ds->longitude);
+ blob_insert(repo, subdir, &b, name);
+ }
+}
+
static int create_git_tree(git_repository *repo, struct dir *root, bool select_only)
{
int i;
@@ -826,6 +858,8 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
save_settings(repo, root);
+ save_divesites(repo, root);
+
for (trip = dive_trip_list; trip != NULL; trip = trip->next)
trip->index = 0;
@@ -938,7 +972,7 @@ static void create_commit_message(struct membuffer *msg)
if (dive) {
dive_trip_t *trip = dive->divetrip;
- const char *location = dive->location ? : "no location";
+ const char *location = get_dive_location(dive) ? : "no location";
struct divecomputer *dc = &dive->dc;
const char *sep = "\n";
@@ -957,7 +991,7 @@ static void create_commit_message(struct membuffer *msg)
} while ((dc = dc->next) != NULL);
put_format(msg, "\n");
}
- put_format(msg, "Created by subsurface %s\n", VERSION_STRING);
+ put_format(msg, "Created by subsurface %s\n", subsurface_version());
}
static int create_new_commit(git_repository *repo, const char *branch, git_oid *tree_id)
@@ -1094,73 +1128,6 @@ static int do_git_save(git_repository *repo, const char *branch, bool select_onl
return create_new_commit(repo, branch, &id);
}
-/*
- * If it's not a git repo, return NULL. Be very conservative.
- */
-struct git_repository *is_git_repository(const char *filename, const char **branchp)
-{
- int flen, blen, ret;
- struct stat st;
- git_repository *repo;
- char *loc, *branch;
-
- flen = strlen(filename);
- if (!flen || filename[--flen] != ']')
- return NULL;
-
- /* Find the matching '[' */
- blen = 0;
- while (flen && filename[--flen] != '[')
- blen++;
-
- if (!flen)
- return NULL;
-
- /*
- * This is the "point of no return": the name matches
- * the git repository name rules, and we will no longer
- * return NULL.
- *
- * We will either return "dummy_git_repository" and the
- * branch pointer will have the _whole_ filename in it,
- * or we will return a real git repository with the
- * branch pointer being filled in with just the branch
- * name.
- *
- * The actual git reading/writing routines can use this
- * to generate proper error messages.
- */
- *branchp = filename;
- loc = malloc(flen+1);
- if (!loc)
- return dummy_git_repository;
- memcpy(loc, filename, flen);
- loc[flen] = 0;
-
- branch = malloc(blen+1);
- if (!branch) {
- free(loc);
- return dummy_git_repository;
- }
- memcpy(branch, filename+flen+1, blen);
- branch[blen] = 0;
-
- if (stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) {
- free(loc);
- free(branch);
- return dummy_git_repository;
- }
-
- ret = git_repository_open(&repo, loc);
- free(loc);
- if (ret < 0) {
- free(branch);
- return dummy_git_repository;
- }
- *branchp = branch;
- return repo;
-}
-
int git_save_dives(struct git_repository *repo, const char *branch, bool select_only)
{
int ret;