load-git: fix up any corrupted modechange event names

Because of the multiple string confusion, we'd get the names wrong for
modechange events.  If we then made other changes to the dive and saved
the end result back, they'd now be wrong in the git cloud storage too.

Fix it up manually by just noticing that there's a 'divemode' string on
the event line, which can only happen with modechange events.

Maybe we should report the fixup? This just silently fixes it (but only
for the git save format).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2020-02-14 12:08:43 -08:00 committed by Robert C. Helling
parent a9112e6e05
commit 66a2b2e133

View file

@ -761,6 +761,7 @@ static int get_divemode(const char *divemodestring) {
struct parse_event {
const char *name;
struct event ev;
int has_divemode;
};
static void parse_event_keyvalue(void *_parse, const char *key, const char *value)
@ -778,6 +779,7 @@ static void parse_event_keyvalue(void *_parse, const char *key, const char *valu
parse->name = value;
} else if (!strcmp(key,"divemode")) {
parse->ev.value = get_divemode(value);
parse->has_divemode = 1;
} else if (!strcmp(key, "cylinder")) {
/* NOTE! We add one here as a marker that "yes, we got a cylinder index" */
parse->ev.gas.index = 1 + get_index(value);
@ -834,6 +836,10 @@ static void parse_dc_event(char *line, struct membuffer *str, struct git_parser_
line = parse_keyvalue_entry(parse_event_keyvalue, &p, line, str);
}
/* Only modechange events should have a divemode - fix up any corrupted names */
if (p.has_divemode && strcmp(p.name, "modechange"))
p.name = "modechange";
ev = add_event(state->active_dc, p.ev.time.seconds, p.ev.type, p.ev.flags, p.ev.value, p.name);
/*