summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--divelist.c18
-rw-r--r--divelist.h7
-rw-r--r--load-git.c9
-rw-r--r--parse-xml.c2
-rw-r--r--qt-ui/mainwindow.cpp2
-rw-r--r--save-git.c5
-rw-r--r--save-xml.c7
7 files changed, 40 insertions, 10 deletions
diff --git a/divelist.c b/divelist.c
index 468373591..953dd7839 100644
--- a/divelist.c
+++ b/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;
+}
diff --git a/divelist.h b/divelist.h
index 91318c3b1..04f26f68a 100644
--- a/divelist.h
+++ b/divelist.h
@@ -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);
diff --git a/load-git.c b/load-git.c
index 6a054e887..6cf62ec79 100644
--- a/load-git.c
+++ b/load-git.c
@@ -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 */
diff --git a/parse-xml.c b/parse-xml.c
index aaf8651c0..0e8e3a556 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -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);
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 0095aaf97..d9a2769c2 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -458,6 +458,8 @@ void MainWindow::closeCurrentFile()
free((void *)existing_filename);
existing_filename = NULL;
+ reset_min_datafile_version();
+
cleanUpEmpty();
mark_divelist_changed(false);
diff --git a/save-git.c b/save-git.c
index e13847125..4e5ed38e0 100644
--- a/save-git.c
+++ b/save-git.c
@@ -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");
diff --git a/save-xml.c b/save-xml.c
index 8ff133122..620980a60 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -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);