mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-01 06:30:26 +00:00
Avoid duplicate dive_trip entries
When inserting a trip into the dive_trip_list we already check for duplicate trips, but we still kept the additional dive_trip around. With this change we instead replace it with the existing one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
6d0af91398
commit
4679f4fbbc
3 changed files with 8 additions and 11 deletions
10
dive.h
10
dive.h
|
@ -305,14 +305,16 @@ static void dump_trip_list(void)
|
|||
/* insert the trip into the dive_trip_list - but ensure you don't have
|
||||
* two trips for the same date; but if you have, make sure you don't
|
||||
* keep the one with less information */
|
||||
static inline void insert_trip(struct dive *_trip)
|
||||
static void inline insert_trip(struct dive **trip)
|
||||
{
|
||||
GList *result = FIND_TRIP(_trip->when);
|
||||
struct dive *dive_trip = *trip;
|
||||
GList *result = FIND_TRIP(dive_trip->when);
|
||||
if (result) {
|
||||
if (! DIVE_TRIP(result)->location)
|
||||
DIVE_TRIP(result)->location = _trip->location;
|
||||
DIVE_TRIP(result)->location = dive_trip->location;
|
||||
*trip = DIVE_TRIP(result);
|
||||
} else {
|
||||
dive_trip_list = g_list_insert_sorted(dive_trip_list, (_trip), dive_date_cmp);
|
||||
dive_trip_list = g_list_insert_sorted(dive_trip_list, dive_trip, dive_date_cmp);
|
||||
}
|
||||
#ifdef DEBUG_TRIP
|
||||
dump_trip_list();
|
||||
|
|
|
@ -921,7 +921,7 @@ static struct dive *create_and_hookup_trip_from_dive(struct dive *dive)
|
|||
dive_trip->when = dive->when;
|
||||
if (dive->location)
|
||||
dive_trip->location = strdup(dive->location);
|
||||
insert_trip(dive_trip);
|
||||
insert_trip(&dive_trip);
|
||||
dive->divetrip = dive_trip;
|
||||
dive->tripflag = IN_TRIP;
|
||||
return dive_trip;
|
||||
|
|
|
@ -39,11 +39,6 @@ void record_dive(struct dive *dive)
|
|||
dive_table.nr = nr+1;
|
||||
}
|
||||
|
||||
void record_trip(struct dive *trip)
|
||||
{
|
||||
insert_trip(trip);
|
||||
}
|
||||
|
||||
static void delete_dive_renumber(struct dive **dives, int i, int nr)
|
||||
{
|
||||
struct dive *dive = dives[i];
|
||||
|
@ -1213,7 +1208,7 @@ static void trip_end(void)
|
|||
{
|
||||
if (!cur_trip)
|
||||
return;
|
||||
record_trip(cur_trip);
|
||||
insert_trip(&cur_trip);
|
||||
cur_trip = NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue