summaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c51
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, ", ");