diff options
author | Miika Turkia <miika.turkia@gmail.com> | 2015-07-24 19:53:21 +0300 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-07-24 13:20:57 -0700 |
commit | 76fe262a0ffac68cf61da470772d2e370d9e019d (patch) | |
tree | a1f9e39bc1fcbc3e27e274e028da36e7ce7ff314 | |
parent | 0d2d91a28c1c10a0ee36c42610f618265a5f48be (diff) | |
download | subsurface-76fe262a0ffac68cf61da470772d2e370d9e019d.tar.gz |
Allow creating new dive site with specific uuid
Test cases require deterministic results and thus we should allow uuid
to be specified when needed.
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | divesite.c | 11 | ||||
-rw-r--r-- | divesite.h | 2 | ||||
-rw-r--r-- | load-git.c | 2 | ||||
-rw-r--r-- | parse-xml.c | 2 |
4 files changed, 10 insertions, 7 deletions
diff --git a/divesite.c b/divesite.c index 4348461c6..4ffdcd78f 100644 --- a/divesite.c +++ b/divesite.c @@ -86,7 +86,7 @@ static uint32_t dive_site_getUniqId() return id; } -struct dive_site *alloc_dive_site() +struct dive_site *alloc_dive_site(uint32_t uuid) { int nr = dive_site_table.nr, allocated = dive_site_table.allocated; struct dive_site **sites = dive_site_table.dive_sites; @@ -104,7 +104,10 @@ struct dive_site *alloc_dive_site() exit(1); sites[nr] = ds; dive_site_table.nr = nr + 1; - ds->uuid = dive_site_getUniqId(); + if (uuid) + ds->uuid = uuid; + else + ds->uuid = dive_site_getUniqId(); return ds; } @@ -157,7 +160,7 @@ void delete_dive_site(uint32_t id) /* allocate a new site and add it to the table */ uint32_t create_dive_site(const char *name) { - struct dive_site *ds = alloc_dive_site(); + struct dive_site *ds = alloc_dive_site(0); ds->name = copy_string(name); return ds->uuid; @@ -166,7 +169,7 @@ uint32_t create_dive_site(const char *name) /* same as before, but with GPS data */ uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude) { - struct dive_site *ds = alloc_dive_site(); + struct dive_site *ds = alloc_dive_site(0); ds->name = copy_string(name); ds->latitude = latitude; ds->longitude = longitude; diff --git a/divesite.h b/divesite.h index d1d6ba9ae..71f64a0a1 100644 --- a/divesite.h +++ b/divesite.h @@ -49,7 +49,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid) return NULL; } -struct dive_site *alloc_dive_site(); +struct dive_site *alloc_dive_site(uint32_t uuid); int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only); bool is_dive_site_used(uint32_t uuid, bool select_only); void delete_dive_site(uint32_t id); diff --git a/load-git.c b/load-git.c index 649663f2d..d1fa3e3dd 100644 --- a/load-git.c +++ b/load-git.c @@ -1437,7 +1437,7 @@ static int parse_site_entry(git_repository *repo, const git_tree_entry *entry, c { if (*suffix == '\0') return report_error("Dive site without uuid"); - struct dive_site *ds = alloc_dive_site(); + struct dive_site *ds = alloc_dive_site(0); ds->uuid = strtoul(suffix, NULL, 16); git_blob *blob = git_tree_entry_blob(repo, entry); if (!blob) diff --git a/parse-xml.c b/parse-xml.c index 4936bcd2d..d235f2e83 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -1517,7 +1517,7 @@ static void dive_site_end(void) if (!cur_dive_site) return; if (cur_dive_site->uuid) { - struct dive_site *ds = alloc_dive_site(); + struct dive_site *ds = alloc_dive_site(0); if (cur_dive_site->taxonomy.nr == 0) { free(cur_dive_site->taxonomy.category); cur_dive_site->taxonomy.category = NULL; |