summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-08 17:13:17 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-18 16:50:09 -0800
commit0618aa737fde54e634d16273ec0246ced9c454aa (patch)
tree0ebcb45cb2c3849d5b78fc979e9984380485a9a3
parentc48056300d61987850dbe9ad92b20a293d03dc75 (diff)
downloadsubsurface-0618aa737fde54e634d16273ec0246ced9c454aa.tar.gz
Core: unify insert_trip() and insert_trip_dont_merge()
There were two versions of the insert_trip() function: one would merge trips if a trip with the same date already existed, the other wouldn't. The latter was introduced with the dive-list undo work. The problem is that the "date" of a trip (i.e. the first dive) seems ill-defined as this is a volatile value. Moreover in the context of making dive-import undoable this is a very dangerous notion, as the caller needs control over when the dives are added to a trip. Therefore, unify these two functions and never merge trips. The decision on merging dives now has to made by the caller. This will be implemented in a future commit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/dive.h3
-rw-r--r--core/divelist.c48
-rw-r--r--core/load-git.c2
-rw-r--r--core/parse.c2
-rw-r--r--desktop-widgets/command_divelist.cpp4
-rw-r--r--mobile-widgets/qmlmanager.cpp2
6 files changed, 13 insertions, 48 deletions
diff --git a/core/dive.h b/core/dive.h
index 7e4336317..aa37eeb46 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -421,8 +421,7 @@ extern void delete_single_dive(int idx);
extern int dive_get_insertion_index(struct dive *dive);
extern void add_single_dive(int idx, struct dive *dive);
-extern void insert_trip(dive_trip_t **trip);
-extern void insert_trip_dont_merge(dive_trip_t *trip);
+extern void insert_trip(dive_trip_t *trip);
extern void unregister_trip(dive_trip_t *trip);
extern void free_trip(dive_trip_t *trip);
diff --git a/core/divelist.c b/core/divelist.c
index 6eb2b2389..52c724429 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -16,8 +16,7 @@
* int init_decompression(struct dive *dive)
* void update_cylinder_related_info(struct dive *dive)
* void dump_trip_list(void)
- * void insert_trip(dive_trip_t **dive_trip_p)
- * void insert_trip_dont_merge(dive_trip_t *dive_trip_p)
+ * void insert_trip(dive_trip_t *dive_trip_p)
* void unregister_trip(dive_trip_t *trip)
* void free_trip(dive_trip_t *trip)
* void remove_dive_from_trip(struct dive *dive)
@@ -742,56 +741,23 @@ void dump_trip_list(void)
}
#endif
-/* 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 */
-void insert_trip(dive_trip_t **dive_trip_p)
+/* insert the trip into the dive_trip_list */
+void insert_trip(dive_trip_t *dive_trip)
{
- 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)
p = &trip->next;
- 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;
- *p = dive_trip;
- }
+ dive_trip->next = trip;
+ *p = dive_trip;
#ifdef DEBUG_TRIP
dump_trip_list();
#endif
}
-/* same as insert_trip, but don't merge trips with the same date.
- * this is cruical for the merge undo-command, because there we
- * add a new trip with the same date and then remove the old one. */
-void insert_trip_dont_merge(dive_trip_t *dive_trip)
-{
- dive_trip_t **p = &dive_trip_list;
- dive_trip_t *trip;
-
- /* Walk the dive trip list looking for the right location.. */
- while ((trip = *p) != NULL && trip->when < dive_trip->when)
- p = &trip->next;
-
- dive_trip->next = trip;
- *p = dive_trip;
-}
-
/* free resources associated with a trip structure */
void free_trip(dive_trip_t *trip)
{
@@ -957,7 +923,7 @@ dive_trip_t *create_and_hookup_trip_from_dive(struct dive *dive)
dive_trip_t *dive_trip = alloc_trip();
dive_trip = create_trip_from_dive(dive);
- insert_trip(&dive_trip);
+ insert_trip(dive_trip);
dive->tripflag = IN_TRIP;
add_dive_to_trip(dive, dive_trip);
@@ -1072,7 +1038,7 @@ void autogroup_dives(void)
for(i = 0; (trip = get_dives_to_autogroup(i, &from, &to, &alloc)) != NULL; i = to) {
/* If this was newly allocated, add trip to list */
if (alloc)
- insert_trip(&trip);
+ insert_trip(trip);
for (j = from; j < to; ++j)
add_dive_to_trip(get_dive(j), trip);
}
diff --git a/core/load-git.c b/core/load-git.c
index 8483b9cf0..8e3254abd 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -1176,7 +1176,7 @@ static void finish_active_trip(void)
if (trip) {
active_trip = NULL;
- insert_trip(&trip);
+ insert_trip(trip);
}
}
diff --git a/core/parse.c b/core/parse.c
index 56e2e1b6f..f54d36742 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -279,7 +279,7 @@ void trip_end(struct parser_state *state)
{
if (!state->cur_trip)
return;
- insert_trip(&state->cur_trip);
+ insert_trip(state->cur_trip);
state->cur_trip = NULL;
}
diff --git a/desktop-widgets/command_divelist.cpp b/desktop-widgets/command_divelist.cpp
index e129fefdd..9f4ea8cd2 100644
--- a/desktop-widgets/command_divelist.cpp
+++ b/desktop-widgets/command_divelist.cpp
@@ -82,7 +82,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d)
dive *DiveListBase::addDive(DiveToAdd &d)
{
if (d.tripToAdd)
- insert_trip_dont_merge(d.tripToAdd.release()); // Return ownership to backend
+ insert_trip(d.tripToAdd.release()); // Return ownership to backend
if (d.trip)
add_dive_to_trip(d.dive.get(), d.trip);
dive *res = d.dive.release(); // Give up ownership of dive
@@ -259,7 +259,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives)
for (OwningTripPtr &trip: dives.tripsToAdd) {
dive_trip *t = trip.release(); // Give up ownership
createdTrips.push_back(t);
- insert_trip_dont_merge(t); // Return ownership to backend
+ insert_trip(t); // Return ownership to backend
}
dives.tripsToAdd.clear();
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 307acae5d..8bae01d86 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -1270,7 +1270,7 @@ bool QMLManager::undoDelete(int id)
return false;
}
if (deletedTrip)
- insert_trip(&deletedTrip);
+ insert_trip(deletedTrip);
if (deletedDive->divetrip) {
struct dive_trip *trip = deletedDive->divetrip;
tripflag_t tripflag = deletedDive->tripflag; // this gets overwritten in add_dive_to_trip()