mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
git access: move git repo open from update_local_repo() to caller
We currently only have one single caller of update_local_repo(), and instead of that caller checking whether the existing repo is a directory, just make it open the git repository. This avoids duplicate error handling and simplifies the code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
ac70282193
commit
6f5783b203
1 changed files with 11 additions and 17 deletions
|
@ -755,23 +755,8 @@ int sync_with_remote(struct git_info *info)
|
||||||
|
|
||||||
static bool update_local_repo(struct git_info *info)
|
static bool update_local_repo(struct git_info *info)
|
||||||
{
|
{
|
||||||
int error;
|
|
||||||
git_reference *head;
|
git_reference *head;
|
||||||
|
|
||||||
if (verbose)
|
|
||||||
SSRF_INFO("git storage: update local repo\n");
|
|
||||||
|
|
||||||
error = git_repository_open(&info->repo, info->localdir);
|
|
||||||
if (error) {
|
|
||||||
const char *msg = giterr_last()->message;
|
|
||||||
SSRF_INFO("git storage: unable to open local cache at %s: %s", info->localdir, msg);
|
|
||||||
if (info->is_subsurface_cloud)
|
|
||||||
(void)cleanup_local_cache(info);
|
|
||||||
else
|
|
||||||
report_error("Unable to open git cache repository at %s: %s", info->localdir, msg);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check the HEAD being the right branch */
|
/* Check the HEAD being the right branch */
|
||||||
if (!git_repository_head(&head, info->repo)) {
|
if (!git_repository_head(&head, info->repo)) {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -942,13 +927,22 @@ static bool get_remote_repo(struct git_info *info)
|
||||||
git_storage_update_progress(translate("gettextFromC", "Synchronising data file"));
|
git_storage_update_progress(translate("gettextFromC", "Synchronising data file"));
|
||||||
/* Do we already have a local cache? */
|
/* Do we already have a local cache? */
|
||||||
if (!subsurface_stat(info->localdir, &st)) {
|
if (!subsurface_stat(info->localdir, &st)) {
|
||||||
if (!S_ISDIR(st.st_mode)) {
|
int error;
|
||||||
|
|
||||||
|
if (verbose)
|
||||||
|
SSRF_INFO("git storage: update local repo\n");
|
||||||
|
|
||||||
|
error = git_repository_open(&info->repo, info->localdir);
|
||||||
|
if (error) {
|
||||||
|
const char *msg = giterr_last()->message;
|
||||||
|
SSRF_INFO("git storage: unable to open local cache at %s: %s", info->localdir, msg);
|
||||||
if (info->is_subsurface_cloud)
|
if (info->is_subsurface_cloud)
|
||||||
(void)cleanup_local_cache(info);
|
(void)cleanup_local_cache(info);
|
||||||
else
|
else
|
||||||
report_error("local git cache at '%s' is corrupt", info->localdir);
|
report_error("Unable to open git cache repository at %s: %s", info->localdir, msg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return update_local_repo(info);
|
return update_local_repo(info);
|
||||||
} else {
|
} else {
|
||||||
/* We have no local cache yet.
|
/* We have no local cache yet.
|
||||||
|
|
Loading…
Add table
Reference in a new issue