mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
git: load into arbitrary dive tables
The git parser loads into the global dive table, even if it is called indirectly via parse_file(). However, parse_file() may be given a different table. Fix this by extending the git parser state. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
2042a47230
commit
ed3e68c36a
4 changed files with 13 additions and 7 deletions
|
@ -325,7 +325,7 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
}
|
||||
free(current_sha);
|
||||
if (git)
|
||||
return git_load_dives(git, branch);
|
||||
return git_load_dives(git, branch, table, trips, sites);
|
||||
|
||||
if ((ret = readfile(filename, &mem)) < 0) {
|
||||
/* we don't want to display an error if this was the default file */
|
||||
|
|
|
@ -19,7 +19,7 @@ extern struct git_repository *is_git_repository(const char *filename, const char
|
|||
extern int check_git_sha(const char *filename, git_repository **git_p, const char **branch_p);
|
||||
extern int sync_with_remote(struct git_repository *repo, const char *remote, const char *branch, enum remote_transport rt);
|
||||
extern int git_save_dives(struct git_repository *, const char *, const char *remote, bool select_only);
|
||||
extern int git_load_dives(struct git_repository *, const char *);
|
||||
extern int git_load_dives(struct git_repository *repo, const char *branch, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
extern const char *get_sha(git_repository *repo, const char *branch);
|
||||
extern int do_git_save(git_repository *repo, const char *branch, const char *remote, bool select_only, bool create_empty);
|
||||
extern const char *saved_git_id;
|
||||
|
|
|
@ -34,6 +34,9 @@ struct git_parser_state {
|
|||
dive_trip_t *active_trip;
|
||||
struct picture *active_pic;
|
||||
struct dive_site *active_site;
|
||||
struct dive_table *table;
|
||||
struct trip_table *trips;
|
||||
struct dive_site_table *sites;
|
||||
int o2pressure_sensor;
|
||||
};
|
||||
|
||||
|
@ -159,7 +162,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, struct git_parser_
|
|||
|
||||
parse_location(line, &location);
|
||||
if (!ds) {
|
||||
ds = get_dive_site_by_gps(&location, &dive_site_table);
|
||||
ds = get_dive_site_by_gps(&location, state->sites);
|
||||
if (!ds)
|
||||
ds = create_dive_site_with_gps("", &location, &dive_site_table);
|
||||
add_dive_to_dive_site(state->active_dive, ds);
|
||||
|
@ -1225,7 +1228,7 @@ static void finish_active_trip(struct git_parser_state *state)
|
|||
|
||||
if (trip) {
|
||||
state->active_trip = NULL;
|
||||
insert_trip(trip, &trip_table);
|
||||
insert_trip(trip, state->trips);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1235,7 +1238,7 @@ static void finish_active_dive(struct git_parser_state *state)
|
|||
|
||||
if (dive) {
|
||||
state->active_dive = NULL;
|
||||
record_dive(dive);
|
||||
record_dive_to_table(dive, state->table);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1729,11 +1732,14 @@ const char *get_sha(git_repository *repo, const char *branch)
|
|||
* If it is a git repository, we return zero for success,
|
||||
* or report an error and return 1 if the load failed.
|
||||
*/
|
||||
int git_load_dives(struct git_repository *repo, const char *branch)
|
||||
int git_load_dives(struct git_repository *repo, const char *branch, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
||||
{
|
||||
int ret;
|
||||
struct git_parser_state state = { 0 };
|
||||
state.repo = repo;
|
||||
state.table = table;
|
||||
state.trips = trips;
|
||||
state.sites = sites;
|
||||
|
||||
if (repo == dummy_git_repository)
|
||||
return report_error("Unable to open git repository at '%s'", branch);
|
||||
|
|
|
@ -693,7 +693,7 @@ void QMLManager::loadDivesWithValidCredentials()
|
|||
}
|
||||
if (git != dummy_git_repository) {
|
||||
appendTextToLog(QString("have repository and branch %1").arg(branch));
|
||||
error = git_load_dives(git, branch);
|
||||
error = git_load_dives(git, branch, &dive_table, &trip_table, &dive_site_table);
|
||||
} else {
|
||||
appendTextToLog(QString("didn't receive valid git repo, try again"));
|
||||
error = parse_file(fileNamePrt.data(), &dive_table, &trip_table, &dive_site_table);
|
||||
|
|
Loading…
Reference in a new issue