2017-04-27 18:18:03 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-03-11 20:08:31 +00:00
|
|
|
#ifdef __clang__
|
2016-03-09 18:19:06 +00:00
|
|
|
// Clang has a bug on zero-initialization of C structs.
|
|
|
|
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
|
2017-03-11 20:08:31 +00:00
|
|
|
#endif
|
2016-03-09 18:19:06 +00:00
|
|
|
|
2018-05-22 07:07:42 +00:00
|
|
|
#include "ssrf.h"
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <git2.h>
|
2024-02-27 21:58:11 +00:00
|
|
|
#include <memory>
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2020-05-01 11:43:52 +00:00
|
|
|
#include "dive.h"
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
#include "divelog.h"
|
2019-03-04 22:20:29 +00:00
|
|
|
#include "divesite.h"
|
2020-06-18 20:30:01 +00:00
|
|
|
#include "filterconstraint.h"
|
|
|
|
#include "filterpreset.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "sample.h"
|
2018-05-11 15:25:41 +00:00
|
|
|
#include "subsurface-string.h"
|
2019-05-31 14:09:14 +00:00
|
|
|
#include "trip.h"
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
#include "device.h"
|
2019-08-05 17:41:15 +00:00
|
|
|
#include "errorhelper.h"
|
2020-10-25 08:14:16 +00:00
|
|
|
#include "event.h"
|
2020-10-25 12:28:55 +00:00
|
|
|
#include "extradata.h"
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
#include "membuffer.h"
|
2015-06-13 15:01:06 +00:00
|
|
|
#include "git-access.h"
|
2015-02-15 18:25:18 +00:00
|
|
|
#include "version.h"
|
2020-04-10 07:42:14 +00:00
|
|
|
#include "picture.h"
|
2018-02-24 22:28:13 +00:00
|
|
|
#include "qthelper.h"
|
2017-06-18 06:50:22 +00:00
|
|
|
#include "gettext.h"
|
2019-05-30 16:29:36 +00:00
|
|
|
#include "tag.h"
|
2020-05-01 12:07:59 +00:00
|
|
|
#include "subsurface-time.h"
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
#define VA_BUF(b, fmt) do { va_list args; va_start(args, fmt); put_vformat(b, fmt, args); va_end(args); } while (0)
|
|
|
|
|
|
|
|
static void cond_put_format(int cond, struct membuffer *b, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
if (cond) {
|
|
|
|
VA_BUF(b, fmt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SAVE(str, x) cond_put_format(dive->x, b, str " %d\n", dive->x)
|
|
|
|
|
|
|
|
static void quote(struct membuffer *b, const char *text)
|
|
|
|
{
|
|
|
|
const char *p = text;
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const char *escape;
|
|
|
|
|
|
|
|
switch (*p++) {
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
case 0:
|
|
|
|
escape = NULL;
|
|
|
|
break;
|
|
|
|
case 1 ... 8:
|
|
|
|
case 11:
|
|
|
|
case 12:
|
|
|
|
case 14 ... 31:
|
|
|
|
escape = "?";
|
|
|
|
break;
|
2014-03-07 17:33:13 +00:00
|
|
|
case '\\':
|
|
|
|
escape = "\\\\";
|
|
|
|
break;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
case '"':
|
|
|
|
escape = "\\\"";
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
escape = "\n\t";
|
|
|
|
if (*p == '\n')
|
|
|
|
escape = "\n";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
put_bytes(b, text, (p - text - 1));
|
|
|
|
if (!escape)
|
|
|
|
break;
|
|
|
|
put_string(b, escape);
|
|
|
|
text = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void show_utf8(struct membuffer *b, const char *prefix, const char *value, const char *postfix)
|
|
|
|
{
|
|
|
|
if (value) {
|
|
|
|
put_format(b, "%s\"", prefix);
|
|
|
|
quote(b, value);
|
|
|
|
put_format(b, "\"%s", postfix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_overview(struct membuffer *b, struct dive *dive)
|
|
|
|
{
|
2022-02-12 13:03:18 +00:00
|
|
|
show_utf8(b, "divemaster ", dive->diveguide, "\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
show_utf8(b, "buddy ", dive->buddy, "\n");
|
|
|
|
show_utf8(b, "suit ", dive->suit, "\n");
|
|
|
|
show_utf8(b, "notes ", dive->notes, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_tags(struct membuffer *b, struct tag_entry *tags)
|
|
|
|
{
|
|
|
|
const char *sep = " ";
|
|
|
|
|
|
|
|
if (!tags)
|
|
|
|
return;
|
|
|
|
put_string(b, "tags");
|
|
|
|
while (tags) {
|
2024-03-26 20:06:13 +00:00
|
|
|
show_utf8(b, sep, tags->tag->source.empty() ? tags->tag->name.c_str() : tags->tag->source.c_str(), "");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
sep = ", ";
|
|
|
|
tags = tags->next;
|
|
|
|
}
|
|
|
|
put_string(b, "\n");
|
|
|
|
}
|
|
|
|
|
2014-11-06 19:23:34 +00:00
|
|
|
static void save_extra_data(struct membuffer *b, struct extra_data *ed)
|
|
|
|
{
|
|
|
|
while (ed) {
|
|
|
|
if (ed->key && ed->value)
|
|
|
|
put_format(b, "keyvalue \"%s\" \"%s\"\n", ed->key ? : "", ed->value ? : "");
|
|
|
|
ed = ed->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-16 17:10:10 +00:00
|
|
|
static void put_gasmix(struct membuffer *b, struct gasmix mix)
|
2014-08-17 18:26:21 +00:00
|
|
|
{
|
2018-08-16 17:10:10 +00:00
|
|
|
int o2 = mix.o2.permille;
|
|
|
|
int he = mix.he.permille;
|
2014-08-17 18:26:21 +00:00
|
|
|
|
|
|
|
if (o2) {
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " o2=%u.%u%%", FRACTION_TUPLE(o2, 10));
|
2014-08-17 18:26:21 +00:00
|
|
|
if (he)
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " he=%u.%u%%", FRACTION_TUPLE(he, 10));
|
2014-08-17 18:26:21 +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>
2014-03-06 21:28:39 +00:00
|
|
|
static void save_cylinder_info(struct membuffer *b, struct dive *dive)
|
|
|
|
{
|
|
|
|
int i, nr;
|
|
|
|
|
|
|
|
nr = nr_cylinders(dive);
|
|
|
|
for (i = 0; i < nr; i++) {
|
2019-08-04 20:13:49 +00:00
|
|
|
cylinder_t *cylinder = get_cylinder(dive, i);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
int volume = cylinder->type.size.mliter;
|
|
|
|
const char *description = cylinder->type.description;
|
2019-07-14 17:40:04 +00:00
|
|
|
int use = cylinder->cylinder_use;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
put_string(b, "cylinder");
|
|
|
|
if (volume)
|
|
|
|
put_milli(b, " vol=", volume, "l");
|
|
|
|
put_pressure(b, cylinder->type.workingpressure, " workpressure=", "bar");
|
|
|
|
show_utf8(b, " description=", description, "");
|
|
|
|
strip_mb(b);
|
2018-08-16 17:10:10 +00:00
|
|
|
put_gasmix(b, cylinder->gasmix);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
put_pressure(b, cylinder->start, " start=", "bar");
|
|
|
|
put_pressure(b, cylinder->end, " end=", "bar");
|
2019-07-14 17:40:04 +00:00
|
|
|
if (use > OC_GAS && use < NUM_GAS_USE)
|
|
|
|
show_utf8(b, " use=", cylinderuse_text[use], "");
|
2017-11-27 17:20:21 +00:00
|
|
|
if (cylinder->depth.mm != 0)
|
2017-12-20 13:15:56 +00:00
|
|
|
put_milli(b, " depth=", cylinder->depth.mm, "m");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
put_string(b, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_weightsystem_info(struct membuffer *b, struct dive *dive)
|
|
|
|
{
|
|
|
|
int i, nr;
|
|
|
|
|
|
|
|
nr = nr_weightsystems(dive);
|
|
|
|
for (i = 0; i < nr; i++) {
|
2019-06-26 15:21:03 +00:00
|
|
|
weightsystem_t ws = dive->weightsystems.weightsystems[i];
|
|
|
|
int grams = ws.weight.grams;
|
|
|
|
const char *description = ws.description;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
put_string(b, "weightsystem");
|
|
|
|
put_milli(b, " weight=", grams, "kg");
|
|
|
|
show_utf8(b, " description=", description, "");
|
|
|
|
put_string(b, "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_dive_temperature(struct membuffer *b, struct dive *dive)
|
|
|
|
{
|
|
|
|
if (dive->airtemp.mkelvin != dc_airtemp(&dive->dc))
|
2014-03-07 17:33:13 +00:00
|
|
|
put_temperature(b, dive->airtemp, "airtemp ", "°C\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (dive->watertemp.mkelvin != dc_watertemp(&dive->dc))
|
2014-03-07 17:33:13 +00:00
|
|
|
put_temperature(b, dive->watertemp, "watertemp ", "°C\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void save_depths(struct membuffer *b, struct divecomputer *dc)
|
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
put_depth(b, dc->maxdepth, "maxdepth ", "m\n");
|
|
|
|
put_depth(b, dc->meandepth, "meandepth ", "m\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void save_temperatures(struct membuffer *b, struct divecomputer *dc)
|
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
put_temperature(b, dc->airtemp, "airtemp ", "°C\n");
|
|
|
|
put_temperature(b, dc->watertemp, "watertemp ", "°C\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void save_airpressure(struct membuffer *b, struct divecomputer *dc)
|
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
put_pressure(b, dc->surface_pressure, "surfacepressure ", "bar\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void save_salinity(struct membuffer *b, struct divecomputer *dc)
|
|
|
|
{
|
2023-03-27 17:35:24 +00:00
|
|
|
if (!dc->salinity)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
return;
|
2014-03-07 17:33:13 +00:00
|
|
|
put_salinity(b, dc->salinity, "salinity ", "g/l\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void show_date(struct membuffer *b, timestamp_t when)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
|
|
|
|
utc_mkdate(when, &tm);
|
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(b, "date %04u-%02u-%02u\n",
|
2016-04-28 22:13:30 +00:00
|
|
|
tm.tm_year, tm.tm_mon + 1, tm.tm_mday);
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(b, "time %02u:%02u:%02u\n",
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
}
|
|
|
|
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
static void show_integer(struct membuffer *b, int value, const char *pre, const char *post)
|
|
|
|
{
|
|
|
|
put_format(b, " %s%d%s", pre, value, post);
|
|
|
|
}
|
|
|
|
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
static void show_index(struct membuffer *b, int value, const char *pre, const char *post)
|
|
|
|
{
|
|
|
|
if (value)
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
show_integer(b, value, pre, post);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Samples are saved as densely as possible while still being readable,
|
|
|
|
* since they are the bulk of the data.
|
|
|
|
*
|
|
|
|
* For parsing, look at the units to figure out what the numbers are.
|
|
|
|
*/
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
static void save_sample(struct membuffer *b, struct sample *sample, struct sample *old, int o2sensor)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
int idx;
|
|
|
|
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, "%3u:%02u", FRACTION_TUPLE(sample->time.seconds, 60));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
put_milli(b, " ", sample->depth.mm, "m");
|
|
|
|
put_temperature(b, sample->temperature, " ", "°C");
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
|
|
|
|
for (idx = 0; idx < MAX_SENSORS; idx++) {
|
|
|
|
pressure_t p = sample->pressure[idx];
|
|
|
|
int sensor = sample->sensor[idx];
|
|
|
|
|
2021-09-13 18:57:56 +00:00
|
|
|
if (sensor == NO_SENSOR)
|
|
|
|
continue;
|
|
|
|
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
if (!p.mbar)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Old-style "o2sensor" syntax for CCR dives? */
|
|
|
|
if (o2sensor >= 0) {
|
|
|
|
if (sensor == o2sensor) {
|
|
|
|
put_pressure(b, sample->pressure[1]," o2pressure=","bar");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
put_pressure(b, p, " ", "bar");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: regardless of which index we used for the non-O2
|
|
|
|
* sensor, we know there is only one non-O2 sensor in legacy
|
|
|
|
* mode, and "old->sensor[0]" contains that index.
|
|
|
|
*/
|
|
|
|
if (sensor != old->sensor[0]) {
|
|
|
|
put_format(b, " sensor=%d", sensor);
|
|
|
|
old->sensor[0] = sensor;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The new-style format is much simpler: the sensor is always encoded */
|
|
|
|
put_pressure(b, p, " ", "bar");
|
|
|
|
put_format(b, ":%d", sensor);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* the deco/ndl values are stored whenever they change */
|
|
|
|
if (sample->ndl.seconds != old->ndl.seconds) {
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " ndl=%u:%02u", FRACTION_TUPLE(sample->ndl.seconds, 60));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
old->ndl = sample->ndl;
|
|
|
|
}
|
2014-07-09 20:13:36 +00:00
|
|
|
if (sample->tts.seconds != old->tts.seconds) {
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " tts=%u:%02u", FRACTION_TUPLE(sample->tts.seconds, 60));
|
2014-07-09 20:13:36 +00:00
|
|
|
old->tts = sample->tts;
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (sample->in_deco != old->in_deco) {
|
|
|
|
put_format(b, " in_deco=%d", sample->in_deco ? 1 : 0);
|
|
|
|
old->in_deco = sample->in_deco;
|
|
|
|
}
|
|
|
|
if (sample->stoptime.seconds != old->stoptime.seconds) {
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " stoptime=%u:%02u", FRACTION_TUPLE(sample->stoptime.seconds, 60));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
old->stoptime = sample->stoptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sample->stopdepth.mm != old->stopdepth.mm) {
|
|
|
|
put_milli(b, " stopdepth=", sample->stopdepth.mm, "m");
|
|
|
|
old->stopdepth = sample->stopdepth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sample->cns != old->cns) {
|
|
|
|
put_format(b, " cns=%u%%", sample->cns);
|
|
|
|
old->cns = sample->cns;
|
|
|
|
}
|
|
|
|
|
2017-07-21 03:56:58 +00:00
|
|
|
if (sample->rbt.seconds != old->rbt.seconds) {
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, " rbt=%u:%02u", FRACTION_TUPLE(sample->rbt.seconds, 60));
|
2017-07-21 03:56:58 +00:00
|
|
|
old->rbt.seconds = sample->rbt.seconds;
|
|
|
|
}
|
2015-07-22 15:23:20 +00:00
|
|
|
|
2014-11-22 13:13:13 +00:00
|
|
|
if (sample->o2sensor[0].mbar != old->o2sensor[0].mbar) {
|
|
|
|
put_milli(b, " sensor1=", sample->o2sensor[0].mbar, "bar");
|
|
|
|
old->o2sensor[0] = sample->o2sensor[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sample->o2sensor[1].mbar) && (sample->o2sensor[1].mbar != old->o2sensor[1].mbar)) {
|
|
|
|
put_milli(b, " sensor2=", sample->o2sensor[1].mbar, "bar");
|
|
|
|
old->o2sensor[1] = sample->o2sensor[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sample->o2sensor[2].mbar) && (sample->o2sensor[2].mbar != old->o2sensor[2].mbar)) {
|
|
|
|
put_milli(b, " sensor3=", sample->o2sensor[2].mbar, "bar");
|
|
|
|
old->o2sensor[2] = sample->o2sensor[2];
|
|
|
|
}
|
|
|
|
|
2024-01-20 23:35:44 +00:00
|
|
|
if ((sample->o2sensor[3].mbar) && (sample->o2sensor[3].mbar != old->o2sensor[3].mbar)) {
|
|
|
|
put_milli(b, " sensor4=", sample->o2sensor[3].mbar, "bar");
|
|
|
|
old->o2sensor[3] = sample->o2sensor[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sample->o2sensor[4].mbar) && (sample->o2sensor[4].mbar != old->o2sensor[4].mbar)) {
|
|
|
|
put_milli(b, " sensor5=", sample->o2sensor[4].mbar, "bar");
|
|
|
|
old->o2sensor[4] = sample->o2sensor[4];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sample->o2sensor[5].mbar) && (sample->o2sensor[5].mbar != old->o2sensor[5].mbar)) {
|
|
|
|
put_milli(b, " sensor6=", sample->o2sensor[5].mbar, "bar");
|
|
|
|
old->o2sensor[5] = sample->o2sensor[5];
|
|
|
|
}
|
|
|
|
|
2014-10-19 14:07:07 +00:00
|
|
|
if (sample->setpoint.mbar != old->setpoint.mbar) {
|
|
|
|
put_milli(b, " po2=", sample->setpoint.mbar, "bar");
|
|
|
|
old->setpoint = sample->setpoint;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
2017-07-21 03:56:58 +00:00
|
|
|
if (sample->heartbeat != old->heartbeat) {
|
|
|
|
show_index(b, sample->heartbeat, "heartbeat=", "");
|
|
|
|
old->heartbeat = sample->heartbeat;
|
|
|
|
}
|
|
|
|
if (sample->bearing.degrees != old->bearing.degrees) {
|
|
|
|
show_index(b, sample->bearing.degrees, "bearing=", "°");
|
|
|
|
old->bearing.degrees = sample->bearing.degrees;
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
put_format(b, "\n");
|
|
|
|
}
|
|
|
|
|
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 20:37:34 +00:00
|
|
|
static void save_samples(struct membuffer *b, struct dive *dive, struct divecomputer *dc)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 20:37:34 +00:00
|
|
|
int nr;
|
2017-08-26 19:14:46 +00:00
|
|
|
int o2sensor;
|
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 20:37:34 +00:00
|
|
|
struct sample *s;
|
2024-02-27 17:40:45 +00:00
|
|
|
struct sample dummy;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
/* Is this a CCR dive with the old-style "o2pressure" sensor? */
|
|
|
|
o2sensor = legacy_format_o2pressures(dive, dc);
|
|
|
|
if (o2sensor >= 0) {
|
|
|
|
dummy.sensor[0] = !o2sensor;
|
|
|
|
dummy.sensor[1] = o2sensor;
|
|
|
|
}
|
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 20:37:34 +00:00
|
|
|
|
|
|
|
s = dc->sample;
|
|
|
|
nr = dc->samples;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
while (--nr >= 0) {
|
Add support for loading and saving multiple pressure samples
This does both the XML and the git save format, because the changes
really are the same, even if the actual format differs in some details.
See how the two "save_samples()" routines both do the same basic setup,
for example.
This is fairly straightforward, with the possible exception of the odd
sensor = sample->sensor[0];
default in the git pressure loading code.
That line just means that if we do *not* have an explicit cylinder index
for the pressure reading, we will always end up filling in the new
pressure as the first pressure (because the cylinder index will match the
first sensor slot).
So that makes the "add_sample_pressure()" case always do the same thing it
used to do for the legacy case: fill in the first slot. The actual sensor
index may later change, since the legacy format has a "sensor=X" key value
pair that sets the sensor, but it will also use the first sensor slot,
making it all do exactly what it used to do.
And on the other hand, if we're loading new-style data with cylinder
pressure and sensor index together, we just end up using the new semantics
for add_sample_pressure(), which tries to keep the same slot for the same
sensor, but does the right thing if we already have other pressure values.
The XML code has no such issues at all, since it can't share the cases
anyway, and we need to have different node names for the different sensor
values and cannot just have multiple "pressure" entries. Have I mentioned
how much I despise XML lately?
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-26 02:10:03 +00:00
|
|
|
save_sample(b, s, &dummy, o2sensor);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
static void save_one_event(struct membuffer *b, struct dive *dive, struct event *ev)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, "event %d:%02d", FRACTION_TUPLE(ev->time.seconds, 60));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
show_index(b, ev->type, "type=", "");
|
|
|
|
show_index(b, ev->flags, "flags=", "");
|
2018-04-07 12:56:37 +00:00
|
|
|
|
|
|
|
if (!strcmp(ev->name,"modechange"))
|
2018-05-16 06:56:11 +00:00
|
|
|
show_utf8(b, " divemode=", divemode_text[ev->value], "");
|
2018-04-07 12:56:37 +00:00
|
|
|
else
|
|
|
|
show_index(b, ev->value, "value=", "");
|
2014-03-09 22:26:50 +00:00
|
|
|
show_utf8(b, " name=", ev->name, "");
|
2014-08-17 18:26:21 +00:00
|
|
|
if (event_is_gaschange(ev)) {
|
2018-08-16 11:35:14 +00:00
|
|
|
struct gasmix mix = get_gasmix_from_event(dive, ev);
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
if (ev->gas.index >= 0)
|
|
|
|
show_integer(b, ev->gas.index, "cylinder=", "");
|
2018-08-16 17:10:10 +00:00
|
|
|
put_gasmix(b, mix);
|
2014-08-17 18:26:21 +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>
2014-03-06 21:28:39 +00:00
|
|
|
put_string(b, "\n");
|
|
|
|
}
|
|
|
|
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
static void save_events(struct membuffer *b, struct dive *dive, struct event *ev)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
while (ev) {
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
save_one_event(b, dive, ev);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
ev = ev->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer *dc)
|
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
show_utf8(b, "model ", dc->model, "\n");
|
Improve profile display in planner
This patch allows the planner to save the last manually-entered
dive planner point of a dive plan. When the plan has been saved
and re-opened for edit, the time of the last-entered dive planner
point is used to ensure that dive planning continues from the same
point in the profile as was when the original dive plan was saved.
Mechanism:
1) In dive.h, create a new dc attribute dc->last_manual_time
with data type of duration_t.
2) In diveplanner.c, ensure that the last manually-entered
dive planner point is saved in dc->last_manual_time.
3) In save-xml.c, create a new XML attribute for the <divecomputer>
element, named last-manual-time. For dive plans, the element would
now look like:
<divecomputer model='planned dive' last-manual-time='31:17 min'>
4) In parse-xml.c, insert code that recognises the last-manual-time
XML attribute, reads the time value and assigns this time to
dc->last_manual_time.
5) In diveplannermodel.cpp, method DiveplannerPointModel::loadfromdive,
insert code that sets the appropriate boolean value to dp->entered
by comparing newtime (i.e. time of dp) with dc->last_manual_time.
6) Diveplannermodel.cpp also accepts profile data from normal dives in
the dive log, whether hand-entered or loaded from dive computer. It
looks like the reduction of dive points for dives with >100 points
continues to work ok.
The result is that when a dive plan is saved with manually entered
points up to e.g. 10 minutes into the dive, it can be re-opened for edit
in the dive planner and the planner re-creates the plan with manually
entered points up to 10 minutes. The rest of the points are "soft"
points, shaped by the deco calculations of the planner.
Improvements: Improve code for profile display in dive planner
This responds to #1052.
Change load-git.c and save-git.c so that the last-manual-time is
also saved in the git-format dive log.
Several stylistic changes in text for consistent C source code.
Improvement of dive planner profile display:
Do some simplification of my alterations to diveplannermodel.cpp
Two small style changes in planner.c and diveplannermodel.cpp
as requested ny @neolit123
Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-15 12:51:47 +00:00
|
|
|
if (dc->last_manual_time.seconds)
|
|
|
|
put_duration(b, dc->last_manual_time, "lastmanualtime ", "min\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (dc->deviceid)
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(b, "deviceid %08x\n", dc->deviceid);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (dc->diveid)
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(b, "diveid %08x\n", dc->diveid);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (dc->when && dc->when != dive->when)
|
|
|
|
show_date(b, dc->when);
|
|
|
|
if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds)
|
2014-03-07 17:33:13 +00:00
|
|
|
put_duration(b, dc->duration, "duration ", "min\n");
|
2015-01-10 23:01:15 +00:00
|
|
|
if (dc->divemode != OC) {
|
|
|
|
put_format(b, "dctype %s\n", divemode_text[dc->divemode]);
|
2014-11-22 13:13:13 +00:00
|
|
|
put_format(b, "numberofoxygensensors %d\n",dc->no_o2sensors);
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
save_depths(b, dc);
|
|
|
|
save_temperatures(b, dc);
|
|
|
|
save_airpressure(b, dc);
|
|
|
|
save_salinity(b, dc);
|
2014-03-07 17:33:13 +00:00
|
|
|
put_duration(b, dc->surfacetime, "surfacetime ", "min\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-11-06 19:23:34 +00:00
|
|
|
save_extra_data(b, dc->extra_data);
|
Start using the actual cylinder data for gas switch events
Now that gas switch events always have indices into the cylinder table,
start using that to look up the gas mix from the cylinders rather than
from the gas switch event itself. In other words, the cylinder index is
now the primary data for gas switch events.
This means that now as you change the cylinder information, the gas
switch events will automatically update to reflect those changes.
Note that on loading data from the outside (either from a xml file, from
a git/cloud account, or from a dive computer), we may or may not
initially have an index for the gas change event. The external data may
be from an older version of subsurface, or it may be from a
libdivecomputer download that just doesn't give index data at all.
In that case, we will do:
- if there is no index, but there is explicit gas mix information, we
will look up the index based on that gas mix, picking the cylinder
that has the closest mix.
- if there isn't even explicit gas mix data, so we only have the event
value from libdivecomputer, we will turn that value into a gasmix,
and use that to look up the cylinder index as above.
- if no valid cylinder information is available at all, gas switch
events will just be dropped.
When saving the data, we now always save the cylinder index, and the gas
mix associated with that cylinder (that gas mix will be ignored on load,
since the index is the primary, but it makes the event much easier to
read).
It is worth noting we do not modify the libdivecomputer value, even if
the gasmix has changed, so that remains as a record of the original
download.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-02 21:07:06 +00:00
|
|
|
save_events(b, dive, dc->events);
|
Fix up o2 pressure sensor handling at load time
Because of how we traditionally did things, the "o2pressure" parsing
depends on implicitly setting the sensor index to the last cylinder that
was marked as being used for oxygen.
We also always defaulted the primary sensor (which is used for the
diluent tank for CCR) to cylinder 0, but that doesn't work when the
oxygen tank is cylinder 0.
This gets that right at file loading time, and unifies the xml and git
sample parsing to make them match. The new defaults are:
- unless anything else is explicitly specified, the primary sensor is
associated with the first tank, and the secondary sensor is
associated with the second tank
- if we're a CCR dive, and have an explicit oxygen tank, we associate
the secondary sensor with that oxygen cylinder. The primary sensor
will be switched over to the second cylinder if the oxygen cylinder
is the first one.
This may sound backwards, but matches our traditional behavior where
the O2 pressure was the secondary pressure.
This is definitely not pretty, but it gets our historical files working
right, and is at least reasonably sensible.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-21 20:37:34 +00:00
|
|
|
save_samples(b, dive, dc);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we don't save the date and time or dive
|
|
|
|
* number: they are encoded in the filename.
|
|
|
|
*/
|
|
|
|
static void create_dive_buffer(struct dive *dive, struct membuffer *b)
|
|
|
|
{
|
2019-04-30 10:42:33 +00:00
|
|
|
pressure_t surface_pressure = un_fixup_surface_pressure(dive);
|
2017-09-10 07:53:45 +00:00
|
|
|
if (dive->dc.duration.seconds > 0)
|
2024-05-01 09:01:06 +00:00
|
|
|
put_format(b, "duration %u:%02u min\n", FRACTION_TUPLE(dive->dc.duration.seconds, 60));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
SAVE("rating", rating);
|
|
|
|
SAVE("visibility", visibility);
|
2019-11-29 05:08:14 +00:00
|
|
|
SAVE("wavesize", wavesize);
|
|
|
|
SAVE("current", current);
|
|
|
|
SAVE("surge", surge);
|
|
|
|
SAVE("chill", chill);
|
2019-11-19 17:16:45 +00:00
|
|
|
if (dive->user_salinity)
|
|
|
|
put_format(b, "watersalinity %d g/l\n", (int)(dive->user_salinity/10));
|
2019-04-30 10:42:33 +00:00
|
|
|
if (surface_pressure.mbar)
|
|
|
|
SAVE("airpressure", surface_pressure.mbar);
|
2018-11-18 10:15:32 +00:00
|
|
|
cond_put_format(dive->notrip, b, "notrip\n");
|
2019-12-12 21:58:53 +00:00
|
|
|
cond_put_format(dive->invalid, b, "invalid\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
save_tags(b, dive->tag_list);
|
2018-10-31 10:22:52 +00:00
|
|
|
if (dive->dive_site)
|
|
|
|
put_format(b, "divesiteid %08x\n", dive->dive_site->uuid);
|
2018-10-26 15:03:54 +00:00
|
|
|
if (verbose && dive->dive_site)
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("removed reference to non-existant dive site with uuid %08x\n", dive->dive_site->uuid);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
save_overview(b, dive);
|
|
|
|
save_cylinder_info(b, dive);
|
|
|
|
save_weightsystem_info(b, dive);
|
|
|
|
save_dive_temperature(b, dive);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* libgit2 has a "git_treebuilder" concept, but it's broken, and can not
|
|
|
|
* be used to do a flat tree (like the git "index") nor a recursive tree.
|
|
|
|
* Stupid.
|
|
|
|
*
|
|
|
|
* So we have to do that "keep track of recursive treebuilder entries"
|
|
|
|
* ourselves. We use 'git_treebuilder' for any regular files, and our own
|
|
|
|
* data structures for recursive trees.
|
|
|
|
*
|
|
|
|
* When finally writing it out, we traverse the subdirectories depth-
|
|
|
|
* first, writing them out, and then adding the written-out trees to
|
|
|
|
* the git_treebuilder they existed in.
|
|
|
|
*/
|
|
|
|
struct dir {
|
|
|
|
git_treebuilder *files;
|
2024-02-27 21:58:11 +00:00
|
|
|
std::vector<std::unique_ptr<dir>> subdirs;
|
|
|
|
bool unique;
|
|
|
|
std::string name;
|
|
|
|
|
|
|
|
dir() : files(nullptr), unique(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~dir()
|
|
|
|
{
|
|
|
|
if (files)
|
|
|
|
git_treebuilder_free(files);
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
};
|
|
|
|
|
2024-02-27 17:40:45 +00:00
|
|
|
static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, git_filemode_t mode)
|
2014-03-07 17:33:13 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2024-02-27 21:58:11 +00:00
|
|
|
membufferpp uniquename;
|
2014-03-07 17:33:13 +00:00
|
|
|
|
|
|
|
if (mkunique && git_treebuilder_get(dir, name)) {
|
|
|
|
char hex[8];
|
|
|
|
git_oid_nfmt(hex, 7, id);
|
|
|
|
hex[7] = 0;
|
|
|
|
put_format(&uniquename, "%s~%s", name, hex);
|
|
|
|
name = mb_cstring(&uniquename);
|
|
|
|
}
|
|
|
|
ret = git_treebuilder_insert(NULL, dir, name, id, mode);
|
2017-10-26 11:40:21 +00:00
|
|
|
if (ret) {
|
|
|
|
const git_error *gerr = giterr_last();
|
|
|
|
if (gerr) {
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("tree_insert failed with return %d error %s\n", ret, gerr->message);
|
2017-10-26 11:40:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-07 17:33:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
/*
|
2014-03-07 17:33:13 +00:00
|
|
|
* This does *not* make sure the new subdirectory doesn't
|
|
|
|
* alias some existing name. That is actually useful: you
|
|
|
|
* can create multiple directories with the same name, and
|
|
|
|
* set the "unique" flag, which will then append the SHA1
|
|
|
|
* of the directory to the name when it is written.
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
*/
|
2015-01-22 21:14:03 +00:00
|
|
|
static struct dir *new_directory(git_repository *repo, struct dir *parent, struct membuffer *namebuf)
|
2014-03-07 17:33:13 +00:00
|
|
|
{
|
2024-02-27 21:58:11 +00:00
|
|
|
auto subdir = std::make_unique<dir>();
|
|
|
|
subdir->name = mb_cstring(namebuf);
|
2014-03-07 17:33:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It starts out empty: no subdirectories of its own,
|
|
|
|
* and an empty treebuilder list of files.
|
|
|
|
*/
|
2015-01-22 21:14:03 +00:00
|
|
|
git_treebuilder_new(&subdir->files, repo, NULL);
|
2014-03-07 17:33:13 +00:00
|
|
|
|
2024-02-27 21:58:11 +00:00
|
|
|
/* Add it to the list of subdirs of the parent
|
|
|
|
* Note: append at front. Do we want that?
|
|
|
|
*/
|
|
|
|
parent->subdirs.insert(parent->subdirs.begin(), std::move(subdir));
|
2014-03-07 17:33:13 +00:00
|
|
|
|
2024-02-27 21:58:11 +00:00
|
|
|
return parent->subdirs.front().get();
|
2014-03-07 17:33:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 21:14:03 +00:00
|
|
|
static struct dir *mktree(git_repository *repo, struct dir *dir, const char *fmt, ...)
|
2014-06-29 17:30:01 +00:00
|
|
|
{
|
2024-02-27 21:58:11 +00:00
|
|
|
membufferpp buf;
|
2014-06-29 17:30:01 +00:00
|
|
|
|
|
|
|
VA_BUF(&buf, fmt);
|
2024-02-27 21:58:11 +00:00
|
|
|
for (auto &subdir: dir->subdirs) {
|
2014-06-29 17:30:01 +00:00
|
|
|
if (subdir->unique)
|
|
|
|
continue;
|
2024-02-27 21:58:11 +00:00
|
|
|
if (strncmp(subdir->name.c_str(), buf.buffer, buf.len))
|
2014-06-29 17:30:01 +00:00
|
|
|
continue;
|
|
|
|
if (!subdir->name[buf.len])
|
2024-02-27 21:58:11 +00:00
|
|
|
return subdir.get();
|
2014-06-29 17:30:01 +00:00
|
|
|
}
|
2024-02-27 21:58:11 +00:00
|
|
|
return new_directory(repo, dir, &buf);
|
2014-06-29 17:30:01 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
/*
|
|
|
|
* The name of a dive is the date and the dive number (and possibly
|
|
|
|
* the uniqueness suffix).
|
|
|
|
*
|
|
|
|
* Note that the time of the dive may not be the same as the
|
|
|
|
* time of the directory structure it is created in: the dive
|
|
|
|
* might be part of a trip that straddles a month (or even a
|
|
|
|
* year).
|
2014-05-12 08:01:54 +00:00
|
|
|
*
|
|
|
|
* We do *not* want to use localized weekdays and cause peoples save
|
|
|
|
* formats to depend on their locale.
|
2014-03-07 17:33:13 +00:00
|
|
|
*/
|
|
|
|
static void create_dive_name(struct dive *dive, struct membuffer *name, struct tm *dirtm)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
struct tm tm;
|
2014-05-12 08:01:54 +00:00
|
|
|
static const char weekday[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
utc_mkdate(dive->when, &tm);
|
2014-03-07 17:33:13 +00:00
|
|
|
if (tm.tm_year != dirtm->tm_year)
|
2016-04-28 22:13:30 +00:00
|
|
|
put_format(name, "%04u-", tm.tm_year);
|
2014-03-07 17:33:13 +00:00
|
|
|
if (tm.tm_mon != dirtm->tm_mon)
|
|
|
|
put_format(name, "%02u-", tm.tm_mon+1);
|
|
|
|
|
2015-06-19 18:45:24 +00:00
|
|
|
/* a colon is an illegal char in a file name on Windows - use an '=' instead */
|
|
|
|
put_format(name, "%02u-%s-%02u=%02u=%02u",
|
2014-05-12 08:01:54 +00:00
|
|
|
tm.tm_mday, weekday[tm.tm_wday],
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
}
|
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
/*
|
|
|
|
* Write a membuffer to the git repo, and free it
|
|
|
|
*/
|
|
|
|
static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer *b, const char *fmt, ...)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
int ret;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
git_oid blob_id;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp name;
|
2014-03-07 17:33:13 +00:00
|
|
|
|
|
|
|
ret = git_blob_create_frombuffer(&blob_id, repo, b->buffer, b->len);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
VA_BUF(&name, fmt);
|
2014-03-08 04:33:51 +00:00
|
|
|
ret = tree_insert(tree->files, mb_cstring(&name), 1, &blob_id, GIT_FILEMODE_BLOB);
|
2014-03-07 17:33:13 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-03-09 20:33:28 +00:00
|
|
|
static int save_one_divecomputer(git_repository *repo, struct dir *tree, struct dive *dive, struct divecomputer *dc, int idx)
|
2014-03-07 17:33:13 +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>
2014-03-06 21:28:39 +00:00
|
|
|
int ret;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp buf;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
save_dc(&buf, dive, dc);
|
2014-03-09 20:33:28 +00:00
|
|
|
ret = blob_insert(repo, tree, &buf, "Divecomputer%c%03u", idx ? '-' : 0, idx);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (ret)
|
2014-03-07 17:33:13 +00:00
|
|
|
report_error("divecomputer tree insert failed");
|
|
|
|
return ret;
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-06-29 17:30:01 +00:00
|
|
|
static int save_one_picture(git_repository *repo, struct dir *dir, struct picture *pic)
|
|
|
|
{
|
|
|
|
int offset = pic->offset.seconds;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp buf;
|
2014-06-29 17:30:01 +00:00
|
|
|
char sign = '+';
|
|
|
|
unsigned h;
|
|
|
|
|
|
|
|
show_utf8(&buf, "filename ", pic->filename, "\n");
|
2018-10-20 18:12:15 +00:00
|
|
|
put_location(&buf, &pic->location, "gps ", "\n");
|
2014-06-29 17:30:01 +00:00
|
|
|
|
|
|
|
/* 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;
|
2018-05-23 16:01:39 +00:00
|
|
|
return blob_insert(repo, dir, &buf, "%c%02u=%02u=%02u",
|
2024-05-01 09:01:06 +00:00
|
|
|
sign, h, FRACTION_TUPLE(offset, 60));
|
2014-06-29 17:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int save_pictures(git_repository *repo, struct dir *dir, struct dive *dive)
|
|
|
|
{
|
2020-04-11 15:41:56 +00:00
|
|
|
if (dive->pictures.nr > 0) {
|
2015-01-22 21:14:03 +00:00
|
|
|
dir = mktree(repo, dir, "Pictures");
|
2014-06-29 17:30:01 +00:00
|
|
|
FOR_EACH_PICTURE(dive) {
|
|
|
|
save_one_picture(repo, dir, picture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-03 22:31:59 +00:00
|
|
|
static int save_one_dive(git_repository *repo, struct dir *tree, struct dive *dive, struct tm *tm, bool cached_ok)
|
2014-03-07 17:33:13 +00:00
|
|
|
{
|
|
|
|
struct divecomputer *dc;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp buf, name;
|
2014-03-07 17:33:13 +00:00
|
|
|
struct dir *subdir;
|
|
|
|
int ret, nr;
|
|
|
|
|
|
|
|
/* Create dive directory */
|
|
|
|
create_dive_name(dive, &name, tm);
|
2016-04-03 22:31:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the dive git ID is valid, we just create the whole directory
|
|
|
|
* with that ID
|
|
|
|
*/
|
|
|
|
if (cached_ok && dive_cache_is_valid(dive)) {
|
|
|
|
git_oid oid;
|
|
|
|
git_oid_fromraw(&oid, dive->git_id);
|
|
|
|
ret = tree_insert(tree->files, mb_cstring(&name), 1,
|
|
|
|
&oid, GIT_FILEMODE_TREE);
|
|
|
|
if (ret)
|
|
|
|
return report_error("cached dive tree insert failed");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:14:03 +00:00
|
|
|
subdir = new_directory(repo, tree, &name);
|
2024-02-27 21:58:11 +00:00
|
|
|
subdir->unique = true;
|
2014-03-07 17:33:13 +00:00
|
|
|
|
|
|
|
create_dive_buffer(dive, &buf);
|
|
|
|
nr = dive->number;
|
|
|
|
ret = blob_insert(repo, subdir, &buf,
|
|
|
|
"Dive%c%d", nr ? '-' : 0, nr);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (ret)
|
2014-03-07 17:33:13 +00:00
|
|
|
return report_error("dive save-file tree insert failed");
|
|
|
|
|
2014-03-09 20:33:28 +00:00
|
|
|
/*
|
|
|
|
* Save the dive computer data. If there is only one dive
|
|
|
|
* computer, use index 0 for that (which disables the index
|
|
|
|
* generation when naming it).
|
|
|
|
*/
|
2014-03-07 17:33:13 +00:00
|
|
|
dc = &dive->dc;
|
2014-03-09 20:33:28 +00:00
|
|
|
nr = dc->next ? 1 : 0;
|
2014-03-07 17:33:13 +00:00
|
|
|
do {
|
2014-03-09 20:33:28 +00:00
|
|
|
save_one_divecomputer(repo, subdir, dive, dc, nr++);
|
2014-03-07 17:33:13 +00:00
|
|
|
dc = dc->next;
|
|
|
|
} while (dc);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-06-29 17:30:01 +00:00
|
|
|
/* Save the picture data, if any */
|
|
|
|
save_pictures(repo, subdir, dive);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-03-07 17:33:13 +00:00
|
|
|
* We'll mark the trip directories unique, so this does not
|
|
|
|
* need to be unique per se. It could be just "trip". But
|
|
|
|
* to make things a bit more user-friendly, we try to take
|
|
|
|
* the trip location into account.
|
|
|
|
*
|
|
|
|
* But no special characters, and no numbers (numbers in the
|
|
|
|
* name could be construed as a date).
|
|
|
|
*
|
|
|
|
* So we might end up with "02-Maui", and then the unique
|
|
|
|
* flag will make us write it out as "02-Maui~54b4" or
|
|
|
|
* similar.
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
*/
|
2014-03-07 17:33:13 +00:00
|
|
|
#define MAXTRIPNAME 15
|
|
|
|
static void create_trip_name(dive_trip_t *trip, struct membuffer *name, struct tm *tm)
|
|
|
|
{
|
|
|
|
put_format(name, "%02u-", tm->tm_mday);
|
|
|
|
if (trip->location) {
|
|
|
|
char ascii_loc[MAXTRIPNAME+1], *p = trip->location;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXTRIPNAME; ) {
|
|
|
|
char c = *p++;
|
|
|
|
switch (c) {
|
|
|
|
case 0:
|
|
|
|
case ',':
|
|
|
|
case '.':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'a' ... 'z':
|
|
|
|
case 'A' ... 'Z':
|
|
|
|
ascii_loc[i++] = c;
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > 1) {
|
|
|
|
put_bytes(name, ascii_loc, i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No useful name? */
|
|
|
|
put_string(name, "trip");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int save_trip_description(git_repository *repo, struct dir *dir, dive_trip_t *trip, struct tm *tm)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
int ret;
|
|
|
|
git_oid blob_id;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp desc;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(&desc, "date %04u-%02u-%02u\n",
|
2016-04-28 22:13:30 +00:00
|
|
|
tm->tm_year, tm->tm_mon + 1, tm->tm_mday);
|
2014-03-07 17:33:13 +00:00
|
|
|
put_format(&desc, "time %02u:%02u:%02u\n",
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
show_utf8(&desc, "location ", trip->location, "\n");
|
|
|
|
show_utf8(&desc, "notes ", trip->notes, "\n");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
ret = git_blob_create_frombuffer(&blob_id, repo, desc.buffer, desc.len);
|
|
|
|
if (ret)
|
|
|
|
return report_error("trip blob creation failed");
|
2014-03-08 04:33:51 +00:00
|
|
|
ret = tree_insert(dir->files, "00-Trip", 0, &blob_id, GIT_FILEMODE_BLOB);
|
2014-03-07 17:33:13 +00:00
|
|
|
if (ret)
|
|
|
|
return report_error("trip description tree insert failed");
|
|
|
|
return 0;
|
|
|
|
}
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
static void verify_shared_date(timestamp_t when, struct tm *tm)
|
|
|
|
{
|
|
|
|
struct tm tmp_tm;
|
|
|
|
|
|
|
|
utc_mkdate(when, &tmp_tm);
|
|
|
|
if (tmp_tm.tm_year != tm->tm_year) {
|
|
|
|
tm->tm_year = -1;
|
|
|
|
tm->tm_mon = -1;
|
|
|
|
}
|
|
|
|
if (tmp_tm.tm_mon != tm->tm_mon)
|
|
|
|
tm->tm_mon = -1;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
#define MIN_TIMESTAMP (0)
|
|
|
|
#define MAX_TIMESTAMP (0x7fffffffffffffff)
|
|
|
|
|
2016-04-03 22:31:59 +00:00
|
|
|
static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip_t *trip, struct tm *tm, bool cached_ok)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct dive *dive;
|
|
|
|
struct dir *subdir;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp name;
|
2014-03-07 17:33:13 +00:00
|
|
|
timestamp_t first, last;
|
|
|
|
|
|
|
|
/* Create trip directory */
|
|
|
|
create_trip_name(trip, &name, tm);
|
2015-01-22 21:14:03 +00:00
|
|
|
subdir = new_directory(repo, tree, &name);
|
2024-02-27 21:58:11 +00:00
|
|
|
subdir->unique = true;
|
2014-03-07 17:33:13 +00:00
|
|
|
|
|
|
|
/* Trip description file */
|
|
|
|
save_trip_description(repo, subdir, trip, tm);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
/* Make sure we write out the dates to the dives consistently */
|
|
|
|
first = MAX_TIMESTAMP;
|
|
|
|
last = MIN_TIMESTAMP;
|
|
|
|
for_each_dive(i, dive) {
|
|
|
|
if (dive->divetrip != trip)
|
|
|
|
continue;
|
|
|
|
if (dive->when < first)
|
|
|
|
first = dive->when;
|
|
|
|
if (dive->when > last)
|
|
|
|
last = dive->when;
|
|
|
|
}
|
|
|
|
verify_shared_date(first, tm);
|
|
|
|
verify_shared_date(last, tm);
|
|
|
|
|
|
|
|
/* Save each dive in the directory */
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
for_each_dive(i, dive) {
|
|
|
|
if (dive->divetrip == trip)
|
2016-04-03 22:31:59 +00:00
|
|
|
save_one_dive(repo, subdir, dive, tm, cached_ok);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-06-17 03:28:42 +00:00
|
|
|
static void save_units(void *_b)
|
|
|
|
{
|
2024-02-27 17:40:45 +00:00
|
|
|
struct membuffer *b = (membuffer *)_b;
|
2015-06-17 03:28:42 +00:00
|
|
|
if (prefs.unit_system == METRIC)
|
|
|
|
put_string(b, "units METRIC\n");
|
|
|
|
else if (prefs.unit_system == IMPERIAL)
|
|
|
|
put_string(b, "units IMPERIAL\n");
|
|
|
|
else
|
2016-07-11 18:47:53 +00:00
|
|
|
put_format(b, "units PERSONALIZE %s %s %s %s %s %s\n",
|
2024-02-27 17:40:45 +00:00
|
|
|
prefs.units.length == units::METERS ? "METERS" : "FEET",
|
|
|
|
prefs.units.volume == units::LITER ? "LITER" : "CUFT",
|
|
|
|
prefs.units.pressure == units::BAR ? "BAR" : "PSI",
|
|
|
|
prefs.units.temperature == units::CELSIUS ? "CELSIUS" : prefs.units.temperature == units::FAHRENHEIT ? "FAHRENHEIT" : "KELVIN",
|
|
|
|
prefs.units.weight == units::KG ? "KG" : "LBS",
|
|
|
|
prefs.units.vertical_speed_time == units::SECONDS ? "SECONDS" : "MINUTES");
|
2015-06-17 03:28:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-05 19:38:22 +00:00
|
|
|
static void save_one_device(struct membuffer *b, const struct device *d)
|
2014-03-10 00:35:27 +00:00
|
|
|
{
|
2020-10-05 19:38:22 +00:00
|
|
|
const char *model = device_get_model(d);
|
|
|
|
const char *nickname = device_get_nickname(d);
|
|
|
|
const char *serial = device_get_serial(d);
|
Clean up divecomputer 'device' handling
We have this odd legacy notion of a divecomputer 'device', that was
originally just basically the libdivecomputer 'EVENT_DEVINFO' report
that was associated with each dive. So it had firmware version,
deviceid, and serial number.
It had also gotten extended to do 'nickname' handling, and it was all
confusing, ugly and bad. It was particularly bad because it wasn't
actually a 'per device' thing at all: due to the firmware field, a dive
computer that got a firmware update forced a new 'device'.
To make matters worse, the 'deviceid' was also almost random, because
we've calculated it a couple of different ways, and libdivecomputer
itself has changed how the legacy 32-bit 'serial number' is expressed.
Finally, because of all these issues, we didn't even try to make the
thing unique, so it really ended up being a random snapshot of the state
of the dive computer at the time of a dive, and sometimes we'd pick one,
and sometimes another, since they weren't really well-defined.
So get rid of all this confusion.
The new rules:
- the actual random dive computer state at the time of a dive is kept
in the dive data. So if you want to know the firmware version, it
should be in the 'extra data'
- the only serial number that matters is the string one in the extra
data, because that's the one that actually matches what the dive
computer reports, and isn't some random 32-bit integer with ambiguous
formatting.
- the 'device id' - the thing we match with (together with the model
name, eg "Suunto EON Steel") is purely a hash of the real serial
number.
The device ID that libdivecomputer reports in EVENT_DEVINFO is
ignored, as is the device ID we've saved in the XML or git files. If
we have a serial number, the device ID will be uniquely associated
with that serial number, and if we don't have one, the device ID will
be zero (for 'match anything').
So now 'deviceid' is literally just a shorthand for the serial number
string, and the two are joined at the hip.
- the 'device' managament is _only_ used to track devices that have
serial numbers _and_ nicknames. So no more different device
structures just because one had a nickname and the other didn't etc.
Without a serial number, the device is 'anonymous' and fundamentally
cannot be distinguished from other devices of the same model, so a
nickname is meaningless. And without a nickname, there is no point in
creating a device data structure, since all the data is in the dive
itself and the device structure wouldn't add any value..
These rules mean that we no longer have ambiguous 'device' structures,
and we can never have duplicates that can confuse us.
This does mean that you can't give a nickname to a device that cannot be
uniquely identified with a serial number, but those are happily fairly
rare (and mostly older ones). Dirk said he'd look at what it takes to
give more dive computers proper serial numbers, and I already did it for
the Garmin Descent family yesterday.
(Honesty in advertizing: right now you can't add a nickname to a dive
computer that doesn't already have one, because such a dive computer
will not have a device structure. But that's a UI issue, and I'll sort
that out separately)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-16 22:50:11 +00:00
|
|
|
|
2020-10-05 19:38:22 +00:00
|
|
|
if (empty_string(serial)) serial = NULL;
|
|
|
|
if (empty_string(nickname)) nickname = NULL;
|
Clean up divecomputer 'device' handling
We have this odd legacy notion of a divecomputer 'device', that was
originally just basically the libdivecomputer 'EVENT_DEVINFO' report
that was associated with each dive. So it had firmware version,
deviceid, and serial number.
It had also gotten extended to do 'nickname' handling, and it was all
confusing, ugly and bad. It was particularly bad because it wasn't
actually a 'per device' thing at all: due to the firmware field, a dive
computer that got a firmware update forced a new 'device'.
To make matters worse, the 'deviceid' was also almost random, because
we've calculated it a couple of different ways, and libdivecomputer
itself has changed how the legacy 32-bit 'serial number' is expressed.
Finally, because of all these issues, we didn't even try to make the
thing unique, so it really ended up being a random snapshot of the state
of the dive computer at the time of a dive, and sometimes we'd pick one,
and sometimes another, since they weren't really well-defined.
So get rid of all this confusion.
The new rules:
- the actual random dive computer state at the time of a dive is kept
in the dive data. So if you want to know the firmware version, it
should be in the 'extra data'
- the only serial number that matters is the string one in the extra
data, because that's the one that actually matches what the dive
computer reports, and isn't some random 32-bit integer with ambiguous
formatting.
- the 'device id' - the thing we match with (together with the model
name, eg "Suunto EON Steel") is purely a hash of the real serial
number.
The device ID that libdivecomputer reports in EVENT_DEVINFO is
ignored, as is the device ID we've saved in the XML or git files. If
we have a serial number, the device ID will be uniquely associated
with that serial number, and if we don't have one, the device ID will
be zero (for 'match anything').
So now 'deviceid' is literally just a shorthand for the serial number
string, and the two are joined at the hip.
- the 'device' managament is _only_ used to track devices that have
serial numbers _and_ nicknames. So no more different device
structures just because one had a nickname and the other didn't etc.
Without a serial number, the device is 'anonymous' and fundamentally
cannot be distinguished from other devices of the same model, so a
nickname is meaningless. And without a nickname, there is no point in
creating a device data structure, since all the data is in the dive
itself and the device structure wouldn't add any value..
These rules mean that we no longer have ambiguous 'device' structures,
and we can never have duplicates that can confuse us.
This does mean that you can't give a nickname to a device that cannot be
uniquely identified with a serial number, but those are happily fairly
rare (and mostly older ones). Dirk said he'd look at what it takes to
give more dive computers proper serial numbers, and I already did it for
the Garmin Descent family yesterday.
(Honesty in advertizing: right now you can't add a nickname to a dive
computer that doesn't already have one, because such a dive computer
will not have a device structure. But that's a UI issue, and I'll sort
that out separately)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-16 22:50:11 +00:00
|
|
|
if (!nickname || !serial)
|
2014-03-10 00:35:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
show_utf8(b, "divecomputerid ", model, "");
|
Clean up divecomputer 'device' handling
We have this odd legacy notion of a divecomputer 'device', that was
originally just basically the libdivecomputer 'EVENT_DEVINFO' report
that was associated with each dive. So it had firmware version,
deviceid, and serial number.
It had also gotten extended to do 'nickname' handling, and it was all
confusing, ugly and bad. It was particularly bad because it wasn't
actually a 'per device' thing at all: due to the firmware field, a dive
computer that got a firmware update forced a new 'device'.
To make matters worse, the 'deviceid' was also almost random, because
we've calculated it a couple of different ways, and libdivecomputer
itself has changed how the legacy 32-bit 'serial number' is expressed.
Finally, because of all these issues, we didn't even try to make the
thing unique, so it really ended up being a random snapshot of the state
of the dive computer at the time of a dive, and sometimes we'd pick one,
and sometimes another, since they weren't really well-defined.
So get rid of all this confusion.
The new rules:
- the actual random dive computer state at the time of a dive is kept
in the dive data. So if you want to know the firmware version, it
should be in the 'extra data'
- the only serial number that matters is the string one in the extra
data, because that's the one that actually matches what the dive
computer reports, and isn't some random 32-bit integer with ambiguous
formatting.
- the 'device id' - the thing we match with (together with the model
name, eg "Suunto EON Steel") is purely a hash of the real serial
number.
The device ID that libdivecomputer reports in EVENT_DEVINFO is
ignored, as is the device ID we've saved in the XML or git files. If
we have a serial number, the device ID will be uniquely associated
with that serial number, and if we don't have one, the device ID will
be zero (for 'match anything').
So now 'deviceid' is literally just a shorthand for the serial number
string, and the two are joined at the hip.
- the 'device' managament is _only_ used to track devices that have
serial numbers _and_ nicknames. So no more different device
structures just because one had a nickname and the other didn't etc.
Without a serial number, the device is 'anonymous' and fundamentally
cannot be distinguished from other devices of the same model, so a
nickname is meaningless. And without a nickname, there is no point in
creating a device data structure, since all the data is in the dive
itself and the device structure wouldn't add any value..
These rules mean that we no longer have ambiguous 'device' structures,
and we can never have duplicates that can confuse us.
This does mean that you can't give a nickname to a device that cannot be
uniquely identified with a serial number, but those are happily fairly
rare (and mostly older ones). Dirk said he'd look at what it takes to
give more dive computers proper serial numbers, and I already did it for
the Garmin Descent family yesterday.
(Honesty in advertizing: right now you can't add a nickname to a dive
computer that doesn't already have one, because such a dive computer
will not have a device structure. But that's a UI issue, and I'll sort
that out separately)
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-08-16 22:50:11 +00:00
|
|
|
put_format(b, " deviceid=%08x", calculate_string_hash(serial));
|
2014-03-10 00:35:27 +00:00
|
|
|
show_utf8(b, " serial=", serial, "");
|
|
|
|
show_utf8(b, " nickname=", nickname, "");
|
|
|
|
put_string(b, "\n");
|
|
|
|
}
|
|
|
|
|
2024-02-27 17:40:45 +00:00
|
|
|
static void save_one_fingerprint(struct membuffer *b, int i)
|
2021-10-31 01:01:14 +00:00
|
|
|
{
|
|
|
|
put_format(b, "fingerprint model=%08x serial=%08x deviceid=%08x diveid=%08x data=\"%s\"\n",
|
|
|
|
fp_get_model(&fingerprint_table, i),
|
|
|
|
fp_get_serial(&fingerprint_table, i),
|
|
|
|
fp_get_deviceid(&fingerprint_table, i),
|
|
|
|
fp_get_diveid(&fingerprint_table, i),
|
2024-02-29 07:23:55 +00:00
|
|
|
fp_get_data(&fingerprint_table, i).c_str());
|
2021-10-31 01:01:14 +00:00
|
|
|
}
|
|
|
|
|
2014-03-10 00:35:27 +00:00
|
|
|
static void save_settings(git_repository *repo, struct dir *tree)
|
|
|
|
{
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp b;
|
2014-03-10 00:35:27 +00:00
|
|
|
|
2015-06-20 13:45:12 +00:00
|
|
|
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
for (int i = 0; i < nr_devices(divelog.devices); i++)
|
|
|
|
save_one_device(&b, get_device(divelog.devices, i));
|
2021-10-31 01:01:14 +00:00
|
|
|
/* save the fingerprint data */
|
2024-02-27 17:40:45 +00:00
|
|
|
for (int i = 0; i < nr_fingerprints(&fingerprint_table); i++)
|
2021-10-31 01:01:14 +00:00
|
|
|
save_one_fingerprint(&b, i);
|
|
|
|
|
2022-11-12 08:14:00 +00:00
|
|
|
cond_put_format(divelog.autogroup, &b, "autogroup\n");
|
2015-06-17 03:28:42 +00:00
|
|
|
save_units(&b);
|
2017-02-04 09:13:58 +00:00
|
|
|
if (prefs.tankbar)
|
|
|
|
put_string(&b, "prefs TANKBAR\n");
|
|
|
|
if (prefs.dcceiling)
|
|
|
|
put_string(&b, "prefs DCCEILING\n");
|
2017-02-04 16:55:25 +00:00
|
|
|
if (prefs.show_ccr_setpoint)
|
|
|
|
put_string(&b, "prefs SHOW_SETPOINT\n");
|
|
|
|
if (prefs.show_ccr_sensors)
|
|
|
|
put_string(&b, "prefs SHOW_SENSORS\n");
|
|
|
|
if (prefs.pp_graphs.po2)
|
|
|
|
put_string(&b, "prefs PO2_GRAPH\n");
|
2014-03-10 00:35:27 +00:00
|
|
|
|
|
|
|
blob_insert(repo, tree, &b, "00-Subsurface");
|
|
|
|
}
|
|
|
|
|
2015-02-12 08:14:50 +00:00
|
|
|
static void save_divesites(git_repository *repo, struct dir *tree)
|
|
|
|
{
|
|
|
|
struct dir *subdir;
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp dirname;
|
2015-02-12 08:14:50 +00:00
|
|
|
put_format(&dirname, "01-Divesites");
|
|
|
|
subdir = new_directory(repo, tree, &dirname);
|
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
purge_empty_dive_sites(divelog.sites);
|
|
|
|
for (int i = 0; i < divelog.sites->nr; i++) {
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp b;
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
struct dive_site *ds = get_dive_site(i, divelog.sites);
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp site_file_name;
|
2015-06-25 14:46:37 +00:00
|
|
|
put_format(&site_file_name, "Site-%08x", ds->uuid);
|
2024-05-04 15:18:08 +00:00
|
|
|
show_utf8(&b, "name ", ds->name.c_str(), "\n");
|
|
|
|
show_utf8(&b, "description ", ds->description.c_str(), "\n");
|
|
|
|
show_utf8(&b, "notes ", ds->notes.c_str(), "\n");
|
2018-10-20 18:12:15 +00:00
|
|
|
put_location(&b, &ds->location, "gps ", "\n");
|
2024-05-04 11:39:04 +00:00
|
|
|
for (const auto &t: ds->taxonomy) {
|
|
|
|
if (t.category != TC_NONE && !t.value.empty()) {
|
|
|
|
put_format(&b, "geo cat %d origin %d ", t.category, t.origin);
|
|
|
|
show_utf8(&b, "", t.value.c_str(), "\n" );
|
2015-07-01 19:29:32 +00:00
|
|
|
}
|
2015-08-20 18:05:07 +00:00
|
|
|
}
|
2015-06-25 14:46:37 +00:00
|
|
|
blob_insert(repo, subdir, &b, mb_cstring(&site_file_name));
|
2015-02-12 08:14:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 20:30:01 +00:00
|
|
|
/*
|
|
|
|
* Format a filter constraint line to the membuffer b.
|
|
|
|
* The format is
|
|
|
|
* constraint type "type of the constraint" [stringmode "string mode"] [rangemode "rangemode"] [negate] data "data of the constraint".
|
|
|
|
* where brackets indicate optional blocks.
|
|
|
|
* For possible types and how data is interpreted see core/filterconstraint.[c|h]
|
|
|
|
* Whether stringmode or rangemode exist depends on the type of the constraint.
|
|
|
|
* Any constraint can be negated.
|
|
|
|
*/
|
|
|
|
static void format_one_filter_constraint(int preset_id, int constraint_id, struct membuffer *b)
|
|
|
|
{
|
|
|
|
const struct filter_constraint *constraint = filter_preset_constraint(preset_id, constraint_id);
|
|
|
|
const char *type = filter_constraint_type_to_string(constraint->type);
|
|
|
|
|
|
|
|
show_utf8(b, "constraint type=", type, "");
|
|
|
|
if (filter_constraint_has_string_mode(constraint->type)) {
|
|
|
|
const char *mode = filter_constraint_string_mode_to_string(constraint->string_mode);
|
|
|
|
show_utf8(b, " stringmode=", mode, "");
|
|
|
|
}
|
|
|
|
if (filter_constraint_has_range_mode(constraint->type)) {
|
|
|
|
const char *mode = filter_constraint_range_mode_to_string(constraint->range_mode);
|
|
|
|
show_utf8(b, " rangemode=", mode, "");
|
|
|
|
}
|
|
|
|
if (constraint->negate)
|
|
|
|
put_format(b, " negate");
|
2024-02-29 10:31:46 +00:00
|
|
|
std::string data = filter_constraint_data_to_string(constraint);
|
|
|
|
show_utf8(b, " data=", data.c_str(), "\n");
|
2020-06-18 20:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write a filter constraint to the membuffer b.
|
|
|
|
* Each line starts with a type, which is either "name", "fulltext" or "constraint".
|
2020-10-25 21:07:58 +00:00
|
|
|
* There must be one "name" entry, zero or one "fulltext" entries and an arbitrary number of "contraint" entries.
|
2020-06-18 20:30:01 +00:00
|
|
|
* The "name" entry gives the name of the filter constraint.
|
|
|
|
* The "fulltext" entry has the format
|
|
|
|
* fulltext mode "fulltext mode" query "the query as entered by the user"
|
|
|
|
* The format of the "constraint" entry is described in the format_one_filter_constraint() function.
|
|
|
|
*/
|
|
|
|
static void format_one_filter_preset(int preset_id, struct membuffer *b)
|
|
|
|
{
|
2024-02-29 12:39:17 +00:00
|
|
|
std::string name = filter_preset_name(preset_id);
|
|
|
|
show_utf8(b, "name ", name.c_str(), "\n");
|
2020-06-18 20:30:01 +00:00
|
|
|
|
2024-02-29 12:39:17 +00:00
|
|
|
std::string fulltext = filter_preset_fulltext_query(preset_id);
|
|
|
|
if (!fulltext.empty()) {
|
2020-06-18 20:30:01 +00:00
|
|
|
show_utf8(b, "fulltext mode=", filter_preset_fulltext_mode(preset_id), "");
|
2024-02-29 12:39:17 +00:00
|
|
|
show_utf8(b, " query=", fulltext.c_str(), "\n");
|
2020-06-18 20:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < filter_preset_constraint_count(preset_id); i++)
|
|
|
|
format_one_filter_constraint(preset_id, i, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void save_filter_presets(git_repository *repo, struct dir *tree)
|
|
|
|
{
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp dirname;
|
2020-06-18 20:30:01 +00:00
|
|
|
struct dir *filter_dir;
|
|
|
|
put_format(&dirname, "02-Filterpresets");
|
|
|
|
filter_dir = new_directory(repo, tree, &dirname);
|
|
|
|
|
|
|
|
for (int i = 0; i < filter_presets_count(); i++)
|
|
|
|
{
|
2024-02-27 21:58:11 +00:00
|
|
|
membufferpp preset_name;
|
|
|
|
membufferpp preset_buffer;
|
2020-06-18 20:30:01 +00:00
|
|
|
|
|
|
|
put_format(&preset_name, "Preset-%03d", i);
|
|
|
|
format_one_filter_preset(i, &preset_buffer);
|
|
|
|
|
|
|
|
blob_insert(repo, filter_dir, &preset_buffer, mb_cstring(&preset_name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 22:31:59 +00:00
|
|
|
static int create_git_tree(git_repository *repo, struct dir *root, bool select_only, bool cached_ok)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
2014-03-07 17:33:13 +00:00
|
|
|
int i;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
struct dive *dive;
|
|
|
|
dive_trip_t *trip;
|
|
|
|
|
2017-06-18 06:50:22 +00:00
|
|
|
git_storage_update_progress(translate("gettextFromC", "Start saving data"));
|
2014-03-10 00:35:27 +00:00
|
|
|
save_settings(repo, root);
|
|
|
|
|
2015-02-12 08:14:50 +00:00
|
|
|
save_divesites(repo, root);
|
2020-06-18 20:30:01 +00:00
|
|
|
save_filter_presets(repo, root);
|
2015-02-12 08:14:50 +00:00
|
|
|
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
for (i = 0; i < divelog.trips->nr; ++i)
|
|
|
|
divelog.trips->trips[i]->saved = 0;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
/* save the dives */
|
2017-06-18 06:50:22 +00:00
|
|
|
git_storage_update_progress(translate("gettextFromC", "Start saving dives"));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
for_each_dive(i, dive) {
|
2014-03-07 17:33:13 +00:00
|
|
|
struct tm tm;
|
|
|
|
struct dir *tree;
|
2016-04-04 00:26:05 +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>
2014-03-06 21:28:39 +00:00
|
|
|
trip = dive->divetrip;
|
|
|
|
|
|
|
|
if (select_only) {
|
|
|
|
if (!dive->selected)
|
|
|
|
continue;
|
|
|
|
/* We don't save trips when doing selected dive saves */
|
|
|
|
trip = NULL;
|
|
|
|
}
|
|
|
|
|
2014-03-07 17:33:13 +00:00
|
|
|
/* Create the date-based hierarchy */
|
2018-11-11 12:09:51 +00:00
|
|
|
utc_mkdate(trip ? trip_date(trip) : dive->when, &tm);
|
2016-04-28 22:13:30 +00:00
|
|
|
tree = mktree(repo, root, "%04d", tm.tm_year);
|
2015-01-22 21:14:03 +00:00
|
|
|
tree = mktree(repo, tree, "%02d", tm.tm_mon + 1);
|
2014-03-07 17:33:13 +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>
2014-03-06 21:28:39 +00:00
|
|
|
if (trip) {
|
|
|
|
/* Did we already save this trip? */
|
2018-07-18 06:01:25 +00:00
|
|
|
if (trip->saved)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
continue;
|
2018-07-18 06:01:25 +00:00
|
|
|
trip->saved = 1;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
/* Pass that new subdirectory in for save-trip */
|
2016-04-03 22:31:59 +00:00
|
|
|
save_one_trip(repo, tree, trip, &tm, cached_ok);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-03 22:31:59 +00:00
|
|
|
save_one_dive(repo, tree, dive, &tm, cached_ok);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
2017-06-18 06:50:22 +00:00
|
|
|
git_storage_update_progress(translate("gettextFromC", "Done creating local cache"));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-03-13 22:42:45 +00:00
|
|
|
/*
|
|
|
|
* See if we can find the parent ID that the git data came from
|
|
|
|
*/
|
|
|
|
static git_object *try_to_find_parent(const char *hex_id, git_repository *repo)
|
|
|
|
{
|
|
|
|
git_oid object_id;
|
|
|
|
git_commit *commit;
|
|
|
|
|
|
|
|
if (!hex_id)
|
|
|
|
return NULL;
|
|
|
|
if (git_oid_fromstr(&object_id, hex_id))
|
|
|
|
return NULL;
|
|
|
|
if (git_commit_lookup(&commit, repo, &object_id))
|
|
|
|
return NULL;
|
|
|
|
return (git_object *)commit;
|
|
|
|
}
|
|
|
|
|
2024-02-27 17:40:45 +00:00
|
|
|
static int notify_cb(git_checkout_notify_t,
|
2014-03-19 20:28:47 +00:00
|
|
|
const char *path,
|
2024-02-27 17:40:45 +00:00
|
|
|
const git_diff_file *,
|
|
|
|
const git_diff_file *,
|
|
|
|
const git_diff_file *,
|
|
|
|
void *)
|
2014-03-19 20:28:47 +00:00
|
|
|
{
|
|
|
|
report_error("File '%s' does not match in working tree", path);
|
|
|
|
return 0; /* Continue with checkout */
|
|
|
|
}
|
|
|
|
|
|
|
|
static git_tree *get_git_tree(git_repository *repo, git_object *parent)
|
|
|
|
{
|
|
|
|
git_tree *tree;
|
|
|
|
if (!parent)
|
|
|
|
return NULL;
|
|
|
|
if (git_tree_lookup(&tree, repo, git_commit_tree_id((const git_commit *) parent)))
|
|
|
|
return NULL;
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
2024-02-27 17:40:45 +00:00
|
|
|
extern "C" int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree)
|
2014-03-19 20:28:47 +00:00
|
|
|
{
|
2014-03-21 18:08:34 +00:00
|
|
|
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
|
2014-03-19 20:28:47 +00:00
|
|
|
|
|
|
|
opts.checkout_strategy = GIT_CHECKOUT_SAFE;
|
|
|
|
opts.notify_flags = GIT_CHECKOUT_NOTIFY_CONFLICT | GIT_CHECKOUT_NOTIFY_DIRTY;
|
|
|
|
opts.notify_cb = notify_cb;
|
|
|
|
opts.baseline = get_git_tree(repo, parent);
|
|
|
|
return git_checkout_tree(repo, (git_object *) tree, &opts);
|
|
|
|
}
|
|
|
|
|
2024-02-27 17:40:45 +00:00
|
|
|
extern "C" int get_authorship(git_repository *repo, git_signature **authorp)
|
2014-04-14 21:33:46 +00:00
|
|
|
{
|
2015-06-18 21:12:01 +00:00
|
|
|
if (git_signature_default(authorp, repo) == 0)
|
|
|
|
return 0;
|
2020-04-10 00:03:43 +00:00
|
|
|
|
|
|
|
#ifdef SUBSURFACE_MOBILE
|
|
|
|
#define APPNAME "Subsurface-mobile"
|
|
|
|
#else
|
|
|
|
#define APPNAME "Subsurface"
|
2015-06-18 21:12:01 +00:00
|
|
|
#endif
|
2020-04-10 00:03:43 +00:00
|
|
|
return git_signature_now(authorp, APPNAME, "subsurface-app-account@subsurface-divelog.org");
|
|
|
|
#undef APPNAME
|
2014-04-14 21:33:46 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 16:37:57 +00:00
|
|
|
static void create_commit_message(struct membuffer *msg, bool create_empty)
|
2014-04-28 01:18:12 +00:00
|
|
|
{
|
core: introduce divelog structure
The parser API was very annoying, as a number of tables
to-be-filled were passed in as pointers. The goal of this
commit is to collect all these tables in a single struct.
This should make it (more or less) clear what is actually
written into the divelog files.
Moreover, it should now be rather easy to search for
instances, where the global logfile is accessed (and it
turns out that there are many!).
The divelog struct does not contain the tables as substructs,
but only collects pointers. The idea is that the "divelog.h"
file can be included without all the other files describing
the numerous tables.
To make it easier to use from C++ parts of the code, the
struct implements a constructor and a destructor. Sadly,
we can't use smart pointers, since the pointers are accessed
from C code. Therfore the constructor and destructor are
quite complex.
The whole commit is large, but was mostly an automatic
conversion.
One oddity of note: the divelog structure also contains
the "autogroup" flag, since that is saved in the divelog.
This actually fixes a bug: Before, when importing dives
from a different log, the autogroup flag was overwritten.
This was probably not intended and does not happen anymore.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2022-11-08 20:31:08 +00:00
|
|
|
int nr = divelog.dives->nr;
|
2014-04-28 01:18:12 +00:00
|
|
|
struct dive *dive = get_dive(nr-1);
|
2024-02-27 22:10:09 +00:00
|
|
|
std::string changes_made = get_changes_made();
|
2014-04-28 01:18:12 +00:00
|
|
|
|
2017-10-26 16:37:57 +00:00
|
|
|
if (create_empty) {
|
|
|
|
put_string(msg, "Initial commit to create empty repo.\n\n");
|
2024-02-27 22:10:09 +00:00
|
|
|
} else if (!changes_made.empty()) {
|
|
|
|
put_format(msg, "Changes made: \n\n%s\n", changes_made.c_str());
|
2017-10-26 16:37:57 +00:00
|
|
|
} else if (dive) {
|
2014-04-28 01:18:12 +00:00
|
|
|
dive_trip_t *trip = dive->divetrip;
|
2024-05-04 15:18:08 +00:00
|
|
|
std::string location = get_dive_location(dive);
|
|
|
|
if (location.empty())
|
|
|
|
location = "no location";
|
2014-05-14 06:58:46 +00:00
|
|
|
struct divecomputer *dc = &dive->dc;
|
|
|
|
const char *sep = "\n";
|
2014-04-28 01:18:12 +00:00
|
|
|
|
|
|
|
if (dive->number)
|
|
|
|
nr = dive->number;
|
|
|
|
|
2024-05-04 15:18:08 +00:00
|
|
|
put_format(msg, "dive %d: %s", nr, location.c_str());
|
|
|
|
if (trip && !empty_string(trip->location) && location != trip->location)
|
2014-04-28 01:18:12 +00:00
|
|
|
put_format(msg, " (%s)", trip->location);
|
2014-05-14 06:58:46 +00:00
|
|
|
put_format(msg, "\n");
|
|
|
|
do {
|
2018-01-07 14:42:28 +00:00
|
|
|
if (!empty_string(dc->model)) {
|
2014-05-14 06:58:46 +00:00
|
|
|
put_format(msg, "%s%s", sep, dc->model);
|
|
|
|
sep = ", ";
|
|
|
|
}
|
|
|
|
} while ((dc = dc->next) != NULL);
|
|
|
|
put_format(msg, "\n");
|
2014-04-28 01:18:12 +00:00
|
|
|
}
|
2024-02-27 22:10:09 +00:00
|
|
|
put_format(msg, "Created by %s\n", subsurface_user_agent().c_str());
|
2020-03-05 16:58:20 +00:00
|
|
|
if (verbose)
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("Commit message:\n\n%s\n", mb_cstring(msg));
|
2014-04-28 01:18:12 +00:00
|
|
|
}
|
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
static int create_new_commit(struct git_info *info, git_oid *tree_id, bool create_empty)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
git_reference *ref;
|
|
|
|
git_object *parent;
|
|
|
|
git_oid commit_id;
|
|
|
|
git_signature *author;
|
|
|
|
git_commit *commit;
|
|
|
|
git_tree *tree;
|
|
|
|
|
2024-03-11 20:41:14 +00:00
|
|
|
ret = git_branch_lookup(&ref, info->repo, info->branch.c_str(), GIT_BRANCH_LOCAL);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
switch (ret) {
|
|
|
|
default:
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error("Bad branch '%s' (%s)", info->branch.c_str(), strerror(errno));
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
case GIT_EINVALIDSPEC:
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error("Invalid branch name '%s'", info->branch.c_str());
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
case GIT_ENOTFOUND: /* We'll happily create it */
|
2014-03-13 22:42:45 +00:00
|
|
|
ref = NULL;
|
2024-02-28 07:49:42 +00:00
|
|
|
parent = try_to_find_parent(saved_git_id.c_str(), info->repo);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (git_reference_peel(&parent, ref, GIT_OBJ_COMMIT))
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error("Unable to look up parent in branch '%s'", info->branch.c_str());
|
2014-03-11 21:55:43 +00:00
|
|
|
|
2024-02-28 07:49:42 +00:00
|
|
|
if (!saved_git_id.empty()) {
|
2024-03-16 15:06:39 +00:00
|
|
|
if (!existing_filename.empty() && verbose)
|
|
|
|
report_info("existing filename %s\n", existing_filename.c_str());
|
2014-03-13 22:42:45 +00:00
|
|
|
const git_oid *id = git_commit_id((const git_commit *) parent);
|
2015-06-17 16:45:39 +00:00
|
|
|
/* if we are saving to the same git tree we got this from, let's make
|
|
|
|
* sure there is no confusion */
|
2024-03-16 15:06:39 +00:00
|
|
|
if (existing_filename == info->url && git_oid_strcmp(id, saved_git_id.c_str()))
|
2014-03-13 22:42:45 +00:00
|
|
|
return report_error("The git branch does not match the git parent of the source");
|
|
|
|
}
|
2014-03-11 21:55:43 +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>
2014-03-06 21:28:39 +00:00
|
|
|
/* all good */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
if (git_tree_lookup(&tree, info->repo, tree_id))
|
2014-03-07 17:33:13 +00:00
|
|
|
return report_error("Could not look up newly created tree");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
if (get_authorship(info->repo, &author))
|
2014-03-07 17:33:13 +00:00
|
|
|
return report_error("No user name configuration in git repo");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2014-03-13 22:42:45 +00:00
|
|
|
/* If the parent commit has the same tree ID, do not create a new commit */
|
|
|
|
if (parent && git_oid_equal(tree_id, git_commit_tree_id((const git_commit *) parent))) {
|
|
|
|
/* If the parent already came from the ref, the commit is already there */
|
2017-12-26 23:17:00 +00:00
|
|
|
if (ref) {
|
|
|
|
git_signature_free(author);
|
2014-03-13 22:42:45 +00:00
|
|
|
return 0;
|
2017-12-26 23:17:00 +00:00
|
|
|
}
|
2014-03-13 22:42:45 +00:00
|
|
|
/* Else we do want to create the new branch, but with the old commit */
|
|
|
|
commit = (git_commit *) parent;
|
|
|
|
} else {
|
2024-02-27 21:58:11 +00:00
|
|
|
struct membufferpp commit_msg;
|
2014-04-28 01:18:12 +00:00
|
|
|
|
2017-10-26 16:37:57 +00:00
|
|
|
create_commit_message(&commit_msg, create_empty);
|
2022-04-13 16:43:37 +00:00
|
|
|
if (git_commit_create_v(&commit_id, info->repo, NULL, author, author, NULL, mb_cstring(&commit_msg), tree, parent != NULL, parent)) {
|
2017-12-26 23:17:00 +00:00
|
|
|
git_signature_free(author);
|
2014-03-13 22:42:45 +00:00
|
|
|
return report_error("Git commit create failed (%s)", strerror(errno));
|
2017-12-26 23:17:00 +00:00
|
|
|
}
|
2014-03-13 22:42:45 +00:00
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
if (git_commit_lookup(&commit, info->repo, &commit_id)) {
|
2017-12-26 23:17:00 +00:00
|
|
|
git_signature_free(author);
|
2014-03-13 22:42:45 +00:00
|
|
|
return report_error("Could not look up newly created commit");
|
2017-12-26 23:17:00 +00:00
|
|
|
}
|
2014-03-13 22:42:45 +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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2017-12-26 23:17:00 +00:00
|
|
|
git_signature_free(author);
|
|
|
|
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
if (!ref) {
|
2024-03-11 20:41:14 +00:00
|
|
|
if (git_branch_create(&ref, info->repo, info->branch.c_str(), commit, 0))
|
|
|
|
return report_error("Failed to create branch '%s'", info->branch.c_str());
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
2014-03-19 20:28:47 +00:00
|
|
|
/*
|
|
|
|
* If it's a checked-out branch, try to also update the working
|
|
|
|
* tree and index. If that fails (dirty working tree or whatever),
|
|
|
|
* this is not technically a save error (we did save things in
|
|
|
|
* the object database), but it can cause extreme confusion, so
|
|
|
|
* warn about it.
|
|
|
|
*/
|
2022-04-13 16:43:37 +00:00
|
|
|
if (git_branch_is_head(ref) && !git_repository_is_bare(info->repo)) {
|
|
|
|
if (update_git_checkout(info->repo, parent, tree)) {
|
2014-03-19 20:28:47 +00:00
|
|
|
const git_error *err = giterr_last();
|
|
|
|
const char *errstr = err ? err->message : strerror(errno);
|
|
|
|
report_error("Git branch '%s' is checked out, but worktree is dirty (%s)",
|
2024-03-11 20:41:14 +00:00
|
|
|
info->branch.c_str(), errstr);
|
2014-03-19 20:28:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 06:34:15 +00:00
|
|
|
if (git_reference_set_target(&ref, ref, &commit_id, "Subsurface save event"))
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error("Failed to update branch '%s'", info->branch.c_str());
|
2017-10-26 16:37:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if this was the empty commit to initialize a new repo, don't remember the
|
|
|
|
* commit_id, otherwise we'll think that the cache is valid and fail when building
|
|
|
|
* the tree when we actually try to store the dive data
|
|
|
|
*/
|
|
|
|
if (! create_empty)
|
|
|
|
set_git_id(&commit_id);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-02-27 21:58:11 +00:00
|
|
|
static int write_git_tree(git_repository *repo, const struct dir *tree, git_oid *result)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Write out our subdirectories, add them to the treebuilder, and free them */
|
2024-02-27 21:58:11 +00:00
|
|
|
for (auto &subdir: tree->subdirs) {
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
git_oid id;
|
|
|
|
|
2024-02-27 21:58:11 +00:00
|
|
|
if (!write_git_tree(repo, subdir.get(), &id))
|
|
|
|
tree_insert(tree->files, subdir->name.c_str(), subdir->unique, &id, GIT_FILEMODE_TREE);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* .. write out the resulting treebuilder */
|
2015-12-15 06:34:15 +00:00
|
|
|
ret = git_treebuilder_write(result, tree->files);
|
2020-04-14 13:51:43 +00:00
|
|
|
if (ret && verbose) {
|
|
|
|
const git_error *gerr = giterr_last();
|
|
|
|
if (gerr)
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("tree_insert failed with return %d error %s\n", ret, gerr->message);
|
2020-04-14 13:51:43 +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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-03-11 20:41:14 +00:00
|
|
|
int do_git_save(struct git_info *info, bool select_only, bool create_empty)
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
{
|
|
|
|
struct dir tree;
|
|
|
|
git_oid id;
|
2016-04-06 04:21:20 +00:00
|
|
|
bool cached_ok;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
if (!info->repo)
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error("Unable to open git repository '%s[%s]'", info->url.c_str(), info->branch.c_str());
|
2022-04-13 16:43:37 +00:00
|
|
|
|
2015-09-20 17:11:09 +00:00
|
|
|
if (verbose)
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("git storage: do git save\n");
|
2015-09-20 17:11:09 +00:00
|
|
|
|
2016-04-04 00:26:05 +00:00
|
|
|
if (!create_empty) // so we are actually saving the dives
|
2017-06-18 06:50:22 +00:00
|
|
|
git_storage_update_progress(translate("gettextFromC", "Preparing to save data"));
|
2016-04-04 00:26:05 +00:00
|
|
|
|
2016-04-06 04:21:20 +00:00
|
|
|
/*
|
|
|
|
* Check if we can do the cached writes - we need to
|
|
|
|
* have the original git commit we loaded in the repo
|
|
|
|
*/
|
2024-02-28 07:49:42 +00:00
|
|
|
cached_ok = try_to_find_parent(saved_git_id.c_str(), info->repo);
|
2016-04-06 04:21:20 +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>
2014-03-06 21:28:39 +00:00
|
|
|
/* Start with an empty tree: no subdirectories, no files */
|
2022-04-13 16:43:37 +00:00
|
|
|
if (git_treebuilder_new(&tree.files, info->repo, NULL))
|
2014-03-07 17:33:13 +00:00
|
|
|
return report_error("git treebuilder failed");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2015-06-14 01:27:41 +00:00
|
|
|
if (!create_empty)
|
|
|
|
/* Populate our tree data structure */
|
2022-04-13 16:43:37 +00:00
|
|
|
if (create_git_tree(info->repo, &tree, select_only, cached_ok))
|
2015-06-14 01:27:41 +00:00
|
|
|
return -1;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
2016-04-04 00:26:05 +00:00
|
|
|
if (verbose)
|
2024-03-12 08:25:39 +00:00
|
|
|
report_info("git storage, write git tree\n");
|
2016-04-04 00:26:05 +00:00
|
|
|
|
2022-04-13 16:43:37 +00:00
|
|
|
if (write_git_tree(info->repo, &tree, &id))
|
2014-03-07 17:33:13 +00:00
|
|
|
return report_error("git tree write failed");
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
|
|
|
|
/* And save the tree! */
|
2022-04-13 16:43:37 +00:00
|
|
|
if (create_new_commit(info, &id, create_empty))
|
2015-06-12 19:32:12 +00:00
|
|
|
return report_error("creating commit failed");
|
|
|
|
|
2017-12-23 19:59:03 +00:00
|
|
|
/* now sync the tree with the remote server */
|
2024-03-11 20:41:14 +00:00
|
|
|
if (!info->url.empty() && !git_local_only)
|
2022-04-13 16:43:37 +00:00
|
|
|
return sync_with_remote(info);
|
2015-06-14 03:03:20 +00:00
|
|
|
return 0;
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|
|
|
|
|
2024-03-11 20:41:14 +00:00
|
|
|
int git_save_dives(struct git_info *info, bool select_only)
|
2014-03-12 21:12:58 +00:00
|
|
|
{
|
2022-04-13 16:43:37 +00:00
|
|
|
/*
|
2022-04-18 21:51:14 +00:00
|
|
|
* First, just try to open the local git repo without
|
|
|
|
* doing any remote updates at all. If networking is
|
|
|
|
* reliable, the remote has been updated at open time,
|
|
|
|
* and we want to update *after* saving.
|
2022-04-13 16:43:37 +00:00
|
|
|
*
|
2022-04-18 21:51:14 +00:00
|
|
|
* And if networking isn't reliable, we want to save
|
|
|
|
* first anyway.
|
2022-04-13 16:43:37 +00:00
|
|
|
*
|
2022-04-18 21:51:14 +00:00
|
|
|
* Note that 'do_git_save()' will try to sync with the
|
|
|
|
* remote after saving (see sync_with_remote()), so we
|
|
|
|
* will be doing the remote access at that point, but
|
|
|
|
* at least the local state will be saved early in
|
|
|
|
* case something goes wrong.
|
|
|
|
*/
|
2024-03-11 20:41:14 +00:00
|
|
|
if (!git_repository_open(&info->repo, info->localdir.c_str()))
|
2022-04-18 21:51:14 +00:00
|
|
|
return do_git_save(info, select_only, false);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, so there was something wrong with the local
|
|
|
|
* repo (possibly it's just missing entirely). That
|
|
|
|
* means we don't want to just save to it, we'll
|
|
|
|
* need to try to load the remote state first.
|
|
|
|
*
|
|
|
|
* This shouldn't be the common case.
|
2022-04-13 16:43:37 +00:00
|
|
|
*/
|
|
|
|
if (!open_git_repository(info))
|
2024-03-11 20:41:14 +00:00
|
|
|
return report_error(translate("gettextFromC", "Failed to save dives to %s[%s] (%s)"), info->url.c_str(), info->branch.c_str(), strerror(errno));
|
2022-04-13 16:43:37 +00:00
|
|
|
|
2022-04-18 21:36:00 +00:00
|
|
|
return do_git_save(info, select_only, false);
|
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>
2014-03-06 21:28:39 +00:00
|
|
|
}
|