mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
2005723989
commit
97386a6f3d
1 changed files with 23 additions and 1 deletions
24
save-git.c
24
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)
|
||||
|
|
Loading…
Add table
Reference in a new issue