mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Initial implementation of git save format
This saves the dive data into a git object repository instead of a single XML file. We create a git object tree with each dive as a separate file, hierarchically by trip and date. NOTE 1: This largely duplicates the XML saving code, because trying to share it seemed just too painful: the logic is very similar, but the details of the actual strings end up differing sufficiently that there are tons of trivial differences. The git save format is line-based with minimal quoting, while XML quotes everything with either "<..\>" or using single quotes around attributes. NOTE 2: You currently need a dummy "file" to save to, which points to the real save location: the git repository and branch to be used. We should make this a config thing, but for testing, do something like this: echo git /home/torvalds/scuba:linus > git-test to create that git information file, and when you use "Save To" and specify "git-test" as the file to save to, subsurface will use the new git save logic to save to the branch "linus" in the repository found at "/home/torvalds/scuba". NOTE 3: The git save format uses just the git object directory, it does *not* check out the result in any git working tree or index. So after you do a save, you can do git log -p linus to see what actually happened in that branch, but it will not affect any actual checked-out state in the repository. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
c64227efe0
commit
689fe36030
6 changed files with 744 additions and 29 deletions
54
save-xml.c
54
save-xml.c
|
@ -5,6 +5,7 @@
|
|||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "device.h"
|
||||
|
@ -210,18 +211,6 @@ static void save_overview(struct membuffer *b, struct dive *dive)
|
|||
show_utf8(b, dive->suit, " <suit>", "</suit>\n", 0);
|
||||
}
|
||||
|
||||
static int nr_cylinders(struct dive *dive)
|
||||
{
|
||||
int nr;
|
||||
|
||||
for (nr = MAX_CYLINDERS; nr; --nr) {
|
||||
cylinder_t *cylinder = dive->cylinder + nr - 1;
|
||||
if (!cylinder_nodata(cylinder))
|
||||
break;
|
||||
}
|
||||
return nr;
|
||||
}
|
||||
|
||||
static void save_cylinder_info(struct membuffer *b, struct dive *dive)
|
||||
{
|
||||
int i, nr;
|
||||
|
@ -251,18 +240,6 @@ static void save_cylinder_info(struct membuffer *b, struct dive *dive)
|
|||
}
|
||||
}
|
||||
|
||||
static int nr_weightsystems(struct dive *dive)
|
||||
{
|
||||
int nr;
|
||||
|
||||
for (nr = MAX_WEIGHTSYSTEMS; nr; --nr) {
|
||||
weightsystem_t *ws = dive->weightsystem + nr - 1;
|
||||
if (!weightsystem_none(ws))
|
||||
break;
|
||||
}
|
||||
return nr;
|
||||
}
|
||||
|
||||
static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
|
||||
{
|
||||
int i, nr;
|
||||
|
@ -609,15 +586,12 @@ static void save_backup(const char *name, const char *ext, const char *new_ext)
|
|||
free(newname);
|
||||
}
|
||||
|
||||
void save_dives_logic(const char *filename, const bool select_only)
|
||||
static void try_to_backup(const char *filename)
|
||||
{
|
||||
struct membuffer buf = { 0 };
|
||||
FILE *f;
|
||||
char extension[][5] = { "xml", "ssrf", "" };
|
||||
int i = 0;
|
||||
int flen = strlen(filename);
|
||||
|
||||
save_dives_buffer(&buf, select_only);
|
||||
/* Maybe we might want to make this configurable? */
|
||||
while (extension[i][0] != '\0') {
|
||||
int elen = strlen(extension[i]);
|
||||
|
@ -627,6 +601,30 @@ void save_dives_logic(const char *filename, const bool select_only)
|
|||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void save_dives_logic(const char *filename, const bool select_only)
|
||||
{
|
||||
struct membuffer buf = { 0 };
|
||||
FILE *f;
|
||||
int fd;
|
||||
|
||||
/*
|
||||
* See if the file already exists, and if so,
|
||||
* perhaps it's a git save-file pointer?
|
||||
*
|
||||
* Otherwise, try to back it up.
|
||||
*/
|
||||
fd = subsurface_open(filename, O_RDONLY, 0);
|
||||
if (fd >= 0) {
|
||||
if (git_save_dives(fd, select_only))
|
||||
return;
|
||||
close(fd);
|
||||
try_to_backup(filename);
|
||||
}
|
||||
|
||||
save_dives_buffer(&buf, select_only);
|
||||
|
||||
f = subsurface_fopen(filename, "w");
|
||||
if (f) {
|
||||
flush_buffer(&buf, f);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue