diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-12-23 12:46:45 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-09 20:58:04 -0800 |
commit | 1593f2ebad25244fefabe606b32ee505d4d6087d (patch) | |
tree | a47251b4247cbe0c2b5b2fa568179f8abc4c25f9 /core/dive.c | |
parent | f542dc4030dda5dac1da1cc928f7a40a50919c4d (diff) | |
download | subsurface-1593f2ebad25244fefabe606b32ee505d4d6087d.tar.gz |
Import: merge dives trip-wise
The old way of merging log-files was not well defined: Trips
were recognized as the same if and only if the first dives
started at the same instant. Later dives did not matter.
Change this to merge dives if they are overlapping.
Moreover, on parsing and download generate trips in a separate
trip-table.
This will be fundamental for undo of dive-import: Firstly, we
don't want to mix trips of imported and not-yet imported dives.
Secondly, by merging trip-wise, we can autogroup the dives
in the import-data to trips and merge these at once. This will
simplify the code to decide to which trip dives should be
autogrouped.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/dive.c')
-rw-r--r-- | core/dive.c | 51 |
1 files changed, 12 insertions, 39 deletions
diff --git a/core/dive.c b/core/dive.c index 36d05dad5..ba3f7bbe6 100644 --- a/core/dive.c +++ b/core/dive.c @@ -2556,24 +2556,9 @@ static void merge_temperatures(struct dive *res, const struct dive *a, const str } /* - * When merging two dives, this picks the trip from one, and removes it - * from the other. - * - * The 'next' dive is not involved in the dive merging, but is the dive - * that will be the next dive after the merged dive. - */ -static void pick_trip(struct dive *res, const struct dive *pick) -{ - dive_trip_t *trip = pick->divetrip; - - res->notrip = pick->notrip; - add_dive_to_trip(res, trip); -} - -/* * Pick a trip for a dive */ -static const struct dive *get_preferred_trip(const struct dive *a, const struct dive *b) +static struct dive_trip *get_preferred_trip(const struct dive *a, const struct dive *b) { dive_trip_t *atrip, *btrip; @@ -2581,33 +2566,33 @@ static const struct dive *get_preferred_trip(const struct dive *a, const struct atrip = a->divetrip; btrip = b->divetrip; if (!atrip) - return b; + return btrip; if (!btrip) - return a; + return atrip; /* Both dives have a trip - prefer the non-autogenerated one */ if (atrip->autogen && !btrip->autogen) - return b; + return btrip; if (!atrip->autogen && btrip->autogen) - return a; + return atrip; /* Otherwise, look at the trip data and pick the "better" one */ if (!atrip->location) - return b; + return btrip; if (!btrip->location) - return a; + return atrip; if (!atrip->notes) - return b; + return btrip; if (!btrip->notes) - return a; + return atrip; /* * Ok, so both have location and notes. * Pick the earlier one. */ if (a->when < b->when) - return a; - return b; + return atrip; + return btrip; } #if CURRENTLY_NOT_USED @@ -2903,14 +2888,6 @@ static int likely_same_dive(const struct dive *a, const struct dive *b) same_string(b->dc.model, "manually added dive")) return 0; - /* Don't try to merge dives with different trip information - * Exception: if the dive is downloaded without any - * explicit trip information, we do want to merge it - * with existing old dives even if they have trips. - */ - if (a->divetrip != b->divetrip && b->divetrip) - return 0; - /* * Do some basic sanity testing of the values we * have filled in during 'fixup_dive()' @@ -3403,7 +3380,6 @@ bool has_planned(const struct dive *dive, bool planned) { struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset, bool prefer_downloaded, struct dive_trip **trip) { struct dive *res = alloc_dive(); - const struct dive *preferred_trip; int cylinders_map_a[MAX_CYLINDERS], cylinders_map_b[MAX_CYLINDERS]; if (offset) { @@ -3424,11 +3400,8 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset, } res->when = prefer_downloaded ? b->when : a->when; res->selected = a->selected || b->selected; - preferred_trip = get_preferred_trip(a, b); if (trip) - *trip = preferred_trip->divetrip; - else - pick_trip(res, preferred_trip); + *trip = get_preferred_trip(a, b); MERGE_TXT(res, a, b, notes, "\n--\n"); MERGE_TXT(res, a, b, buddy, ", "); MERGE_TXT(res, a, b, divemaster, ", "); |