core: convert core/save-git.c to C++

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-02-27 18:40:45 +01:00 committed by Michael Keller
parent 148775f418
commit 371b155922
3 changed files with 23 additions and 28 deletions

View file

@ -78,7 +78,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/worldmap-save.c \ core/worldmap-save.c \
core/libdivecomputer.c \ core/libdivecomputer.c \
core/version.c \ core/version.c \
core/save-git.c \ core/save-git.cpp \
core/datatrak.c \ core/datatrak.c \
core/ostctools.c \ core/ostctools.c \
core/planner.c \ core/planner.c \

View file

@ -155,7 +155,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
range.h range.h
sample.cpp sample.cpp
sample.h sample.h
save-git.c save-git.cpp
save-html.c save-html.c
save-html.h save-html.h
save-profiledata.c save-profiledata.c

View file

@ -373,7 +373,7 @@ static void save_samples(struct membuffer *b, struct dive *dive, struct divecomp
int nr; int nr;
int o2sensor; int o2sensor;
struct sample *s; struct sample *s;
struct sample dummy = { .bearing.degrees = -1, .ndl.seconds = -1 }; struct sample dummy;
/* Is this a CCR dive with the old-style "o2pressure" sensor? */ /* Is this a CCR dive with the old-style "o2pressure" sensor? */
o2sensor = legacy_format_o2pressures(dive, dc); o2sensor = legacy_format_o2pressures(dive, dc);
@ -498,7 +498,7 @@ struct dir {
char unique, name[1]; char unique, name[1];
}; };
static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, unsigned mode) static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, git_filemode_t mode)
{ {
int ret; int ret;
struct membuffer uniquename = { 0 }; struct membuffer uniquename = { 0 };
@ -534,7 +534,7 @@ static struct dir *new_directory(git_repository *repo, struct dir *parent, struc
const char *name = mb_cstring(namebuf); const char *name = mb_cstring(namebuf);
int len = namebuf->len; int len = namebuf->len;
subdir = malloc(sizeof(*subdir)+len); subdir = (struct dir *)malloc(sizeof(*subdir)+len);
/* /*
* It starts out empty: no subdirectories of its own, * It starts out empty: no subdirectories of its own,
@ -851,19 +851,19 @@ static int save_one_trip(git_repository *repo, struct dir *tree, dive_trip_t *tr
static void save_units(void *_b) static void save_units(void *_b)
{ {
struct membuffer *b =_b; struct membuffer *b = (membuffer *)_b;
if (prefs.unit_system == METRIC) if (prefs.unit_system == METRIC)
put_string(b, "units METRIC\n"); put_string(b, "units METRIC\n");
else if (prefs.unit_system == IMPERIAL) else if (prefs.unit_system == IMPERIAL)
put_string(b, "units IMPERIAL\n"); put_string(b, "units IMPERIAL\n");
else else
put_format(b, "units PERSONALIZE %s %s %s %s %s %s\n", put_format(b, "units PERSONALIZE %s %s %s %s %s %s\n",
prefs.units.length == METERS ? "METERS" : "FEET", prefs.units.length == units::METERS ? "METERS" : "FEET",
prefs.units.volume == LITER ? "LITER" : "CUFT", prefs.units.volume == units::LITER ? "LITER" : "CUFT",
prefs.units.pressure == BAR ? "BAR" : "PSI", prefs.units.pressure == units::BAR ? "BAR" : "PSI",
prefs.units.temperature == CELSIUS ? "CELSIUS" : prefs.units.temperature == FAHRENHEIT ? "FAHRENHEIT" : "KELVIN", prefs.units.temperature == units::CELSIUS ? "CELSIUS" : prefs.units.temperature == units::FAHRENHEIT ? "FAHRENHEIT" : "KELVIN",
prefs.units.weight == KG ? "KG" : "LBS", prefs.units.weight == units::KG ? "KG" : "LBS",
prefs.units.vertical_speed_time == SECONDS ? "SECONDS" : "MINUTES"); prefs.units.vertical_speed_time == units::SECONDS ? "SECONDS" : "MINUTES");
} }
static void save_one_device(struct membuffer *b, const struct device *d) static void save_one_device(struct membuffer *b, const struct device *d)
@ -884,7 +884,7 @@ static void save_one_device(struct membuffer *b, const struct device *d)
put_string(b, "\n"); put_string(b, "\n");
} }
static void save_one_fingerprint(struct membuffer *b, unsigned int i) static void save_one_fingerprint(struct membuffer *b, int i)
{ {
char *fp_data = fp_get_data(&fingerprint_table, i); char *fp_data = fp_get_data(&fingerprint_table, i);
put_format(b, "fingerprint model=%08x serial=%08x deviceid=%08x diveid=%08x data=\"%s\"\n", put_format(b, "fingerprint model=%08x serial=%08x deviceid=%08x diveid=%08x data=\"%s\"\n",
@ -904,7 +904,7 @@ static void save_settings(git_repository *repo, struct dir *tree)
for (int i = 0; i < nr_devices(divelog.devices); i++) for (int i = 0; i < nr_devices(divelog.devices); i++)
save_one_device(&b, get_device(divelog.devices, i)); save_one_device(&b, get_device(divelog.devices, i));
/* save the fingerprint data */ /* save the fingerprint data */
for (unsigned int i = 0; i < nr_fingerprints(&fingerprint_table); i++) for (int i = 0; i < nr_fingerprints(&fingerprint_table); i++)
save_one_fingerprint(&b, i); save_one_fingerprint(&b, i);
cond_put_format(divelog.autogroup, &b, "autogroup\n"); cond_put_format(divelog.autogroup, &b, "autogroup\n");
@ -1105,18 +1105,13 @@ static git_object *try_to_find_parent(const char *hex_id, git_repository *repo)
return (git_object *)commit; return (git_object *)commit;
} }
static int notify_cb(git_checkout_notify_t why, static int notify_cb(git_checkout_notify_t,
const char *path, const char *path,
const git_diff_file *baseline, const git_diff_file *,
const git_diff_file *target, const git_diff_file *,
const git_diff_file *workdir, const git_diff_file *,
void *payload) void *)
{ {
UNUSED(baseline);
UNUSED(target);
UNUSED(workdir);
UNUSED(payload);
UNUSED(why);
report_error("File '%s' does not match in working tree", path); report_error("File '%s' does not match in working tree", path);
return 0; /* Continue with checkout */ return 0; /* Continue with checkout */
} }
@ -1131,7 +1126,7 @@ static git_tree *get_git_tree(git_repository *repo, git_object *parent)
return tree; return tree;
} }
int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree) extern "C" int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree)
{ {
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
@ -1142,7 +1137,7 @@ int update_git_checkout(git_repository *repo, git_object *parent, git_tree *tree
return git_checkout_tree(repo, (git_object *) tree, &opts); return git_checkout_tree(repo, (git_object *) tree, &opts);
} }
int get_authorship(git_repository *repo, git_signature **authorp) extern "C" int get_authorship(git_repository *repo, git_signature **authorp)
{ {
if (git_signature_default(authorp, repo) == 0) if (git_signature_default(authorp, repo) == 0)
return 0; return 0;
@ -1329,7 +1324,7 @@ static int write_git_tree(git_repository *repo, struct dir *tree, git_oid *resul
return ret; return ret;
} }
int do_git_save(struct git_info *info, bool select_only, bool create_empty) extern "C" int do_git_save(struct git_info *info, bool select_only, bool create_empty)
{ {
struct dir tree; struct dir tree;
git_oid id; git_oid id;
@ -1377,7 +1372,7 @@ int do_git_save(struct git_info *info, bool select_only, bool create_empty)
return 0; return 0;
} }
int git_save_dives(struct git_info *info, bool select_only) extern "C" int git_save_dives(struct git_info *info, bool select_only)
{ {
/* /*
* First, just try to open the local git repo without * First, just try to open the local git repo without