mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Collect and convert git repo data to 'struct git_info'
We have this nasty habit of randomly passing down all the different things that we use to look up the local and remote git repository, and the information associated with it. Start collecting the data into a 'struct git_info' instead, so that it is easier to manage, and easier and more logical to just look up different parts of the puzzle. This is a fairly mechanical conversion, but has moved all the basic information collection to the 'is_git_repository()' function. That function no longer actually opens the repository (so the 'dry_run' argument is gone, and instead a successful 'is_git_repository()' is followed by 'opn_git_repository()' if you actually want the old non-dry_run semantics. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
acc4dc57af
commit
7e632173e0
11 changed files with 365 additions and 349 deletions
54
core/file.c
54
core/file.c
|
|
@ -273,55 +273,45 @@ static int parse_file_buffer(const char *filename, struct memblock *mem, struct
|
|||
return parse_xml_buffer(filename, mem->buffer, mem->size, table, trips, sites, devices, filter_presets, NULL);
|
||||
}
|
||||
|
||||
int check_git_sha(const char *filename, struct git_repository **git_p, const char **branch_p)
|
||||
bool check_git_sha(const char *filename, struct git_info *info)
|
||||
{
|
||||
struct git_repository *git;
|
||||
const char *branch = NULL;
|
||||
|
||||
char *current_sha = copy_string(saved_git_id);
|
||||
git = is_git_repository(filename, &branch, NULL, false);
|
||||
if (git_p)
|
||||
*git_p = git;
|
||||
if (branch_p)
|
||||
*branch_p = branch;
|
||||
if (strstr(filename, prefs.cloud_base_url) && git == dummy_git_repository) {
|
||||
/* opening the cloud storage repository failed for some reason,
|
||||
* so we don't know if there is additional data in the remote */
|
||||
free(current_sha);
|
||||
return 1;
|
||||
}
|
||||
/* if this is a git repository, do we already have this exact state loaded ?
|
||||
* get the SHA and compare with what we currently have */
|
||||
if (git && git != dummy_git_repository) {
|
||||
const char *sha = get_sha(git, branch);
|
||||
if (!empty_string(sha) &&
|
||||
same_string(sha, current_sha)) {
|
||||
|
||||
if (is_git_repository(filename, info) && open_git_repository(info)) {
|
||||
const char *sha = get_sha(info->repo, info->branch);
|
||||
if (!empty_string(sha) && same_string(sha, current_sha)) {
|
||||
fprintf(stderr, "already have loaded SHA %s - don't load again\n", sha);
|
||||
free(current_sha);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Either the repository couldn't be opened, or the SHA couldn't
|
||||
// be found.
|
||||
free(current_sha);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
int parse_file(const char *filename, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites,
|
||||
struct device_table *devices, struct filter_preset_table *filter_presets)
|
||||
{
|
||||
struct git_repository *git;
|
||||
const char *branch = NULL;
|
||||
struct git_info info;
|
||||
struct memblock mem;
|
||||
char *fmt;
|
||||
int ret;
|
||||
|
||||
git = is_git_repository(filename, &branch, NULL, false);
|
||||
if (strstr(filename, prefs.cloud_base_url) && git == dummy_git_repository)
|
||||
/* opening the cloud storage repository failed for some reason
|
||||
* give up here and don't send errors about git repositories */
|
||||
return -1;
|
||||
if (is_git_repository(filename, &info)) {
|
||||
if (!open_git_repository(&info)) {
|
||||
/*
|
||||
* Opening the cloud storage repository failed for some reason
|
||||
* give up here and don't send errors about git repositories
|
||||
*/
|
||||
if (info.is_subsurface_cloud)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (git)
|
||||
return git_load_dives(git, branch, table, trips, sites, devices, filter_presets);
|
||||
return git_load_dives(&info, table, trips, sites, devices, filter_presets);
|
||||
}
|
||||
|
||||
if ((ret = readfile(filename, &mem)) < 0) {
|
||||
/* we don't want to display an error if this was the default file */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue