git access: save to local repository before doing remote access

.. at least if the local repository exists and can be opened.

If the local repo cannot be directly opened, we will still try to sync
with the remote first, but this way the *common* git save situation is
that we save locally before we then try to sync with the remote.

That means that if we have network problems, the save will happen before
we possibly hang due to really really slow networking.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds 2022-04-18 14:51:14 -07:00 committed by Dirk Hohndel
parent e33680c336
commit dee13bf410

View file

@ -1363,29 +1363,33 @@ int do_git_save(struct git_info *info, bool select_only, bool create_empty)
int git_save_dives(struct git_info *info, bool select_only) int git_save_dives(struct git_info *info, bool select_only)
{ {
/* /*
* FIXME!! This open_git_repository() will * First, just try to open the local git repo without
* sync with the cloud. That is NOT what * doing any remote updates at all. If networking is
* we actually want to do here. We want * reliable, the remote has been updated at open time,
* to just open the local repo, and then * and we want to update *after* saving.
* sync with the clound after having saved.
* *
* NOTE! The "we already have a repo" case * And if networking isn't reliable, we want to save
* case is fairly easy (we can just treat * first anyway.
* it as a local repository and open it
* as-is). But the "need to create it by
* cloning" case is what we currently also
* do in 'open_git_repository()', and that
* all needs to be thought about a lot.
* *
* Do we want to have the rule that you * Note that 'do_git_save()' will try to sync with the
* can't save to a git repo unless you first * remote after saving (see sync_with_remote()), so we
* opened it for reading, and make all that * will be doing the remote access at that point, but
* complexity be a load-time thing? That * at least the local state will be saved early in
* would make the saving rules be very clear * case something goes wrong.
* and simple. */
if (!git_repository_open(&info->repo, info->localdir))
return do_git_save(info, select_only, false);
/*
* Ok, so there was something wrong with the local
* repo (possibly it's just missing entirely). That
* means we don't want to just save to it, we'll
* need to try to load the remote state first.
*
* This shouldn't be the common case.
*/ */
if (!open_git_repository(info)) if (!open_git_repository(info))
report_error(translate("gettextFromC", "Failed to save dives to %s[%s] (%s)"), info->url, info->branch, strerror(errno)); return report_error(translate("gettextFromC", "Failed to save dives to %s[%s] (%s)"), info->url, info->branch, strerror(errno));
return do_git_save(info, select_only, false); return do_git_save(info, select_only, false);
} }