Properly remove redundant dive computer information

We had logic to remove duplicate dive computer information after merging
dives, but it didn't actually work.

Why? Because we had used the 'res' dive computer pointer to traverse the
list of dive computers, so it no longer actually pointed to the first
dive computer in the result list any more, and so the "remove redundant"
code only removed redundant dive computers from a limited and incomplete
list.

Oops.

Also, before checking the whole event and sample list, check if it's the
exact same dive computer using our new "match_one_dc()" helper function,
and don't even bother checking for sample details if it is.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2012-12-16 12:33:37 -08:00 committed by Dirk Hohndel
parent 459696c90c
commit 7b457d1b5c

15
dive.c
View file

@ -1285,6 +1285,10 @@ static int same_dc(struct divecomputer *a, struct divecomputer *b)
int i;
struct event *eva, *evb;
i = match_one_dc(a, b);
if (i)
return i > 0;
if (a->when && b->when && a->when != b->when)
return 0;
if (a->samples != b->samples)
@ -1406,6 +1410,8 @@ static void interleave_dive_computers(struct divecomputer *res,
*/
static void join_dive_computers(struct divecomputer *res, struct divecomputer *a, struct divecomputer *b)
{
struct divecomputer *tmp;
if (a->model && !b->model) {
*res = *a;
clear_dc(a);
@ -1419,11 +1425,12 @@ static void join_dive_computers(struct divecomputer *res, struct divecomputer *a
*res = *a;
clear_dc(a);
while (res->next)
res = res->next;
tmp = res;
while (tmp->next)
tmp = tmp->next;
res->next = calloc(1, sizeof(*res));
*res->next = *b;
tmp->next = calloc(1, sizeof(*tmp));
*tmp->next = *b;
clear_dc(b);
remove_redundant_dc(res);