summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 07:12:19 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-06-21 10:47:00 -0700
commit97386a6f3d1667f293ab621fd8ae8a3ec2bf2ef2 (patch)
treecbb2a09ce757cc4444efd9ab46fea6f2df26cb37 /save-git.c
parent200572398920e418e548080ac1b4617a11f48270 (diff)
downloadsubsurface-97386a6f3d1667f293ab621fd8ae8a3ec2bf2ef2.tar.gz
Git storage: store pictures in the repository
In order to be able to see pictures when using cloud storage from different machines, we really need to store the pictures with the dive data. This could be made optional with a preference, but for now I'll just enable it by default. Loading the pictures from git still needs to be implemented. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'save-git.c')
-rw-r--r--save-git.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/save-git.c b/save-git.c
index f674b9d84..b7e519463 100644
--- a/save-git.c
+++ b/save-git.c
@@ -16,6 +16,7 @@
#include "membuffer.h"
#include "git-access.h"
#include "version.h"
+#include "qthelperfromc.h"
/*
* handle libgit2 revision 0.20 and earlier
@@ -556,6 +557,18 @@ static void create_dive_name(struct dive *dive, struct membuffer *name, struct t
tm.tm_hour, tm.tm_min, tm.tm_sec);
}
+/* Write file at filepath to the git repo with given filename */
+static int blob_insert_fromdisk(git_repository *repo, struct dir *tree, const char *filepath, const char *filename)
+{
+ int ret;
+ git_oid blob_id;
+
+ ret = git_blob_create_fromdisk(&blob_id, repo, filepath);
+ if (ret)
+ return ret;
+ return tree_insert(tree->files, filename, 1, &blob_id, GIT_FILEMODE_BLOB);
+}
+
/*
* Write a membuffer to the git repo, and free it
*/
@@ -594,6 +607,7 @@ static int save_one_picture(git_repository *repo, struct dir *dir, struct pictur
struct membuffer buf = { 0 };
char sign = '+';
unsigned h;
+ int error;
show_utf8(&buf, "filename ", pic->filename, "\n");
show_gps(&buf, pic->latitude, pic->longitude);
@@ -608,8 +622,16 @@ static int save_one_picture(git_repository *repo, struct dir *dir, struct pictur
/* 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",
+ error = blob_insert(repo, dir, &buf, "%c%02u=%02u=%02u",
sign, h, FRACTION(offset, 60));
+ if (!error) {
+ /* next store the actual picture; we prefix all picture names
+ * with "PIC-" to make things easier on the parsing side */
+ struct membuffer namebuf = { 0 };
+ put_format(&namebuf, "PIC-%s", hashstring(pic->filename));
+ error = blob_insert_fromdisk(repo, dir, pic->filename, mb_cstring(&namebuf));
+ }
+ return error;
}
static int save_pictures(git_repository *repo, struct dir *dir, struct dive *dive)