mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
When merging dives, keep dive ids in mind
We try to do the most reasonable thing. If you have an existing dive and merge a just downloaded dive with it - the you want the existing id. If you merge two consecutive dives, then the start of the merged dive is the earlier of those two dives so we keep that id. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
65e9fecd80
commit
9c617534a0
1 changed files with 11 additions and 0 deletions
11
divelist.c
11
divelist.c
|
@ -792,6 +792,7 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
|
|||
{
|
||||
struct dive *res;
|
||||
int i,j;
|
||||
int id = a->id;
|
||||
|
||||
if (!a || !b)
|
||||
return NULL;
|
||||
|
@ -804,6 +805,10 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
|
|||
add_single_dive(i, res);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(j);
|
||||
// now make sure that we keep the id of the first dive.
|
||||
// why?
|
||||
// because this way one of the previously selected ids is still around
|
||||
res->id = id;
|
||||
mark_divelist_changed(TRUE);
|
||||
return res;
|
||||
}
|
||||
|
@ -956,6 +961,7 @@ void process_dives(bool is_imported, bool prefer_imported)
|
|||
struct dive *prev = pp[0];
|
||||
struct dive *dive = pp[1];
|
||||
struct dive *merged;
|
||||
int id;
|
||||
|
||||
/* only try to merge overlapping dives - or if one of the dives has
|
||||
* zero duration (that might be a gps marker from the webservice) */
|
||||
|
@ -967,6 +973,9 @@ void process_dives(bool is_imported, bool prefer_imported)
|
|||
if (!merged)
|
||||
continue;
|
||||
|
||||
// remember the earlier dive's id
|
||||
id = prev->id;
|
||||
|
||||
/* careful - we might free the dive that last points to. Oops... */
|
||||
if (last == prev || last == dive)
|
||||
last = merged;
|
||||
|
@ -976,6 +985,8 @@ void process_dives(bool is_imported, bool prefer_imported)
|
|||
add_single_dive(i, merged);
|
||||
delete_single_dive(i+1);
|
||||
delete_single_dive(i+1);
|
||||
// keep the id or the first dive for the merged dive
|
||||
merged->id = id;
|
||||
}
|
||||
/* make sure no dives are still marked as downloaded */
|
||||
for (i = 1; i < dive_table.nr; i++)
|
||||
|
|
Loading…
Add table
Reference in a new issue