diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-03-11 14:48:03 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-03-11 17:48:43 -0700 |
commit | b1fa82804ae42fff9a14dd4a0a0db32af8ba28f8 (patch) | |
tree | 52d1c76b579c04e94e0ed1da7db051edbf291b41 | |
parent | 9cc942376e3b9b709de9bb9c58f9ae63ab1502e0 (diff) | |
download | subsurface-b1fa82804ae42fff9a14dd4a0a0db32af8ba28f8.tar.gz |
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@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | load-git.c | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/load-git.c b/load-git.c index 09e07ded8..15c48027b 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; } |