[PATCH 3/4] Allow creating new dive site with specific uuid

Miika Turkia miika.turkia at gmail.com
Fri Jul 24 09:53:21 PDT 2015


Test cases require deterministic results and thus we should allow uuid
to be specified when needed.

Signed-off-by: Miika Turkia <miika.turkia at gmail.com>
---
 divesite.c  | 11 +++++++----
 divesite.h  |  2 +-
 load-git.c  |  2 +-
 parse-xml.c |  2 +-
 4 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/divesite.c b/divesite.c
index 4348461..4ffdcd7 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 d1d6ba9..71f64a0 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 649663f..d1fa3e3 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 4936bcd..d235f2e 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;
-- 
2.1.4



More information about the subsurface mailing list