summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-10-29 11:27:14 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-10-29 11:46:33 -0700
commit2d4fee79853f1d81585beb62d36b68f1602fce5d (patch)
treee76bf594efddb054049b3cfb522fd8f947cc8ce5
parent029db4aae23feec665acb2c1aee7c07fafed3f0f (diff)
downloadsubsurface-2d4fee79853f1d81585beb62d36b68f1602fce5d.tar.gz
Fix merging of weight systems
I just tried downloading some duplicate dives I had on my second dive computer, and it all "just worked" and subsurface merged them for me. Almost perfectly. I say "almost", because in merging them, it threw my old weightsystem data away, due to that not being merged. Also, it was a perfect merge only because the computers are so similar that they just line everything up - same water activation logic, same sample interval, same pretty much everything. So while I know the sample merging is not really the right thing to do (it was designed to get the "merge the exact same dive from the same computer" case right), it worked well enough for this particular case. I'll look at something better later. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--dive.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/dive.c b/dive.c
index c61a02ca0..c855acef8 100644
--- a/dive.c
+++ b/dive.c
@@ -695,6 +695,23 @@ static void merge_cylinder_info(cylinder_t *res, cylinder_t *a, cylinder_t *b)
MERGE_MIN(res, a, b, end.mbar);
}
+static void merge_weightsystem_info(weightsystem_t *res, weightsystem_t *a, weightsystem_t *b)
+{
+ if (!a->weight.grams)
+ a = b;
+ *res = *a;
+}
+
+static void merge_equipment(struct dive *res, struct dive *a, struct dive *b)
+{
+ int i;
+
+ for (i = 0; i < MAX_CYLINDERS; i++)
+ merge_cylinder_info(res->cylinder+i, a->cylinder + i, b->cylinder + i);
+ for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
+ merge_weightsystem_info(res->weightsystem+i, a->weightsystem + i, b->weightsystem + i);
+}
+
/*
* This could do a lot more merging. Right now it really only
* merges almost exact duplicates - something that happens easily
@@ -702,7 +719,6 @@ static void merge_cylinder_info(cylinder_t *res, cylinder_t *a, cylinder_t *b)
*/
struct dive *try_to_merge(struct dive *a, struct dive *b)
{
- int i;
struct dive *res;
if ((a->when >= b->when + 60) || (a->when <= b->when - 60))
@@ -734,8 +750,7 @@ struct dive *try_to_merge(struct dive *a, struct dive *b)
MERGE_MAX(res, a, b, surfacetime.seconds);
MERGE_MAX(res, a, b, airtemp.mkelvin);
MERGE_MIN(res, a, b, watertemp.mkelvin);
- for (i = 0; i < MAX_CYLINDERS; i++)
- merge_cylinder_info(res->cylinder+i, a->cylinder + i, b->cylinder + i);
+ merge_equipment(res, a, b);
merge_events(res, a, b, 0);
return merge_samples(res, a, b, 0);
}