[PATCH 2/2] Be stricter about when we allow merging of dives

Linus Torvalds torvalds at linux-foundation.org
Sun Nov 11 06:07:59 PST 2012


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sun, 11 Nov 2012 15:02:50 +0100
Subject: [PATCH 2/2] Be stricter about when we allow merging of dives

If the surface interval between two dives is more than half an hour,
don't try to call it a single dive.  Just the dive profile will be
looking ridiculous.

Things like tank refills etc could also be a good thing to check (again,
the dive profile would look ridiculous), but the cylinder pressure going
up a small amount is actually normal (ie cylinder warming up in warmer
water on the surface).  So I don't know what the proper limit for that
would be.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
 divelist.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/divelist.c b/divelist.c
index fd55dcd60579..d264c0758656 100644
--- a/divelist.c
+++ b/divelist.c
@@ -2118,16 +2118,25 @@ static void merge_dives_cb(GtkWidget *menuitem, void *unused)
 /* Called if there are exactly two selected dives and the dive at idx is one of them */
 static void add_dive_merge_label(int idx, GtkMenuShell *menu)
 {
-	struct dive *d;
+	struct dive *a, *b;
 	GtkWidget *menuitem;
 
 	/* The other selected dive must be next to it.. */
-	if (!((d = get_dive(idx-1)) && d->selected) &&
-	    !((d = get_dive(idx+1)) && d->selected))
-		return;
+	a = get_dive(idx);
+	b = get_dive(idx+1);
+	if (!b || !b->selected) {
+		b = a;
+		a = get_dive(idx-1);
+		if (!a || !a->selected)
+			return;
+	}
 
 	/* .. and they had better be in the same dive trip */
-	if (d->divetrip != get_dive(idx)->divetrip)
+	if (a->divetrip != b->divetrip)
+		return;
+
+	/* .. and if the surface interval is excessive, you must be kidding us */
+	if (b->when > a->when + a->duration.seconds + 30*60)
 		return;
 
 	/* If so, we can add a "merge dive" menu entry */
-- 
1.8.0



More information about the subsurface mailing list