summaryrefslogtreecommitdiffstats
path: root/load-git.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2014-03-08 08:35:23 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-03-09 19:36:32 -0700
commitf0985644b618a65fcf876c8ea856746b3c1dbaac (patch)
tree2c328ad882f14deaccd810f3682c376c73a24bb1 /load-git.c
parent5ec0dbbce831c53550e3d58a0f1b39d14dd8097f (diff)
downloadsubsurface-f0985644b618a65fcf876c8ea856746b3c1dbaac.tar.gz
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@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'load-git.c')
-rw-r--r--load-git.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/load-git.c b/load-git.c
index 9a1b4708d..60159381f 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.