Git: Initialize GitClient on first access

This does not change the current timing of construction a lot as
the GerritPlugin may need it immediately in some cases, in any
case the gitGrep instance will need it.

There's nothing big going on at destruction time, so the prolonged
lifetime until really close to the end does not hurt.

The reason here is that this way we will avoid cases like in change
5e5b90a9a1.

Change-Id: I326d83c1a3d21114322ac6cce8d9e9b782faacdc
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2023-07-25 16:09:50 +02:00
parent 8d5897b8eb
commit 778a1d75ba
24 changed files with 255 additions and 280 deletions

View File

@@ -246,13 +246,13 @@ void GitLabProjectSettingsWidget::updateUi()
}
const Utils::FilePath projectDirectory = m_projectSettings->project()->projectDirectory();
const auto *gitClient = Git::Internal::GitClient::instance();
const Utils::FilePath repository = gitClient
? gitClient->findRepositoryForDirectory(projectDirectory) : Utils::FilePath();
const Utils::FilePath repository =
Git::Internal::gitClient().findRepositoryForDirectory(projectDirectory);
m_hostCB->clear();
if (!repository.isEmpty()) {
const QMap<QString, QString> remotes = gitClient->synchronousRemotesList(repository);
const QMap<QString, QString> remotes =
Git::Internal::gitClient().synchronousRemotesList(repository);
for (auto it = remotes.begin(), end = remotes.end(); it != end; ++it) {
const QString display = it.key() + " (" + it.value() + ')';
m_hostCB->addItem(display, QVariant::fromValue(it.value()));
@@ -291,9 +291,8 @@ void GitLabProjectSettingsWidget::updateEnabledStates()
m_checkConnection->setEnabled(isGitRepository && hasGitLabServers);
if (!isGitRepository) {
const Utils::FilePath projectDirectory = m_projectSettings->project()->projectDirectory();
const auto *gitClient = Git::Internal::GitClient::instance();
const Utils::FilePath repository = gitClient
? gitClient->findRepositoryForDirectory(projectDirectory) : Utils::FilePath();
const Utils::FilePath repository =
Git::Internal::gitClient().findRepositoryForDirectory(projectDirectory);
if (repository.isEmpty())
m_infoLabel->setText(Tr::tr("Not a git repository."));
else