git: don't access global dive site table

When loading a git repository, dive sites where loaded into the
global dive site table, not the local table. Apparently, nobody
ever tried to import a git repository into an existing divelog
(as opposed to opening it in the application). Because that would
have probably given funky results.

Remove this access of a global variable.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-11-09 08:16:09 +01:00 committed by Dirk Hohndel
parent 2112bd8e08
commit 5525344594

View file

@ -177,7 +177,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, struct git_parser_
if (!ds) { if (!ds) {
ds = get_dive_site_by_gps(&location, state->sites); ds = get_dive_site_by_gps(&location, state->sites);
if (!ds) if (!ds)
ds = create_dive_site_with_gps("", &location, &dive_site_table); ds = create_dive_site_with_gps("", &location, state->sites);
add_dive_to_dive_site(state->active_dive, ds); add_dive_to_dive_site(state->active_dive, ds);
} else { } else {
if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) { if (dive_site_has_gps_location(ds) && !same_location(&ds->location, &location)) {
@ -197,9 +197,9 @@ static void parse_dive_location(char *line, struct membuffer *str, struct git_pa
char *name = detach_cstring(str); char *name = detach_cstring(str);
struct dive_site *ds = get_dive_site_for_dive(state->active_dive); struct dive_site *ds = get_dive_site_for_dive(state->active_dive);
if (!ds) { if (!ds) {
ds = get_dive_site_by_name(name, &dive_site_table); ds = get_dive_site_by_name(name, state->sites);
if (!ds) if (!ds)
ds = create_dive_site(name, &dive_site_table); ds = create_dive_site(name, state->sites);
add_dive_to_dive_site(state->active_dive, ds); add_dive_to_dive_site(state->active_dive, ds);
} else { } else {
// we already had a dive site linked to the dive // we already had a dive site linked to the dive
@ -227,7 +227,7 @@ static void parse_dive_notes(char *line, struct membuffer *str, struct git_parse
{ UNUSED(line); state->active_dive->notes = detach_cstring(str); } { UNUSED(line); state->active_dive->notes = detach_cstring(str); }
static void parse_dive_divesiteid(char *line, struct membuffer *str, struct git_parser_state *state) static void parse_dive_divesiteid(char *line, struct membuffer *str, struct git_parser_state *state)
{ UNUSED(str); add_dive_to_dive_site(state->active_dive, get_dive_site_by_uuid(get_hex(line), &dive_site_table)); } { UNUSED(str); add_dive_to_dive_site(state->active_dive, get_dive_site_by_uuid(get_hex(line), state->sites)); }
/* /*
* We can have multiple tags in the membuffer. They are separated by * We can have multiple tags in the membuffer. They are separated by
@ -1756,7 +1756,7 @@ static int parse_site_entry(struct git_parser_state *state, const git_tree_entry
if (*suffix == '\0') if (*suffix == '\0')
return report_error("Dive site without uuid"); return report_error("Dive site without uuid");
uint32_t uuid = strtoul(suffix, NULL, 16); uint32_t uuid = strtoul(suffix, NULL, 16);
state->active_site = alloc_or_get_dive_site(uuid, &dive_site_table); state->active_site = alloc_or_get_dive_site(uuid, state->sites);
git_blob *blob = git_tree_entry_blob(state->repo, entry); git_blob *blob = git_tree_entry_blob(state->repo, entry);
if (!blob) if (!blob)
return report_error("Unable to read dive site file"); return report_error("Unable to read dive site file");