diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-06-29 10:30:01 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-06-29 17:17:57 -0700 |
commit | 5b311abfb51046585ffba9d865b2f759fd8983d0 (patch) | |
tree | f9681e397ce2e4f64edafc32d44d45229af966ab /save-git.c | |
parent | 537beb319be5eff3f522766afa3f31404e692288 (diff) | |
download | subsurface-5b311abfb51046585ffba9d865b2f759fd8983d0.tar.gz |
git-format: save dive picture data
This doesn't actually parse the data at load time yet, but I need a save
file to do that..
The diff looks larger than it is because this moves the "mktree()"
function up earlier to be used by the picture saving code.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r-- | save-git.c | 76 |
1 files changed, 56 insertions, 20 deletions
diff --git a/save-git.c b/save-git.c index af682820d..f7a244a2a 100644 --- a/save-git.c +++ b/save-git.c @@ -439,6 +439,26 @@ static struct dir *new_directory(struct dir *parent, struct membuffer *namebuf) return subdir; } +static struct dir *mktree(struct dir *dir, const char *fmt, ...) +{ + struct membuffer buf = { 0 }; + struct dir *subdir; + + VA_BUF(&buf, fmt); + for (subdir = dir->subdirs; subdir; subdir = subdir->sibling) { + if (subdir->unique) + continue; + if (strncmp(subdir->name, buf.buffer, buf.len)) + continue; + if (!subdir->name[buf.len]) + break; + } + if (!subdir) + subdir = new_directory(dir, &buf); + free_buffer(&buf); + return subdir; +} + /* * The name of a dive is the date and the dive number (and possibly * the uniqueness suffix). @@ -499,6 +519,40 @@ static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct return ret; } +static int save_one_picture(git_repository *repo, struct dir *dir, struct picture *pic) +{ + int offset = pic->offset.seconds; + struct membuffer buf = { 0 }; + char sign = '+'; + unsigned h; + + show_utf8(&buf, "filename ", pic->filename, "\n"); + show_gps(&buf, pic->latitude, pic->longitude); + + /* Picture loading will load even negative offsets.. */ + if (offset < 0) { + offset = -offset; + sign = '-'; + } + + /* Use full hh:mm:ss format to make it all sort nicely */ + h = offset / 3600; + offset -= h *3600; + return blob_insert(repo, dir, &buf, "%c%02u:%02u:%02u", + sign, h, FRACTION(offset, 60)); +} + +static int save_pictures(git_repository *repo, struct dir *dir, struct dive *dive) +{ + if (dive->picture_list) { + dir = mktree(dir, "Pictures"); + FOR_EACH_PICTURE(dive) { + save_one_picture(repo, dir, picture); + } + } + return 0; +} + static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *dive, struct tm *tm) { struct divecomputer *dc; @@ -531,6 +585,8 @@ static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *di dc = dc->next; } while (dc); + /* Save the picture data, if any */ + save_pictures(repo, subdir, dive); return 0; } @@ -662,26 +718,6 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip_t *tr return 0; } -static struct dir *mktree(struct dir *dir, const char *fmt, ...) -{ - struct membuffer buf = { 0 }; - struct dir *subdir; - - VA_BUF(&buf, fmt); - for (subdir = dir->subdirs; subdir; subdir = subdir->sibling) { - if (subdir->unique) - continue; - if (strncmp(subdir->name, buf.buffer, buf.len)) - continue; - if (!subdir->name[buf.len]) - break; - } - if (!subdir) - subdir = new_directory(dir, &buf); - free_buffer(&buf); - return subdir; -} - static void save_userid(void *_b) { struct membuffer *b = _b; |