From 38c79d149db09cbb856e4827ce7a24d742c91917 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 10 Nov 2012 19:51:03 +0100 Subject: Simplify and clean up dive trip management This adds a couple of helper functions to manage dive trips ("add_dive_to_trip()" and "remove_dive_from_trip()") and makes those functions do the trip statistics maintenance (trip beginning times, number of dives, etc). This was needed because the dive merge cases for multiple dive computers showed some rather nasty special cases: especially if the new dive information has been loaded into an XML file with trips auto-generated, merging several of these kinds of xml files with multiple dives in several overlapping trips would completely confuse our previous code. In particular, auto-generated trips that had the exact same date as previous trips (because they were generated from the same dive computer) really confused the code that used the trip timestamp to manage the trips. Adding the helper functions allows us to get the general case right without having to have each piece of code that handles trip information having to bother about all the odd rules. It will eventually also allow us to make the dive trip data structures more logical: right now the dive trip list is largely designed around the odd gtk model handling, rather than some more higher-level conceptual relationship with the actual dives. But for now, this keeps all the data structures unchanged, and just modifies them using the new helper functions. Signed-off-by: Linus Torvalds Signed-off-by: Dirk Hohndel --- dive.c | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) (limited to 'dive.c') diff --git a/dive.c b/dive.c index 19d3cc5b0..4b894cb48 100644 --- a/dive.c +++ b/dive.c @@ -811,30 +811,9 @@ static void pick_and_delete_trip(struct dive *res, struct dive *pick, struct div dive_trip_t *trip = pick->divetrip; res->tripflag = tripflag; - res->divetrip = trip; - - /* - * We may have to change the trip date if we picked an earlier - * date for the dive that now uses it. - */ - if (res->when < trip->when) - trip->when = res->when; - - /* Was it the same trip as the removed dive? All good*/ - if (trip == remove->divetrip) - return; - - /* Ok, we're dropping a dive. We may need to fix up the date on it */ - trip = remove->divetrip; - if (trip->when != remove->when) - return; - - if (next && next->divetrip == trip) { - trip->when = next->when; - return; - } - - delete_trip(trip); + add_dive_to_trip(res, trip); + remove_dive_from_trip(pick); + remove_dive_from_trip(remove); } /* -- cgit v1.2.3-70-g09d2