[PATCH 1/3] git-load: Add trips to the trip list on loading

Linus Torvalds torvalds at linux-foundation.org
Tue Mar 11 15:08:42 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Tue, 11 Mar 2014 14:48:03 -0700
Subject: [PATCH 1/3] git-load: Add trips to the trip list on loading

We don't actually much use the trip list any more, and it's possible we
should simply get rid of it.  I hadn't added the trips to the trip list
when loading them, and everything worked fine.

Well, *almost* everything worked fine.

There is one use of the list of trips, and that's the "clear the trip
index for each trip before saving them".  That literally seems to be the
only non-debug use of this list, but when we didn't add the trips to the
list, the trip index never got cleared before saving trips.

And even that is unnoticeable for the *first* save event, because the
trip index will have been clear before that.

But on the *second* save event, if the trip index doesn't get cleared
before saving, the saving code will look at the index, say "Hey, I
already saved this" and skip the trip.

So if you loaded the trips from a git repository, and then saved things,
everything worked fine.  But it you saved things a *second* time,
nothing would get saved at all, because all the trips were marked as
saved already.

Anyway, I think the real solution is to get rid of the pointless trip
list, and just use "for_each_dive()" to find all the trips, since that
list clearly is just more pain than gain.  But in the meantime, this
makes the git loading add the trips properly to the list.

Signed-off-by: Linus "oops" Torvalds <torvalds at linux-foundation.org>
---

Annoying bug due to silly data structures. The whole "remove duplicate 
trips with same date" thing is also likely a major mistake. Whatever, 
doesn't matter, this makes the git saving code work ok.

 load-git.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)

diff --git a/load-git.c b/load-git.c
index 09e07ded8c62..15c48027bde2 100644
--- a/load-git.c
+++ b/load-git.c
@@ -836,6 +836,26 @@ static struct divecomputer *active_dc;
 static struct dive *active_dive;
 static dive_trip_t *active_trip;
 
+static void finish_active_trip(void)
+{
+	dive_trip_t *trip = active_trip;
+
+	if (trip) {
+		active_trip = NULL;
+		insert_trip(&trip);
+	}
+}
+
+static void finish_active_dive(void)
+{
+	struct dive *dive = active_dive;
+
+	if (dive) {
+		active_dive = NULL;
+		record_dive(dive);
+	}
+}
+
 static struct dive *create_new_dive(timestamp_t when)
 {
 	struct dive *dive = alloc_dive();
@@ -888,6 +908,7 @@ static int dive_trip_directory(const char *root, const char *name)
 	dd = atoi(name);
 	if (!validate_date(yyyy, mm, dd))
 		return GIT_WALK_SKIP;
+	finish_active_trip();
 	active_trip = create_new_trip(yyyy, mm, dd);
 	return GIT_WALK_OK;
 }
@@ -941,7 +962,7 @@ static int dive_directory(const char *root, const char *name, int timeoff)
 	 * of a pathname of the form 'yyyy/mm/'.
 	 */
 	if (strlen(root) == 8)
-		active_trip = NULL;
+		finish_active_trip();
 
 	/*
 	 * Get the date. The day of the month is in the dive directory
@@ -969,8 +990,7 @@ static int dive_directory(const char *root, const char *name, int timeoff)
 	tm.tm_mon = mm-1;
 	tm.tm_mday = dd;
 
-	if (active_dive)
-		record_dive(active_dive);
+	finish_active_dive();
 	active_dive = create_new_dive(utc_mktime(&tm));
 	return GIT_WALK_OK;
 }
@@ -1220,8 +1240,7 @@ int git_load_dives(char *where)
 
 	ret = do_git_load(repo, branch);
 	git_repository_free(repo);
-	if (active_dive)
-		record_dive(active_dive);
-	active_dive = NULL;
+	finish_active_dive();
+	finish_active_trip();
 	return ret;
 }
-- 
1.9.0




More information about the subsurface mailing list