forked from qt-creator/qt-creator
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:
@@ -78,7 +78,7 @@ BranchView::BranchView()
|
||||
, m_refreshAction(new QAction(this))
|
||||
, m_repositoryLabel(new ElidingLabel(this))
|
||||
, m_branchView(new NavigationTreeView(this))
|
||||
, m_model(new BranchModel(GitClient::instance(), this))
|
||||
, m_model(new BranchModel(this))
|
||||
, m_filterModel(new BranchFilterModel(this))
|
||||
{
|
||||
m_addAction->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
|
||||
@@ -237,12 +237,12 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
|
||||
const std::optional<QString> remote = m_model->remoteName(index);
|
||||
if (remote.has_value()) {
|
||||
contextMenu.addAction(Tr::tr("&Fetch"), this, [this, &remote] {
|
||||
GitClient::instance()->fetch(m_repository, *remote);
|
||||
gitClient().fetch(m_repository, *remote);
|
||||
});
|
||||
contextMenu.addSeparator();
|
||||
if (!remote->isEmpty()) {
|
||||
contextMenu.addAction(Tr::tr("Remove &Stale Branches"), this, [this, &remote] {
|
||||
GitClient::instance()->removeStaleRemoteBranches(m_repository, *remote);
|
||||
gitClient().removeStaleRemoteBranches(m_repository, *remote);
|
||||
});
|
||||
contextMenu.addSeparator();
|
||||
}
|
||||
@@ -261,7 +261,7 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
|
||||
contextMenu.addAction(Tr::tr("&Diff"), this, [this] {
|
||||
const QString fullName = m_model->fullName(selectedIndex(), true);
|
||||
if (!fullName.isEmpty())
|
||||
GitClient::instance()->diffBranch(m_repository, fullName);
|
||||
gitClient().diffBranch(m_repository, fullName);
|
||||
});
|
||||
contextMenu.addAction(Tr::tr("&Log"), this, [this] { log(selectedIndex()); });
|
||||
contextMenu.addAction(Tr::tr("Reflo&g"), this, [this] { reflog(selectedIndex()); });
|
||||
@@ -394,13 +394,12 @@ bool BranchView::checkout()
|
||||
' ' + nextBranch + "-AutoStash ";
|
||||
|
||||
BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch);
|
||||
GitClient *client = GitClient::instance();
|
||||
|
||||
if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
|
||||
if (gitClient().gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
|
||||
branchCheckoutDialog.foundNoLocalChanges();
|
||||
|
||||
QList<Stash> stashes;
|
||||
client->synchronousStashList(m_repository, &stashes);
|
||||
gitClient().synchronousStashList(m_repository, &stashes);
|
||||
for (const Stash &stash : std::as_const(stashes)) {
|
||||
if (stash.message.startsWith(popMessageStart)) {
|
||||
branchCheckoutDialog.foundStashForNextBranch();
|
||||
@@ -415,13 +414,13 @@ bool BranchView::checkout()
|
||||
} else if (branchCheckoutDialog.exec() == QDialog::Accepted) {
|
||||
|
||||
if (branchCheckoutDialog.makeStashOfCurrentBranch()) {
|
||||
if (client->synchronousStash(m_repository, currentBranch + "-AutoStash").isEmpty())
|
||||
if (gitClient().synchronousStash(m_repository, currentBranch + "-AutoStash").isEmpty())
|
||||
return false;
|
||||
} else if (branchCheckoutDialog.moveLocalChangesToNextBranch()) {
|
||||
if (!client->beginStashScope(m_repository, "Checkout", NoPrompt))
|
||||
if (!gitClient().beginStashScope(m_repository, "Checkout", NoPrompt))
|
||||
return false;
|
||||
} else if (branchCheckoutDialog.discardLocalChanges()) {
|
||||
if (!client->synchronousReset(m_repository))
|
||||
if (!gitClient().synchronousReset(m_repository))
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -429,18 +428,18 @@ bool BranchView::checkout()
|
||||
const bool popStash = branchCheckoutDialog.popStashOfNextBranch();
|
||||
const auto commandHandler = [=](const CommandResult &) {
|
||||
if (moveChanges) {
|
||||
client->endStashScope(m_repository);
|
||||
gitClient().endStashScope(m_repository);
|
||||
} else if (popStash) {
|
||||
QList<Stash> stashes;
|
||||
QString stashName;
|
||||
client->synchronousStashList(m_repository, &stashes);
|
||||
gitClient().synchronousStashList(m_repository, &stashes);
|
||||
for (const Stash &stash : std::as_const(stashes)) {
|
||||
if (stash.message.startsWith(popMessageStart)) {
|
||||
stashName = stash.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
client->synchronousStashRestore(m_repository, stashName, true);
|
||||
gitClient().synchronousStashRestore(m_repository, stashName, true);
|
||||
}
|
||||
};
|
||||
m_model->checkoutBranch(selected, this, commandHandler);
|
||||
@@ -526,7 +525,7 @@ bool BranchView::reset(const QByteArray &resetType)
|
||||
if (QMessageBox::question(this, Tr::tr("Git Reset"), Tr::tr("Reset branch \"%1\" to \"%2\"?")
|
||||
.arg(currentName, branchName),
|
||||
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
|
||||
GitClient::instance()->reset(m_repository, QLatin1String("--" + resetType), branchName);
|
||||
gitClient().reset(m_repository, QLatin1String("--" + resetType), branchName);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -547,15 +546,14 @@ TaskTree *BranchView::onFastForwardMerge(const std::function<void()> &callback)
|
||||
|
||||
const TreeStorage<FastForwardStorage> storage;
|
||||
|
||||
GitClient *client = GitClient::instance();
|
||||
const auto setupMergeBase = [=](Process &process) {
|
||||
client->setupCommand(process, m_repository, {"merge-base", "HEAD", branch});
|
||||
gitClient().setupCommand(process, m_repository, {"merge-base", "HEAD", branch});
|
||||
};
|
||||
const auto onMergeBaseDone = [storage](const Process &process) {
|
||||
storage->mergeBase = process.cleanedStdOut().trimmed();
|
||||
};
|
||||
|
||||
const ProcessTask topRevisionProc = client->topRevision(
|
||||
const ProcessTask topRevisionProc = gitClient().topRevision(
|
||||
m_repository,
|
||||
[storage](const QString &revision, const QDateTime &) {
|
||||
storage->topRevision = revision;
|
||||
@@ -584,9 +582,8 @@ bool BranchView::merge(bool allowFastForward)
|
||||
QTC_CHECK(selected != m_model->currentBranch());
|
||||
|
||||
const QString branch = m_model->fullName(selected, true);
|
||||
GitClient *client = GitClient::instance();
|
||||
if (client->beginStashScope(m_repository, "merge", AllowUnstashed))
|
||||
return client->synchronousMerge(m_repository, branch, allowFastForward);
|
||||
if (gitClient().beginStashScope(m_repository, "merge", AllowUnstashed))
|
||||
return gitClient().synchronousMerge(m_repository, branch, allowFastForward);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -599,9 +596,8 @@ void BranchView::rebase()
|
||||
QTC_CHECK(selected != m_model->currentBranch());
|
||||
|
||||
const QString baseBranch = m_model->fullName(selected, true);
|
||||
GitClient *client = GitClient::instance();
|
||||
if (client->beginStashScope(m_repository, "rebase"))
|
||||
client->rebase(m_repository, baseBranch);
|
||||
if (gitClient().beginStashScope(m_repository, "rebase"))
|
||||
gitClient().rebase(m_repository, baseBranch);
|
||||
}
|
||||
|
||||
bool BranchView::cherryPick()
|
||||
@@ -612,7 +608,7 @@ bool BranchView::cherryPick()
|
||||
QTC_CHECK(selected != m_model->currentBranch());
|
||||
|
||||
const QString branch = m_model->fullName(selected, true);
|
||||
return GitClient::instance()->synchronousCherryPick(m_repository, branch);
|
||||
return gitClient().synchronousCherryPick(m_repository, branch);
|
||||
}
|
||||
|
||||
void BranchView::log(const QModelIndex &idx)
|
||||
@@ -621,7 +617,7 @@ void BranchView::log(const QModelIndex &idx)
|
||||
if (branchName.isEmpty())
|
||||
return;
|
||||
SetInContext block(m_blockRefresh);
|
||||
GitClient::instance()->log(m_repository, QString(), false, {branchName});
|
||||
gitClient().log(m_repository, QString(), false, {branchName});
|
||||
}
|
||||
|
||||
void BranchView::reflog(const QModelIndex &idx)
|
||||
@@ -630,7 +626,7 @@ void BranchView::reflog(const QModelIndex &idx)
|
||||
if (branchName.isEmpty())
|
||||
return;
|
||||
SetInContext block(m_blockRefresh);
|
||||
GitClient::instance()->reflog(m_repository, branchName);
|
||||
gitClient().reflog(m_repository, branchName);
|
||||
}
|
||||
|
||||
void BranchView::push()
|
||||
@@ -646,7 +642,7 @@ void BranchView::push()
|
||||
const QString remoteBranch = fullTargetName.mid(pos + 1);
|
||||
const QStringList pushArgs = {remoteName, localBranch + ':' + remoteBranch};
|
||||
|
||||
GitClient::instance()->push(m_repository, pushArgs);
|
||||
gitClient().push(m_repository, pushArgs);
|
||||
}
|
||||
|
||||
BranchViewFactory::BranchViewFactory()
|
||||
|
||||
Reference in New Issue
Block a user