summaryrefslogtreecommitdiffstats
path: root/divelist.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2013-01-07 14:12:07 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-07 14:55:42 -0800
commitc2bc6633ec19255aa5c083662f361250a3657b79 (patch)
tree0ea9aa85d6d1c19b46eb6d1452c795e0eb3998a6 /divelist.c
parent661a3809128f3d5d3af8d4a49d37558a2d9cf933 (diff)
downloadsubsurface-c2bc6633ec19255aa5c083662f361250a3657b79.tar.gz
Improve dive trip sort comparison function
We do want to compare "loose" dives too, but we need to be a bit careful, and always use the trip date as the primary sort key for any dives that are not in the same trip. Reported-and-tested-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r--divelist.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/divelist.c b/divelist.c
index 6397f62fd..6b09b7d3d 100644
--- a/divelist.c
+++ b/divelist.c
@@ -1461,15 +1461,18 @@ static gint dive_nr_sort(GtkTreeModel *model,
tripb = b->divetrip;
}
- if (!tripa || !tripb)
- return 0;
- if (tripa->when < tripb->when)
- return -1;
- if (tripa->when > tripb->when)
- return 1;
- if (a && b)
- return a->when - b->when;
- return 0;
+ /*
+ * Compare dive dates within the same trip (or when there
+ * are no trips involved at all). But if we have two
+ * different trips use the trip dates for comparison
+ */
+ if (tripa != tripb) {
+ if (tripa)
+ when_a = tripa->when;
+ if (tripb)
+ when_b = tripb->when;
+ }
+ return when_a - when_b;
}