summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-11-24 17:06:06 -1000
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-11-25 13:05:04 -0800
commit5a4640cf44bc08788eb13ab44a5f84ccf75e4a75 (patch)
treeef26d17e6a28316678af0e2168c367dde437f84a
parentc019da8fd5e09ee9efd7f158c68e8afaf7140e56 (diff)
downloadsubsurface-5a4640cf44bc08788eb13ab44a5f84ccf75e4a75.tar.gz
Match newly downloaded dives against dive computer information
Now that we have more complete dive computer information, we can use that to match the dives we download, and stop with the hacky "Would we merge this" check. For XML files without the explicit dive computer information, go back to checking the exact dive time. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--libdivecomputer.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/libdivecomputer.c b/libdivecomputer.c
index 48680c7ce..82b1ba3cd 100644
--- a/libdivecomputer.c
+++ b/libdivecomputer.c
@@ -182,21 +182,37 @@ 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)
+{
+ if (a->when != b->when)
+ return 0;
+ if (a->vendor && b->vendor && strcasecmp(a->vendor, b->vendor))
+ return 0;
+ if (a->product && b->product && strcasecmp(a->product, b->product))
+ return 0;
+ return 1;
+}
+
/*
* Check if this dive already existed before the import
*/
-static int find_dive(struct dive *dive, device_data_t *devdata)
+static int find_dive(struct divecomputer *match)
{
int i;
for (i = 0; i < dive_table.preexisting; i++) {
struct dive *old = dive_table.dives[i];
+ struct divecomputer *dc = &old->dc;
- if (dive->when > old->when + 60)
- continue;
- if (dive->when + 60 < old->when)
- continue;
- return 1;
+ /* Old-style dive with no explicit divecomputer information? */
+ if (!dc->when && old->when == match->when)
+ return 1;
+
+ do {
+ if (match_dc(dc, match))
+ return 1;
+ dc = dc->next;
+ } while (dc);
}
return 0;
}
@@ -314,7 +330,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dc_parser_destroy(parser);
/* If we already saw this dive, abort. */
- if (!devdata->force_download && find_dive(dive, devdata))
+ if (!devdata->force_download && find_dive(&dive->dc))
return 0;
dive->downloaded = TRUE;