Make created dive site uuid deterministic

Having random uuids seemed like a good idea, but there are several
situations where they really cause problems. One is merging dive file
imports from V2 logfiles. Another is testing such imports.

Instead of making the uuid random we now hash the name and add the
timestamp of the first dive associated with this dive site to the hash
(first in this context is "first encountered" with no guarantee that it is
the chronologically first). This way V2 imports create deterministic uuids
but uuid conflicts are still extremely unlikely, even if the user has
multiple dive sites with the same name.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-08-24 10:37:18 -07:00
parent 6eed3155e6
commit e03b553e80
11 changed files with 60 additions and 37 deletions

View file

@ -179,7 +179,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive)
if (!ds) {
uuid = get_dive_site_uuid_by_gps(latitude, longitude, NULL);
if (!uuid)
uuid = create_dive_site_with_gps("", latitude, longitude);
uuid = create_dive_site_with_gps("", latitude, longitude, dive->when);
dive->dive_site_uuid = uuid;
} else {
if (dive_site_has_gps_location(ds) &&
@ -204,7 +204,7 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive)
if (!ds) {
uuid = get_dive_site_uuid_by_name(name, NULL);
if (!uuid)
uuid = create_dive_site(name);
uuid = create_dive_site(name, dive->when);
dive->dive_site_uuid = uuid;
} else {
// we already had a dive site linked to the dive
@ -1443,8 +1443,8 @@ 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(0);
ds->uuid = strtoul(suffix, NULL, 16);
uint32_t uuid = strtoul(suffix, NULL, 16);
struct dive_site *ds = alloc_dive_site(uuid);
git_blob *blob = git_tree_entry_blob(repo, entry);
if (!blob)
return report_error("Unable to read dive site file");