[PATCH 04/12] git dive loading: actually insert the dives into the dive table

Linus Torvalds torvalds at linux-foundation.org
Sun Mar 9 18:43:14 PDT 2014


From: Linus Torvalds <torvalds at linux-foundation.org>
Date: Sat, 8 Mar 2014 08:35:23 -0800
Subject: [PATCH 04/12] git dive loading: actually insert the dives into the dive table

The biggest part of this commit is the comment about the woeful state of
the "git_tree_walk()" interface - the interface is not really very good
for seeing any recursive state, since it just walks the tree pretty much
linearly.

But the only real recursive state we care about is the trip, and in all
normal situations the "trip this dive is in" is the same thing as "what
was the last trip directory we traversed", so a linear walk works fine.

The one exception is if a dive isn't in a trip at all, in which case
"last trip directory" obviously isn't what we want.

But rather than do our own tree walking by hand (and just passing the
trip information in the natural recursive manner when traversing the
tree), we hack around it by just looking at the path to the dive.

That one-liner trivial hack has now generated about 20 lines of
explanation of it.

ANYWAY.  With this, we parse the dive and trip hierarchy properly, and
instead of just printing out the data, we might as well insert the dives
and trips into the subsurface data structures.

Note: the only data we have about the dive and trip right now is what is
visible in the directory structure, since we don't look at the actual
dive file at all (not even the name of it, which contains the dive
number).  So the end result will be just a sea of empty dives and the
trips they are contained in.  The dives have a date and time, and the
trip has a date, though.

So this is *not* useful for actually saving and loading data, but the
data we do load is easily visualized inside subsurface, so as I'm
starting to add real dive data parsing code, it will all be much more
visually satisfying.

Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
---
 load-git.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

diff --git a/load-git.c b/load-git.c
index 9a1b4708de97..60159381f5c6 100644
--- a/load-git.c
+++ b/load-git.c
@@ -22,16 +22,14 @@ static dive_trip_t *active_trip;
 
 static struct dive *create_new_dive(timestamp_t when)
 {
-	struct tm tm;
 	struct dive *dive = alloc_dive();
 
 	/* We'll fill in more data from the dive file */
 	dive->when = when;
 
-	utc_mkdate(when, &tm);
-	report_error("New dive: %04u-%02u-%02u %02u:%02u:%02u",
-		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
-		tm.tm_hour, tm.tm_min, tm.tm_sec);
+	if (active_trip)
+		add_dive_to_trip(dive, active_trip);
+	record_dive(dive);
 
 	return dive;
 }
@@ -47,9 +45,6 @@ static dive_trip_t *create_new_trip(int yyyy, int mm, int dd)
 	tm.tm_mday = dd;
 	trip->when = utc_mktime(&tm);
 
-	report_error("New trip: %04u-%02u-%02u",
-		tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
-
 	return trip;
 }
 
@@ -112,6 +107,29 @@ static int dive_directory(const char *root, const char *name, int timeoff)
 		return GIT_WALK_SKIP;
 
 	/*
+	 * Using the "git_tree_walk()" interface is simple, but
+	 * it kind of sucks as an interface because there is
+	 * no sane way to pass the hierarchy to the callbacks.
+	 * The "payload" is a fixed one-time thing: we'd like
+	 * the "current trip" to be passed down to the dives
+	 * that get parsed under that trip, but we can't.
+	 *
+	 * So "active_trip" is not the trip that is in the hierarchy
+	 * _above_ us, it's just the trip that was _before_ us. But
+	 * if a dive is not in a trip at all, we can't tell.
+	 *
+	 * We could just do a better walker that passes the
+	 * return value around, but we hack around this by
+	 * instead looking at the one hierarchical piece of
+	 * data we have: the pathname to the current entry.
+	 *
+	 * This is pretty hacky. The magic '8' is the length
+	 * of a pathname of the form 'yyyy/mm/'.
+	 */
+	if (strlen(root) == 8)
+		active_trip = NULL;
+
+	/*
 	 * Get the date. The day of the month is in the dive directory
 	 * name, the year and month might be in the path leading up
 	 * to it.
-- 
1.8.5.3



More information about the subsurface mailing list