summaryrefslogtreecommitdiffstats
path: root/save-git.c
diff options
context:
space:
mode:
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)