diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2012-12-16 10:40:17 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2012-12-16 15:48:09 -1000 |
commit | 459696c90c94834b7498a1b20cd6ccb85bfaa9e0 (patch) | |
tree | 6e8b3b12ea81248f5c9bcb0475ee5f53343bb3ca /libdivecomputer.c | |
parent | 73defa9a52e9c22fa6c87b6c2ff779da213efd1a (diff) | |
download | subsurface-459696c90c94834b7498a1b20cd6ccb85bfaa9e0.tar.gz |
Use dive ID for matching dives during downloads
If we have a dive computer model and dive ID, use that to match newly
downloaded dives against the existing dives.
Otherwise fall back to "exact date match" again, like we've always done.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'libdivecomputer.c')
-rw-r--r-- | libdivecomputer.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c index 51c6a5775..971d70948 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -231,13 +231,32 @@ static int parse_samples(device_data_t *devdata, struct divecomputer *dc, dc_par return dc_parser_samples_foreach(parser, sample_cb, dc); } -static inline int match_dc(struct divecomputer *a, struct divecomputer *b) +static int match_one_dive(struct divecomputer *a, struct dive *dive) { - if (a->when != b->when) - return 0; - if (a->model && b->model && strcasecmp(a->model, b->model)) - return 0; - return 1; + struct divecomputer *b = &dive->dc; + + /* + * Walk the existing dive computer data, + * see if we have a match (or an anti-match: + * the same dive computer but a different + * dive ID). + */ + do { + int match = match_one_dc(a, b); + if (match) + return match > 0; + b = b->next; + } while (b); + + /* Ok, no exact dive computer match. Does the date match? */ + b = &dive->dc; + do { + if (a->when == b->when) + return 1; + b = b->next; + } while (b); + + return 0; } /* @@ -249,17 +268,9 @@ static int find_dive(struct divecomputer *match) for (i = 0; i < dive_table.preexisting; i++) { struct dive *old = dive_table.dives[i]; - struct divecomputer *dc = &old->dc; - /* Old-style dive with no explicit divecomputer information? */ - if (!dc->when && old->when == match->when) + if (match_one_dive(match, old)) return 1; - - do { - if (match_dc(dc, match)) - return 1; - dc = dc->next; - } while (dc); } return 0; } |