summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divesite.c14
-rw-r--r--divesite.h1
-rw-r--r--load-git.c23
3 files changed, 30 insertions, 8 deletions
diff --git a/divesite.c b/divesite.c
index c9dbb095a..d9351e1af 100644
--- a/divesite.c
+++ b/divesite.c
@@ -67,3 +67,17 @@ uint32_t dive_site_uuid_by_name(const char *name)
return id;
}
+
+/* if the uuid is valid, just get the site, otherwise create it first;
+ * so you can call this with dive->dive_site_uuid and you'll either get the existing
+ * dive site or it will create a new one - so make sure you assign the uuid back to
+ * dive->dive_site_uuid when using this function! */
+struct dive_site *get_or_create_dive_site_by_uuid(uint32_t uuid)
+{
+ struct dive_site *ds = get_dive_site_by_uuid(uuid);
+
+ if (!ds)
+ ds = alloc_dive_site();
+
+ return ds;
+}
diff --git a/divesite.h b/divesite.h
index b3487c341..f0cf08067 100644
--- a/divesite.h
+++ b/divesite.h
@@ -60,6 +60,7 @@ struct dive_site *alloc_dive_site();
uint32_t create_dive_site(const char *name);
uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude);
uint32_t dive_site_uuid_by_name(const char *name);
+struct dive_site *get_or_create_dive_site_by_uuid(uint32_t uuid);
#ifdef __cplusplus
}
diff --git a/load-git.c b/load-git.c
index 7bd020bd5..4fcf1f600 100644
--- a/load-git.c
+++ b/load-git.c
@@ -23,13 +23,6 @@ struct keyword_action {
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
extern degrees_t parse_degrees(char *buf, char **end);
-static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
-{
- struct dive *dive = _dive;
-
- dive->latitude = parse_degrees(line, &line);
- dive->longitude = parse_degrees(line, &line);
-}
static char *get_utf8(struct membuffer *b)
{
@@ -145,8 +138,22 @@ static int get_index(const char *line)
static int get_hex(const char *line)
{ return strtoul(line, NULL, 16); }
+static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
+{
+ struct dive *dive = _dive;
+ struct dive_site *ds = get_or_create_dive_site_by_uuid(dive->dive_site_uuid);
+ dive->dive_site_uuid = ds->uuid;
+ ds->latitude = parse_degrees(line, &line);
+ ds->longitude = parse_degrees(line, &line);
+}
+
static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
-{ struct dive *dive = _dive; dive->location = get_utf8(str); }
+{
+ struct dive *dive = _dive;
+ struct dive_site *ds = get_or_create_dive_site_by_uuid(dive->dive_site_uuid);
+ dive->dive_site_uuid = ds->uuid;
+ ds->name = get_utf8(str);
+}
static void parse_dive_divemaster(char *line, struct membuffer *str, void *_dive)
{ struct dive *dive = _dive; dive->divemaster = get_utf8(str); }