From: Linus Torvalds <torva...@linux-foundation.org>
Date: Sun, 29 Jun 2014 10:30:01 -0700
Subject: [PATCH 1/2] 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 <torva...@linux-foundation.org>
---

I think we migth want to think more about the actual save format, but this 
encodes the time offset within the dive in the name of the picture data.  
That seems reasonable.

NOTE! I've not really used the subsurface picture stuff, so somebody who 
does and has used the git format should test this. It works for me, and 
the filenames look reasonable: it ends up doing things like this in my 
stupid tests:

 git show --stat:

  ...
    dive 525: Mala Pier, Maui (Maui, Hawaii)
    
    Suunto Vyper Air, Suunto HelO2, Uemis Zurich
    Created by subsurface 4.1-490-g238c905b1686

 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:00:32 | 1 +
 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:01:01 | 1 +
 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:01:09 | 1 +
 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:01:16 | 1 +
 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:01:20 | 1 +
 2014/06/14-Maui/20-Fri-16:11:52/Pictures/+00:01:26 | 1 +
  ...

ie the picture files are all just one line long (it's just the "filename" 
line, since I don't have gps data on my pictures underwater), and they get 
saved as "Pictures/[offset]" in the dive directory.

So it all seems sane, but I think having somebody else use it and test it 
is a good idea.


 save-git.c | 76 +++++++++++++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 56 insertions(+), 20 deletions(-)

diff --git a/save-git.c b/save-git.c
index af682820dbbf..f7a244a2a0fd 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;
-- 
2.0.0.154.g79f30a3

_______________________________________________
subsurface mailing list
subsurface@hohndel.org
http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to