From 936d289cb7d5c1af9aa47784557bbf053cdbb988 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Thu, 6 Dec 2012 13:04:37 -0800 Subject: [PATCH] Fix insert_trip to correctly deal with trips that start at the same time The existing code did not move the dives that are part of the second trip to the first trip (and forgot to keep the 'better' notes as well). Signed-off-by: Dirk Hohndel --- divelist.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/divelist.c b/divelist.c index 128ee0c99..7a2f4fa5b 100644 --- a/divelist.c +++ b/divelist.c @@ -1008,6 +1008,7 @@ void insert_trip(dive_trip_t **dive_trip_p) dive_trip_t *dive_trip = *dive_trip_p; dive_trip_t **p = &dive_trip_list; dive_trip_t *trip; + struct dive *divep; /* Walk the dive trip list looking for the right location.. */ while ((trip = *p) != NULL && trip->when < dive_trip->when) @@ -1016,6 +1017,13 @@ void insert_trip(dive_trip_t **dive_trip_p) if (trip && trip->when == dive_trip->when) { if (! trip->location) trip->location = dive_trip->location; + if (! trip->notes) + trip->notes = dive_trip->notes; + divep = dive_trip->dives; + while (divep) { + add_dive_to_trip(divep, trip); + divep = divep->next; + } *dive_trip_p = trip; } else { dive_trip->next = trip; @@ -1829,6 +1837,7 @@ void merge_trips_cb(GtkWidget *menuitem, GtkTreePath *trippath) prevtrip = find_matching_trip(when); remember_tree_state(); /* move dives from trip */ + assert(thistrip != prevtrip); while (thistrip->dives) add_dive_to_trip(thistrip->dives, prevtrip); dive_list_update_dives();