mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 20:53:23 +00:00
Track minimum datafile version
Add infrastructure and helper functions to track minimum datafile version. To make this information useful we need to keep the XML and git data format versions in track moving forward. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
70d4421cd0
commit
de35c88683
7 changed files with 40 additions and 10 deletions
18
divelist.c
18
divelist.c
|
@ -1080,3 +1080,21 @@ void set_dive_nr_for_current_dive()
|
|||
else if (selected_dive == dive_table.nr - 1 && get_dive(dive_table.nr - 2)->number)
|
||||
current_dive->number = get_dive(dive_table.nr - 2)->number + 1;
|
||||
}
|
||||
|
||||
static int min_datafile_version;
|
||||
|
||||
int get_min_datafile_version()
|
||||
{
|
||||
return min_datafile_version;
|
||||
}
|
||||
|
||||
void reset_min_datafile_version()
|
||||
{
|
||||
min_datafile_version = 0;
|
||||
}
|
||||
|
||||
void report_datafile_version(int version)
|
||||
{
|
||||
if (min_datafile_version == 0 || min_datafile_version > version)
|
||||
min_datafile_version = version;
|
||||
}
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* this is used for both git and xml format */
|
||||
#define DATAFORMAT_VERSION 3
|
||||
|
||||
struct dive;
|
||||
|
||||
extern void update_cylinder_related_info(struct dive *);
|
||||
|
@ -41,6 +44,10 @@ extern struct dive *last_selected_dive();
|
|||
extern bool is_trip_before_after(struct dive *dive, bool before);
|
||||
extern void set_dive_nr_for_current_dive();
|
||||
|
||||
int get_min_datafile_version();
|
||||
void reset_min_datafile_version();
|
||||
void report_datafile_version(int version);
|
||||
|
||||
#ifdef DEBUG_TRIP
|
||||
extern void dump_selection(void);
|
||||
extern void dump_trip_list(void);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "gettext.h"
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
#include "git-access.h"
|
||||
|
@ -745,13 +746,15 @@ static void parse_settings_userid(char *line, struct membuffer *str, void *_unus
|
|||
* Our versioning is a joke right now, but this is more of an example of what we
|
||||
* *can* do some day. And if we do change the version, this warning will show if
|
||||
* you read with a version of subsurface that doesn't know about it.
|
||||
* We MUST keep this in sync with the XML version (so we can report a consistent
|
||||
* minimum datafile version)
|
||||
*/
|
||||
#define VERSION 3
|
||||
static void parse_settings_version(char *line, struct membuffer *str, void *_unused)
|
||||
{
|
||||
int version = atoi(line);
|
||||
if (version > VERSION)
|
||||
report_error("Git save file version %d is newer than version %d I know about", version, VERSION);
|
||||
report_datafile_version(version);
|
||||
if (version > DATAFORMAT_VERSION)
|
||||
report_error("Git save file version %d is newer than version %d I know about", version, DATAFORMAT_VERSION);
|
||||
}
|
||||
|
||||
/* The string in the membuffer is the version string of subsurface that saved things, just FYI */
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "gettext.h"
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
|
||||
|
@ -1715,6 +1716,7 @@ static bool entry(const char *name, char *buf)
|
|||
if (!strncmp(name, "version.program", sizeof("version.program") - 1) ||
|
||||
!strncmp(name, "version.divelog", sizeof("version.divelog") - 1)) {
|
||||
last_xml_version = atoi(buf);
|
||||
report_datafile_version(last_xml_version);
|
||||
}
|
||||
if (in_userid) {
|
||||
try_to_fill_userid(name, buf);
|
||||
|
|
|
@ -458,6 +458,8 @@ void MainWindow::closeCurrentFile()
|
|||
free((void *)existing_filename);
|
||||
existing_filename = NULL;
|
||||
|
||||
reset_min_datafile_version();
|
||||
|
||||
cleanUpEmpty();
|
||||
mark_divelist_changed(false);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <git2.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
#include "git-access.h"
|
||||
|
@ -832,13 +833,11 @@ static void save_one_device(void *_b, const char *model, uint32_t deviceid,
|
|||
put_string(b, "\n");
|
||||
}
|
||||
|
||||
#define VERSION 3
|
||||
|
||||
static void save_settings(git_repository *repo, struct dir *tree)
|
||||
{
|
||||
struct membuffer b = { 0 };
|
||||
|
||||
put_format(&b, "version %d\n", VERSION);
|
||||
put_format(&b, "version %d\n", DATAFORMAT_VERSION);
|
||||
save_userid(&b);
|
||||
call_for_each_dc(&b, save_one_device, false);
|
||||
cond_put_format(autogroup, &b, "autogroup\n");
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <fcntl.h>
|
||||
|
||||
#include "dive.h"
|
||||
#include "divelist.h"
|
||||
#include "device.h"
|
||||
#include "membuffer.h"
|
||||
#include "strndup.h"
|
||||
|
@ -483,8 +484,6 @@ static void save_one_device(void *_f, const char *model, uint32_t deviceid,
|
|||
put_format(b, "/>\n");
|
||||
}
|
||||
|
||||
#define VERSION 3
|
||||
|
||||
int save_dives(const char *filename)
|
||||
{
|
||||
return save_dives_logic(filename, false);
|
||||
|
@ -496,7 +495,7 @@ void save_dives_buffer(struct membuffer *b, const bool select_only)
|
|||
struct dive *dive;
|
||||
dive_trip_t *trip;
|
||||
|
||||
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);
|
||||
put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);
|
||||
|
||||
if (prefs.save_userid_local)
|
||||
put_format(b, " <userid>%30s</userid>\n", prefs.userid);
|
||||
|
@ -618,7 +617,7 @@ static void try_to_backup(const char *filename)
|
|||
while (extension[i][0] != '\0') {
|
||||
int elen = strlen(extension[i]);
|
||||
if (strcasecmp(filename + flen - elen, extension[i]) == 0) {
|
||||
if (last_xml_version < VERSION) {
|
||||
if (last_xml_version < DATAFORMAT_VERSION) {
|
||||
int se_len = strlen(extension[i]) + 5;
|
||||
char *special_ext = malloc(se_len);
|
||||
snprintf(special_ext, se_len, "%s.v%d", extension[i], last_xml_version);
|
||||
|
|
Loading…
Add table
Reference in a new issue