From 420afeef570cd4989dac60ac6376929ca1cc9a03 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Mon, 24 Aug 2015 11:07:57 -0700 Subject: Save XML: sort the dive sites by uuid This makes it much easier to compare XML files written by Subsurface. The order of the dive_site_table depended on the order in which they were encountered. This makes it easier to eye-ball changes in XML files. And allows the GitStorage test to pass. Signed-off-by: Dirk Hohndel --- divesite.c | 12 ++++++++++++ divesite.h | 1 + save-xml.c | 3 ++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/divesite.c b/divesite.c index 035c1b82d..93bd35e59 100644 --- a/divesite.c +++ b/divesite.c @@ -263,3 +263,15 @@ uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t diveti return ds->uuid; return create_dive_site(name, divetime); } + +static int compare_sites(const void *_a, const void *_b) +{ + const struct dive_site *a = (const struct dive_site *)*(void **)_a; + const struct dive_site *b = (const struct dive_site *)*(void **)_b; + return a->uuid > b->uuid ? 1 : a->uuid == b->uuid ? 0 : -1; +} + +void dive_site_table_sort() +{ + qsort(dive_site_table.dive_sites, dive_site_table.nr, sizeof(struct dive_site *), compare_sites); +} diff --git a/divesite.h b/divesite.h index 1dd1d04e8..52901e9b4 100644 --- a/divesite.h +++ b/divesite.h @@ -49,6 +49,7 @@ static inline struct dive_site *get_dive_site_by_uuid(uint32_t uuid) return NULL; } +void dive_site_table_sort(); 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); diff --git a/save-xml.c b/save-xml.c index 67ae96a37..778218fa4 100644 --- a/save-xml.c +++ b/save-xml.c @@ -507,7 +507,8 @@ void save_dives_buffer(struct membuffer *b, const bool select_only) put_format(b, " \n"); put_format(b, "\n"); - /* save the dive sites */ + /* save the dive sites - to make the output consistent let's sort the table, first */ + dive_site_table_sort(); put_format(b, "\n"); for (i = 0; i < dive_site_table.nr; i++) { int j; -- cgit v1.2.3-70-g09d2