Git: Store singleton instance in GitClient

On many cases, GitPlugin is not required at all, and is only used as
a proxy for GitClient.

Change-Id: I246012658ab3e8c7a12f1a459b1b1748ff358e0b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Orgad Shaneh
2020-02-25 20:20:25 +02:00
committed by Orgad Shaneh
parent 5765bd8507
commit 7c4f0a9b1e
19 changed files with 123 additions and 118 deletions

View File

@@ -82,7 +82,7 @@ BranchView::BranchView() :
m_refreshButton(new QToolButton(this)), m_refreshButton(new QToolButton(this)),
m_repositoryLabel(new Utils::ElidingLabel(this)), m_repositoryLabel(new Utils::ElidingLabel(this)),
m_branchView(new Utils::NavigationTreeView(this)), m_branchView(new Utils::NavigationTreeView(this)),
m_model(new BranchModel(GitPlugin::client(), this)), m_model(new BranchModel(GitClient::instance(), this)),
m_filterModel(new BranchFilterModel(this)) m_filterModel(new BranchFilterModel(this))
{ {
m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon()); m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon());
@@ -122,7 +122,7 @@ BranchView::BranchView() :
this, &BranchView::setIncludeOldEntries); this, &BranchView::setIncludeOldEntries);
m_includeTagsAction->setCheckable(true); m_includeTagsAction->setCheckable(true);
m_includeTagsAction->setChecked( m_includeTagsAction->setChecked(
GitPlugin::client()->settings().boolValue(GitSettings::showTagsKey)); GitClient::instance()->settings().boolValue(GitSettings::showTagsKey));
connect(m_includeTagsAction, &QAction::toggled, connect(m_includeTagsAction, &QAction::toggled,
this, &BranchView::setIncludeTags); this, &BranchView::setIncludeTags);
@@ -214,12 +214,12 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
const Utils::optional<QString> remote = m_model->remoteName(index); const Utils::optional<QString> remote = m_model->remoteName(index);
if (remote.has_value()) { if (remote.has_value()) {
contextMenu.addAction(tr("&Fetch"), this, [this, &remote]() { contextMenu.addAction(tr("&Fetch"), this, [this, &remote]() {
GitPlugin::client()->fetch(m_repository, *remote); GitClient::instance()->fetch(m_repository, *remote);
}); });
contextMenu.addSeparator(); contextMenu.addSeparator();
if (!remote->isEmpty()) { if (!remote->isEmpty()) {
contextMenu.addAction(tr("Remove &Stale Branches"), this, [this, &remote]() { contextMenu.addAction(tr("Remove &Stale Branches"), this, [this, &remote]() {
GitPlugin::client()->removeStaleRemoteBranches(m_repository, *remote); GitClient::instance()->removeStaleRemoteBranches(m_repository, *remote);
}); });
contextMenu.addSeparator(); contextMenu.addSeparator();
} }
@@ -238,7 +238,7 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
contextMenu.addAction(tr("&Diff"), this, [this] { contextMenu.addAction(tr("&Diff"), this, [this] {
const QString fullName = m_model->fullName(selectedIndex(), true); const QString fullName = m_model->fullName(selectedIndex(), true);
if (!fullName.isEmpty()) if (!fullName.isEmpty())
GitPlugin::client()->diffBranch(m_repository, fullName); GitClient::instance()->diffBranch(m_repository, fullName);
}); });
contextMenu.addAction(tr("&Log"), this, [this] { log(selectedIndex()); }); contextMenu.addAction(tr("&Log"), this, [this] { log(selectedIndex()); });
contextMenu.addAction(tr("Reflo&g"), this, [this] { reflog(selectedIndex()); }); contextMenu.addAction(tr("Reflo&g"), this, [this] { reflog(selectedIndex()); });
@@ -289,7 +289,7 @@ void BranchView::setIncludeOldEntries(bool filter)
void BranchView::setIncludeTags(bool includeTags) void BranchView::setIncludeTags(bool includeTags)
{ {
GitPlugin::client()->settings().setValue(GitSettings::showTagsKey, includeTags); GitClient::instance()->settings().setValue(GitSettings::showTagsKey, includeTags);
refreshCurrentRepository(); refreshCurrentRepository();
} }
@@ -365,7 +365,7 @@ bool BranchView::checkout()
' ' + nextBranch + "-AutoStash "; ' ' + nextBranch + "-AutoStash ";
BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch); BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch);
GitClient *client = GitPlugin::client(); GitClient *client = GitClient::instance();
if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged) if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged)
branchCheckoutDialog.foundNoLocalChanges(); branchCheckoutDialog.foundNoLocalChanges();
@@ -500,7 +500,7 @@ bool BranchView::reset(const QByteArray &resetType)
if (QMessageBox::question(this, tr("Git Reset"), tr("Reset branch \"%1\" to \"%2\"?") if (QMessageBox::question(this, tr("Git Reset"), tr("Reset branch \"%1\" to \"%2\"?")
.arg(currentName).arg(branchName), .arg(currentName).arg(branchName),
QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) {
GitPlugin::client()->reset(m_repository, QLatin1String("--" + resetType), branchName); GitClient::instance()->reset(m_repository, QLatin1String("--" + resetType), branchName);
return true; return true;
} }
return false; return false;
@@ -512,7 +512,7 @@ bool BranchView::isFastForwardMerge()
QTC_CHECK(selected != m_model->currentBranch()); QTC_CHECK(selected != m_model->currentBranch());
const QString branch = m_model->fullName(selected, true); const QString branch = m_model->fullName(selected, true);
return GitPlugin::client()->isFastForwardMerge(m_repository, branch); return GitClient::instance()->isFastForwardMerge(m_repository, branch);
} }
bool BranchView::merge(bool allowFastForward) bool BranchView::merge(bool allowFastForward)
@@ -523,7 +523,7 @@ bool BranchView::merge(bool allowFastForward)
QTC_CHECK(selected != m_model->currentBranch()); QTC_CHECK(selected != m_model->currentBranch());
const QString branch = m_model->fullName(selected, true); const QString branch = m_model->fullName(selected, true);
GitClient *client = GitPlugin::client(); GitClient *client = GitClient::instance();
if (client->beginStashScope(m_repository, "merge", AllowUnstashed)) if (client->beginStashScope(m_repository, "merge", AllowUnstashed))
return client->synchronousMerge(m_repository, branch, allowFastForward); return client->synchronousMerge(m_repository, branch, allowFastForward);
@@ -538,7 +538,7 @@ void BranchView::rebase()
QTC_CHECK(selected != m_model->currentBranch()); QTC_CHECK(selected != m_model->currentBranch());
const QString baseBranch = m_model->fullName(selected, true); const QString baseBranch = m_model->fullName(selected, true);
GitClient *client = GitPlugin::client(); GitClient *client = GitClient::instance();
if (client->beginStashScope(m_repository, "rebase")) if (client->beginStashScope(m_repository, "rebase"))
client->rebase(m_repository, baseBranch); client->rebase(m_repository, baseBranch);
} }
@@ -551,21 +551,21 @@ bool BranchView::cherryPick()
QTC_CHECK(selected != m_model->currentBranch()); QTC_CHECK(selected != m_model->currentBranch());
const QString branch = m_model->fullName(selected, true); const QString branch = m_model->fullName(selected, true);
return GitPlugin::client()->synchronousCherryPick(m_repository, branch); return GitClient::instance()->synchronousCherryPick(m_repository, branch);
} }
void BranchView::log(const QModelIndex &idx) void BranchView::log(const QModelIndex &idx)
{ {
const QString branchName = m_model->fullName(idx, true); const QString branchName = m_model->fullName(idx, true);
if (!branchName.isEmpty()) if (!branchName.isEmpty())
GitPlugin::client()->log(m_repository, QString(), false, {branchName}); GitClient::instance()->log(m_repository, QString(), false, {branchName});
} }
void BranchView::reflog(const QModelIndex &idx) void BranchView::reflog(const QModelIndex &idx)
{ {
const QString branchName = m_model->fullName(idx, true); const QString branchName = m_model->fullName(idx, true);
if (!branchName.isEmpty()) if (!branchName.isEmpty())
GitPlugin::client()->reflog(m_repository, branchName); GitClient::instance()->reflog(m_repository, branchName);
} }
void BranchView::push() void BranchView::push()
@@ -581,7 +581,7 @@ void BranchView::push()
const QString remoteBranch = fullTargetName.mid(pos + 1); const QString remoteBranch = fullTargetName.mid(pos + 1);
const QStringList pushArgs = {remoteName, localBranch + ':' + remoteBranch}; const QStringList pushArgs = {remoteName, localBranch + ':' + remoteBranch};
GitPlugin::client()->push(m_repository, pushArgs); GitClient::instance()->push(m_repository, pushArgs);
} }
BranchViewFactory::BranchViewFactory() BranchViewFactory::BranchViewFactory()

View File

@@ -25,7 +25,6 @@
#include "changeselectiondialog.h" #include "changeselectiondialog.h"
#include "logchangedialog.h" #include "logchangedialog.h"
#include "gitplugin.h"
#include "gitclient.h" #include "gitclient.h"
#include "ui_changeselectiondialog.h" #include "ui_changeselectiondialog.h"
@@ -57,12 +56,12 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co
QWidget *parent) : QWidget *parent) :
QDialog(parent), m_ui(new Ui::ChangeSelectionDialog) QDialog(parent), m_ui(new Ui::ChangeSelectionDialog)
{ {
m_gitExecutable = GitPlugin::client()->vcsBinary(); m_gitExecutable = GitClient::instance()->vcsBinary();
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->workingDirectoryChooser->setExpectedKind(PathChooser::ExistingDirectory); m_ui->workingDirectoryChooser->setExpectedKind(PathChooser::ExistingDirectory);
m_ui->workingDirectoryChooser->setPromptDialogTitle(tr("Select Git Directory")); m_ui->workingDirectoryChooser->setPromptDialogTitle(tr("Select Git Directory"));
m_ui->workingDirectoryChooser->setPath(workingDirectory); m_ui->workingDirectoryChooser->setPath(workingDirectory);
m_gitEnvironment = GitPlugin::client()->processEnvironment(); m_gitEnvironment = GitClient::instance()->processEnvironment();
m_ui->changeNumberEdit->setFocus(); m_ui->changeNumberEdit->setFocus();
m_ui->changeNumberEdit->selectAll(); m_ui->changeNumberEdit->selectAll();
@@ -203,7 +202,7 @@ void ChangeSelectionDialog::recalculateCompletion()
if (workingDir.isEmpty()) if (workingDir.isEmpty())
return; return;
GitClient *client = GitPlugin::client(); GitClient *client = GitClient::instance();
VcsBase::VcsCommand *command = client->asyncForEachRefCmd( VcsBase::VcsCommand *command = client->asyncForEachRefCmd(
workingDir, {"--format=%(refname:short)"}); workingDir, {"--format=%(refname:short)"});
connect(this, &QObject::destroyed, command, &VcsBase::VcsCommand::abort); connect(this, &QObject::destroyed, command, &VcsBase::VcsCommand::abort);

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "branchcombobox.h" #include "branchcombobox.h"
#include "../gitplugin.h"
#include "../gitclient.h" #include "../gitclient.h"
using namespace Git::Internal; using namespace Git::Internal;
@@ -36,7 +35,7 @@ BranchComboBox::BranchComboBox(QWidget *parent) : QComboBox(parent)
void BranchComboBox::init(const QString &repository) void BranchComboBox::init(const QString &repository)
{ {
m_repository = repository; m_repository = repository;
QString currentBranch = GitPlugin::client()->synchronousCurrentLocalBranch(repository); QString currentBranch = GitClient::instance()->synchronousCurrentLocalBranch(repository);
if (currentBranch.isEmpty()) { if (currentBranch.isEmpty()) {
m_detached = true; m_detached = true;
currentBranch = "HEAD"; currentBranch = "HEAD";
@@ -44,7 +43,7 @@ void BranchComboBox::init(const QString &repository)
} }
QString output; QString output;
const QString branchPrefix("refs/heads/"); const QString branchPrefix("refs/heads/");
if (!GitPlugin::client()->synchronousForEachRefCmd( if (!GitClient::instance()->synchronousForEachRefCmd(
m_repository, {"--format=%(refname)", branchPrefix}, &output)) { m_repository, {"--format=%(refname)", branchPrefix}, &output)) {
return; return;
} }

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "gerritmodel.h" #include "gerritmodel.h"
#include "../gitplugin.h"
#include "../gitclient.h" #include "../gitclient.h"
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -295,7 +294,7 @@ QueryContext::QueryContext(const QString &query,
connect(&m_process, &QProcess::errorOccurred, this, &QueryContext::processError); connect(&m_process, &QProcess::errorOccurred, this, &QueryContext::processError);
connect(&m_watcher, &QFutureWatcherBase::canceled, this, &QueryContext::terminate); connect(&m_watcher, &QFutureWatcherBase::canceled, this, &QueryContext::terminate);
m_watcher.setFuture(m_progress.future()); m_watcher.setFuture(m_progress.future());
m_process.setProcessEnvironment(Git::Internal::GitPlugin::client()->processEnvironment()); m_process.setProcessEnvironment(Git::Internal::GitClient::instance()->processEnvironment());
m_progress.setProgressRange(0, 1); m_progress.setProgressRange(0, 1);
m_timer.setInterval(timeOutMS); m_timer.setInterval(timeOutMS);

View File

@@ -148,7 +148,7 @@ FetchContext::FetchContext(const QSharedPointer<GerritChange> &change,
connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &FetchContext::terminate); connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &FetchContext::terminate);
m_watcher.setFuture(m_progress.future()); m_watcher.setFuture(m_progress.future());
m_process.setWorkingDirectory(repository); m_process.setWorkingDirectory(repository);
m_process.setProcessEnvironment(GitPlugin::client()->processEnvironment()); m_process.setProcessEnvironment(GitClient::instance()->processEnvironment());
m_process.closeWriteChannel(); m_process.closeWriteChannel();
} }
@@ -240,7 +240,7 @@ void FetchContext::show()
{ {
const QString title = QString::number(m_change->number) + '/' const QString title = QString::number(m_change->number) + '/'
+ QString::number(m_change->currentPatchSet.patchSetNumber); + QString::number(m_change->currentPatchSet.patchSetNumber);
GitPlugin::client()->show(m_repository, "FETCH_HEAD", title); GitClient::instance()->show(m_repository, "FETCH_HEAD", title);
} }
void FetchContext::cherryPick() void FetchContext::cherryPick()
@@ -248,12 +248,12 @@ void FetchContext::cherryPick()
// Point user to errors. // Point user to errors.
VcsBase::VcsOutputWindow::instance()->popup(IOutputPane::ModeSwitch VcsBase::VcsOutputWindow::instance()->popup(IOutputPane::ModeSwitch
| IOutputPane::WithFocus); | IOutputPane::WithFocus);
GitPlugin::client()->synchronousCherryPick(m_repository, "FETCH_HEAD"); GitClient::instance()->synchronousCherryPick(m_repository, "FETCH_HEAD");
} }
void FetchContext::checkout() void FetchContext::checkout()
{ {
GitPlugin::client()->checkout(m_repository, "FETCH_HEAD"); GitClient::instance()->checkout(m_repository, "FETCH_HEAD");
} }
void FetchContext::terminate() void FetchContext::terminate()
@@ -328,7 +328,7 @@ void GerritPlugin::push(const QString &topLevel)
dialog.storeTopic(); dialog.storeTopic();
m_reviewers = dialog.reviewers(); m_reviewers = dialog.reviewers();
GitPlugin::client()->push(topLevel, {dialog.selectedRemoteName(), dialog.pushTarget()}); GitClient::instance()->push(topLevel, {dialog.selectedRemoteName(), dialog.pushTarget()});
} }
static QString currentRepository() static QString currentRepository()
@@ -375,19 +375,19 @@ void GerritPlugin::push()
Utils::FilePath GerritPlugin::gitBinDirectory() Utils::FilePath GerritPlugin::gitBinDirectory()
{ {
return GitPlugin::client()->gitBinDirectory(); return GitClient::instance()->gitBinDirectory();
} }
// Find the branch of a repository. // Find the branch of a repository.
QString GerritPlugin::branch(const QString &repository) QString GerritPlugin::branch(const QString &repository)
{ {
return GitPlugin::client()->synchronousCurrentLocalBranch(repository); return GitClient::instance()->synchronousCurrentLocalBranch(repository);
} }
void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
{ {
// Locate git. // Locate git.
const Utils::FilePath git = GitPlugin::client()->vcsBinary(); const Utils::FilePath git = GitClient::instance()->vcsBinary();
if (git.isEmpty()) { if (git.isEmpty()) {
VcsBase::VcsOutputWindow::appendError(tr("Git is not available.")); VcsBase::VcsOutputWindow::appendError(tr("Git is not available."));
return; return;
@@ -400,7 +400,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
if (!repository.isEmpty()) { if (!repository.isEmpty()) {
// Check if remote from a working dir is the same as remote from patch // Check if remote from a working dir is the same as remote from patch
QMap<QString, QString> remotesList = GitPlugin::client()->synchronousRemotesList(repository); QMap<QString, QString> remotesList = GitClient::instance()->synchronousRemotesList(repository);
if (!remotesList.isEmpty()) { if (!remotesList.isEmpty()) {
const QStringList remotes = remotesList.values(); const QStringList remotes = remotesList.values();
for (QString remote : remotes) { for (QString remote : remotes) {
@@ -413,7 +413,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
} }
if (!verifiedRepository) { if (!verifiedRepository) {
const SubmoduleDataMap submodules = GitPlugin::client()->submoduleList(repository); const SubmoduleDataMap submodules = GitClient::instance()->submoduleList(repository);
for (const SubmoduleData &submoduleData : submodules) { for (const SubmoduleData &submoduleData : submodules) {
QString remote = submoduleData.url; QString remote = submoduleData.url;
if (remote.endsWith(".git")) if (remote.endsWith(".git"))

View File

@@ -27,7 +27,6 @@
#include "ui_gerritpushdialog.h" #include "ui_gerritpushdialog.h"
#include "branchcombobox.h" #include "branchcombobox.h"
#include "../gitplugin.h"
#include "../gitclient.h" #include "../gitclient.h"
#include "../gitconstants.h" #include "../gitconstants.h"
@@ -70,7 +69,7 @@ QString GerritPushDialog::determineRemoteBranch(const QString &localBranch)
QString output; QString output;
QString error; QString error;
if (!GitPlugin::client()->synchronousBranchCmd( if (!GitClient::instance()->synchronousBranchCmd(
m_workingDir, {"-r", "--contains", earliestCommit + '^'}, &output, &error)) { m_workingDir, {"-r", "--contains", earliestCommit + '^'}, &output, &error)) {
return QString(); return QString();
} }
@@ -79,7 +78,7 @@ QString GerritPushDialog::determineRemoteBranch(const QString &localBranch)
QString remoteTrackingBranch; QString remoteTrackingBranch;
if (localBranch != "HEAD") if (localBranch != "HEAD")
remoteTrackingBranch = GitPlugin::client()->synchronousTrackingBranch(m_workingDir, localBranch); remoteTrackingBranch = GitClient::instance()->synchronousTrackingBranch(m_workingDir, localBranch);
QString remoteBranch; QString remoteBranch;
for (const QString &reference : refs) { for (const QString &reference : refs) {
@@ -103,7 +102,7 @@ void GerritPushDialog::initRemoteBranches()
const QString head = "/HEAD"; const QString head = "/HEAD";
QString remotesPrefix("refs/remotes/"); QString remotesPrefix("refs/remotes/");
if (!GitPlugin::client()->synchronousForEachRefCmd( if (!GitClient::instance()->synchronousForEachRefCmd(
m_workingDir, {"--format=%(refname)\t%(committerdate:raw)", remotesPrefix}, &output)) { m_workingDir, {"--format=%(refname)\t%(committerdate:raw)", remotesPrefix}, &output)) {
return; return;
} }
@@ -186,8 +185,8 @@ QString GerritPushDialog::calculateChangeRange(const QString &branch)
QString number; QString number;
QString error; QString error;
GitPlugin::client()->synchronousRevListCmd(m_workingDir, { remote + ".." + branch, "--count" }, GitClient::instance()->synchronousRevListCmd(
&number, &error); m_workingDir, { remote + ".." + branch, "--count" }, &number, &error);
number.chop(1); number.chop(1);
return number; return number;
@@ -303,8 +302,8 @@ QString GerritPushDialog::pushTarget() const
void GerritPushDialog::storeTopic() void GerritPushDialog::storeTopic()
{ {
const QString branch = m_ui->localBranchComboBox->currentText(); const QString branch = m_ui->localBranchComboBox->currentText();
GitPlugin::client()->setConfigValue(m_workingDir, QString("branch.%1.topic").arg(branch), GitClient::instance()->setConfigValue(
selectedTopic()); m_workingDir, QString("branch.%1.topic").arg(branch), selectedTopic());
} }
void GerritPushDialog::setRemoteBranches(bool includeOld) void GerritPushDialog::setRemoteBranches(bool includeOld)
@@ -316,7 +315,7 @@ void GerritPushDialog::setRemoteBranches(bool includeOld)
const QString remoteName = selectedRemoteName(); const QString remoteName = selectedRemoteName();
if (!m_remoteBranches.contains(remoteName)) { if (!m_remoteBranches.contains(remoteName)) {
const QStringList remoteBranches = const QStringList remoteBranches =
GitPlugin::client()->synchronousRepositoryBranches(remoteName, m_workingDir); GitClient::instance()->synchronousRepositoryBranches(remoteName, m_workingDir);
for (const QString &branch : remoteBranches) for (const QString &branch : remoteBranches)
m_remoteBranches.insertMulti(remoteName, qMakePair(branch, QDate())); m_remoteBranches.insertMulti(remoteName, qMakePair(branch, QDate()));
if (remoteBranches.isEmpty()) { if (remoteBranches.isEmpty()) {
@@ -354,7 +353,7 @@ void GerritPushDialog::updateCommits(int index)
{ {
const QString branch = m_ui->localBranchComboBox->itemText(index); const QString branch = m_ui->localBranchComboBox->itemText(index);
m_hasLocalCommits = m_ui->commitView->init(m_workingDir, branch, LogChangeWidget::Silent); m_hasLocalCommits = m_ui->commitView->init(m_workingDir, branch, LogChangeWidget::Silent);
QString topic = GitPlugin::client()->readConfigValue( QString topic = GitClient::instance()->readConfigValue(
m_workingDir, QString("branch.%1.topic").arg(branch)); m_workingDir, QString("branch.%1.topic").arg(branch));
if (!topic.isEmpty()) if (!topic.isEmpty())
m_ui->topicLineEdit->setText(topic); m_ui->topicLineEdit->setText(topic);

View File

@@ -27,7 +27,6 @@
#include "gerritparameters.h" #include "gerritparameters.h"
#include "gerritserver.h" #include "gerritserver.h"
#include "../gitclient.h" #include "../gitclient.h"
#include "../gitplugin.h"
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
@@ -104,7 +103,7 @@ bool GerritRemoteChooser::updateRemotes(bool forceReload)
m_remotes.clear(); m_remotes.clear();
QString errorMessage; // Mute errors. We'll just fallback to the defaults QString errorMessage; // Mute errors. We'll just fallback to the defaults
const QMap<QString, QString> remotesList = const QMap<QString, QString> remotesList =
Git::Internal::GitPlugin::client()->synchronousRemotesList(m_repository, &errorMessage); Git::Internal::GitClient::instance()->synchronousRemotesList(m_repository, &errorMessage);
for (auto mapIt = remotesList.cbegin(), end = remotesList.cend(); mapIt != end; ++mapIt) { for (auto mapIt = remotesList.cbegin(), end = remotesList.cend(); mapIt != end; ++mapIt) {
GerritServer server; GerritServer server;
if (!server.fillFromRemote(mapIt.value(), *m_parameters, forceReload)) if (!server.fillFromRemote(mapIt.value(), *m_parameters, forceReload))

View File

@@ -241,7 +241,7 @@ QStringList GerritServer::curlArguments() const
int GerritServer::testConnection() int GerritServer::testConnection()
{ {
static GitClient *const client = GitPlugin::client(); static GitClient *const client = GitClient::instance();
const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC); const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
const SynchronousProcessResponse resp = client->vcsFullySynchronousExec( const SynchronousProcessResponse resp = client->vcsFullySynchronousExec(
QString(), {curlBinary, arguments}, QString(), {curlBinary, arguments},
@@ -333,7 +333,7 @@ bool GerritServer::resolveRoot()
void GerritServer::resolveVersion(const GerritParameters &p, bool forceReload) void GerritServer::resolveVersion(const GerritParameters &p, bool forceReload)
{ {
static GitClient *const client = GitPlugin::client(); static GitClient *const client = GitClient::instance();
QSettings *settings = Core::ICore::settings(); QSettings *settings = Core::ICore::settings();
const QString fullVersionKey = "Gerrit/" + host + '/' + versionKey; const QString fullVersionKey = "Gerrit/" + host + '/' + versionKey;
version = settings->value(fullVersionKey).toString(); version = settings->value(fullVersionKey).toString();

View File

@@ -106,6 +106,8 @@ using namespace VcsBase;
namespace Git { namespace Git {
namespace Internal { namespace Internal {
static GitClient *m_instance = nullptr;
// Suppress git diff warnings about "LF will be replaced by CRLF..." on Windows. // Suppress git diff warnings about "LF will be replaced by CRLF..." on Windows.
static unsigned diffExecutionFlags() static unsigned diffExecutionFlags()
{ {
@@ -300,7 +302,7 @@ void GitDiffEditorController::updateBranchList()
return; return;
const QString workingDirectory = baseDirectory(); const QString workingDirectory = baseDirectory();
VcsCommand *command = GitPlugin::client()->vcsExec( VcsCommand *command = m_instance->vcsExec(
workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr, workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr,
false, 0, workingDirectory); false, 0, workingDirectory);
connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) { connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) {
@@ -375,7 +377,7 @@ QStringList GitDiffEditorController::addHeadWhenCommandInProgress() const
// This is workaround for lack of support for merge commits and resolving conflicts, // This is workaround for lack of support for merge commits and resolving conflicts,
// we compare the current state of working tree to the HEAD of current branch // we compare the current state of working tree to the HEAD of current branch
// instead of showing unsupported combined diff format. // instead of showing unsupported combined diff format.
GitClient::CommandInProgress commandInProgress = GitPlugin::client()->checkCommandInProgress(workingDirectory()); GitClient::CommandInProgress commandInProgress = m_instance->checkCommandInProgress(workingDirectory());
if (commandInProgress != GitClient::NoCommand) if (commandInProgress != GitClient::NoCommand)
return {HEAD}; return {HEAD};
return QStringList(); return QStringList();
@@ -478,7 +480,7 @@ public:
setReloader([this] { setReloader([this] {
m_state = GettingDescription; m_state = GettingDescription;
const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id}; const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id};
runCommand({args}, GitPlugin::client()->encoding(workingDirectory(), "i18n.commitEncoding")); runCommand({args}, m_instance->encoding(workingDirectory(), "i18n.commitEncoding"));
setStartupFile(VcsBase::source(this->document())); setStartupFile(VcsBase::source(this->document()));
}); });
} }
@@ -495,7 +497,7 @@ void ShowController::processCommandOutput(const QString &output)
{ {
QTC_ASSERT(m_state != Idle, return); QTC_ASSERT(m_state != Idle, return);
if (m_state == GettingDescription) { if (m_state == GettingDescription) {
setDescription(GitPlugin::client()->extendedShowDescription(workingDirectory(), output)); setDescription(m_instance->extendedShowDescription(workingDirectory(), output));
// stage 2 // stage 2
m_state = GettingDiff; m_state = GettingDiff;
const QStringList args = {"show", "--format=format:", // omit header, already generated const QStringList args = {"show", "--format=format:", // omit header, already generated
@@ -669,12 +671,11 @@ private:
{ {
// If interactive rebase editor window is closed, plugin is terminated // If interactive rebase editor window is closed, plugin is terminated
// but referenced here when the command ends // but referenced here when the command ends
GitClient *client = GitPlugin::client();
if (m_commit.isEmpty() && m_files.isEmpty()) { if (m_commit.isEmpty() && m_files.isEmpty()) {
if (client->checkCommandInProgress(m_workingDirectory) == GitClient::NoCommand) if (m_instance->checkCommandInProgress(m_workingDirectory) == GitClient::NoCommand)
client->endStashScope(m_workingDirectory); m_instance->endStashScope(m_workingDirectory);
} else { } else {
client->handleMergeConflicts(m_workingDirectory, m_commit, m_files, m_abortCommand); m_instance->handleMergeConflicts(m_workingDirectory, m_commit, m_files, m_abortCommand);
} }
} }
@@ -763,11 +764,17 @@ GitClient::GitClient(GitSettings *settings) : VcsBase::VcsBaseClientImpl(setting
m_cachedGitVersion(0), m_cachedGitVersion(0),
m_disableEditor(false) m_disableEditor(false)
{ {
m_instance = this;
m_gitQtcEditor = QString::fromLatin1("\"%1\" -client -block -pid %2") m_gitQtcEditor = QString::fromLatin1("\"%1\" -client -block -pid %2")
.arg(QCoreApplication::applicationFilePath()) .arg(QCoreApplication::applicationFilePath())
.arg(QCoreApplication::applicationPid()); .arg(QCoreApplication::applicationPid());
} }
GitClient *GitClient::instance()
{
return m_instance;
}
QString GitClient::findRepositoryForDirectory(const QString &directory) const QString GitClient::findRepositoryForDirectory(const QString &directory) const
{ {
if (directory.isEmpty() || directory.endsWith("/.git") || directory.contains("/.git/")) if (directory.isEmpty() || directory.endsWith("/.git") || directory.contains("/.git/"))
@@ -3476,7 +3483,7 @@ bool GitClient::StashInfo::init(const QString &workingDirectory, const QString &
m_pushAction = pushAction; m_pushAction = pushAction;
QString errorMessage; QString errorMessage;
QString statusOutput; QString statusOutput;
switch (GitPlugin::client()->gitStatus(m_workingDir, StatusMode(NoUntracked | NoSubmodules), switch (m_instance->gitStatus(m_workingDir, StatusMode(NoUntracked | NoSubmodules),
&statusOutput, &errorMessage)) { &statusOutput, &errorMessage)) {
case GitClient::StatusChanged: case GitClient::StatusChanged:
if (m_flags & NoPrompt) if (m_flags & NoPrompt)
@@ -3529,14 +3536,14 @@ void GitClient::StashInfo::stashPrompt(const QString &command, const QString &st
msgBox.exec(); msgBox.exec();
if (msgBox.clickedButton() == discardButton) { if (msgBox.clickedButton() == discardButton) {
m_stashResult = GitPlugin::client()->synchronousReset(m_workingDir, QStringList(), errorMessage) ? m_stashResult = m_instance->synchronousReset(m_workingDir, QStringList(), errorMessage) ?
StashUnchanged : StashFailed; StashUnchanged : StashFailed;
} else if (msgBox.clickedButton() == ignoreButton) { // At your own risk, so. } else if (msgBox.clickedButton() == ignoreButton) { // At your own risk, so.
m_stashResult = NotStashed; m_stashResult = NotStashed;
} else if (msgBox.clickedButton() == cancelButton) { } else if (msgBox.clickedButton() == cancelButton) {
m_stashResult = StashCanceled; m_stashResult = StashCanceled;
} else if (msgBox.clickedButton() == stashButton) { } else if (msgBox.clickedButton() == stashButton) {
const bool result = GitPlugin::client()->executeSynchronousStash( const bool result = m_instance->executeSynchronousStash(
m_workingDir, creatorStashMessage(command), false, errorMessage); m_workingDir, creatorStashMessage(command), false, errorMessage);
m_stashResult = result ? StashUnchanged : StashFailed; m_stashResult = result ? StashUnchanged : StashFailed;
} else if (msgBox.clickedButton() == stashAndPopButton) { } else if (msgBox.clickedButton() == stashAndPopButton) {
@@ -3547,7 +3554,7 @@ void GitClient::StashInfo::stashPrompt(const QString &command, const QString &st
void GitClient::StashInfo::executeStash(const QString &command, QString *errorMessage) void GitClient::StashInfo::executeStash(const QString &command, QString *errorMessage)
{ {
m_message = creatorStashMessage(command); m_message = creatorStashMessage(command);
if (!GitPlugin::client()->executeSynchronousStash(m_workingDir, m_message, false, errorMessage)) if (!m_instance->executeSynchronousStash(m_workingDir, m_message, false, errorMessage))
m_stashResult = StashFailed; m_stashResult = StashFailed;
else else
m_stashResult = Stashed; m_stashResult = Stashed;
@@ -3570,12 +3577,12 @@ void GitClient::StashInfo::end()
{ {
if (m_stashResult == Stashed) { if (m_stashResult == Stashed) {
QString stashName; QString stashName;
if (GitPlugin::client()->stashNameFromMessage(m_workingDir, m_message, &stashName)) if (m_instance->stashNameFromMessage(m_workingDir, m_message, &stashName))
GitPlugin::client()->stashPop(m_workingDir, stashName); m_instance->stashPop(m_workingDir, stashName);
} }
if (m_pushAction == NormalPush) if (m_pushAction == NormalPush)
GitPlugin::client()->push(m_workingDir); m_instance->push(m_workingDir);
else if (m_pushAction == PushToGerrit) else if (m_pushAction == PushToGerrit)
GitPlugin::gerritPush(m_workingDir); GitPlugin::gerritPush(m_workingDir);

View File

@@ -139,6 +139,7 @@ public:
}; };
explicit GitClient(GitSettings *settings); explicit GitClient(GitSettings *settings);
static GitClient *instance();
Utils::FilePath vcsBinary() const override; Utils::FilePath vcsBinary() const override;
unsigned gitVersion(QString *errorMessage = nullptr) const; unsigned gitVersion(QString *errorMessage = nullptr) const;

View File

@@ -152,7 +152,7 @@ static QString sanitizeBlameOutput(const QString &b)
if (b.isEmpty()) if (b.isEmpty())
return b; return b;
const bool omitDate = GitPlugin::client()->settings().boolValue( const bool omitDate = GitClient::instance()->settings().boolValue(
GitSettings::omitAnnotationDateKey); GitSettings::omitAnnotationDateKey);
const QChar space(' '); const QChar space(' ');
const int parenPos = b.indexOf(')'); const int parenPos = b.indexOf(')');
@@ -231,7 +231,7 @@ void GitEditorWidget::applyDiffChunk(const DiffChunk& chunk, bool revert)
if (revert) if (revert)
args << "--reverse"; args << "--reverse";
QString errorMessage; QString errorMessage;
if (GitPlugin::client()->synchronousApplyPatch(baseDir, patchFile.fileName(), &errorMessage, args)) { if (GitClient::instance()->synchronousApplyPatch(baseDir, patchFile.fileName(), &errorMessage, args)) {
if (errorMessage.isEmpty()) if (errorMessage.isEmpty())
VcsOutputWindow::append(tr("Chunk successfully staged")); VcsOutputWindow::append(tr("Chunk successfully staged"));
else else
@@ -280,14 +280,14 @@ void GitEditorWidget::aboutToOpen(const QString &fileName, const QString &realFi
const QString gitPath = fi.absolutePath(); const QString gitPath = fi.absolutePath();
setSource(gitPath); setSource(gitPath);
textDocument()->setCodec( textDocument()->setCodec(
GitPlugin::client()->encoding(gitPath, "i18n.commitEncoding")); GitClient::instance()->encoding(gitPath, "i18n.commitEncoding"));
} }
} }
QString GitEditorWidget::decorateVersion(const QString &revision) const QString GitEditorWidget::decorateVersion(const QString &revision) const
{ {
// Format verbose, SHA1 being first token // Format verbose, SHA1 being first token
return GitPlugin::client()->synchronousShortDescription(sourceWorkingDirectory(), revision); return GitClient::instance()->synchronousShortDescription(sourceWorkingDirectory(), revision);
} }
QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision) const QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision) const
@@ -295,8 +295,8 @@ QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision)
QStringList revisions; QStringList revisions;
QString errorMessage; QString errorMessage;
// Get the SHA1's of the file. // Get the SHA1's of the file.
if (!GitPlugin::client()->synchronousParentRevisions(sourceWorkingDirectory(), if (!GitClient::instance()->synchronousParentRevisions(
revision, &revisions, &errorMessage)) { sourceWorkingDirectory(), revision, &revisions, &errorMessage)) {
VcsOutputWindow::appendSilently(errorMessage); VcsOutputWindow::appendSilently(errorMessage);
return QStringList(); return QStringList();
} }
@@ -305,31 +305,31 @@ QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision)
bool GitEditorWidget::isValidRevision(const QString &revision) const bool GitEditorWidget::isValidRevision(const QString &revision) const
{ {
return GitPlugin::client()->isValidRevision(revision); return GitClient::instance()->isValidRevision(revision);
} }
void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change, const QString &workingDir) void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change, const QString &workingDir)
{ {
menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] { menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), [workingDir, change] {
GitPlugin::client()->synchronousCherryPick(workingDir, change); GitClient::instance()->synchronousCherryPick(workingDir, change);
}); });
menu->addAction(tr("Re&vert Change %1").arg(change), [workingDir, change] { menu->addAction(tr("Re&vert Change %1").arg(change), [workingDir, change] {
GitPlugin::client()->synchronousRevert(workingDir, change); GitClient::instance()->synchronousRevert(workingDir, change);
}); });
menu->addAction(tr("C&heckout Change %1").arg(change), [workingDir, change] { menu->addAction(tr("C&heckout Change %1").arg(change), [workingDir, change] {
GitPlugin::client()->checkout(workingDir, change); GitClient::instance()->checkout(workingDir, change);
}); });
connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)), connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)),
&QAction::triggered, [workingDir, change] { &QAction::triggered, [workingDir, change] {
GitPlugin::startRebaseFromCommit(workingDir, change); GitPlugin::startRebaseFromCommit(workingDir, change);
}); });
menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] { menu->addAction(tr("&Log for Change %1").arg(change), [workingDir, change] {
GitPlugin::client()->log(workingDir, QString(), false, {change}); GitClient::instance()->log(workingDir, QString(), false, {change});
}); });
menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] { menu->addAction(tr("Add &Tag for Change %1...").arg(change), [workingDir, change] {
QString output; QString output;
QString errorMessage; QString errorMessage;
GitPlugin::client()->synchronousTagCmd(workingDir, QStringList(), GitClient::instance()->synchronousTagCmd(workingDir, QStringList(),
&output, &errorMessage); &output, &errorMessage);
const QStringList tags = output.split('\n'); const QStringList tags = output.split('\n');
@@ -338,7 +338,7 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change, const
if (dialog.exec() == QDialog::Rejected) if (dialog.exec() == QDialog::Rejected)
return; return;
GitPlugin::client()->synchronousTagCmd(workingDir, GitClient::instance()->synchronousTagCmd(workingDir,
{dialog.branchName(), change}, {dialog.branchName(), change},
&output, &errorMessage); &output, &errorMessage);
VcsOutputWindow::append(output); VcsOutputWindow::append(output);
@@ -347,7 +347,7 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change, const
}); });
auto resetChange = [workingDir, change](const QByteArray &resetType) { auto resetChange = [workingDir, change](const QByteArray &resetType) {
GitPlugin::client()->reset( GitClient::instance()->reset(
workingDir, QLatin1String("--" + resetType), change); workingDir, QLatin1String("--" + resetType), change);
}; };
auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu); auto resetMenu = new QMenu(tr("&Reset to Change %1").arg(change), menu);

View File

@@ -26,7 +26,6 @@
#include "gitgrep.h" #include "gitgrep.h"
#include "gitclient.h" #include "gitclient.h"
#include "gitconstants.h" #include "gitconstants.h"
#include "gitplugin.h"
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/progressmanager/progressmanager.h>
@@ -187,7 +186,7 @@ public:
return QString(":!" + filter); return QString(":!" + filter);
}); });
arguments << "--" << filterArgs << exclusionArgs; arguments << "--" << filterArgs << exclusionArgs;
QScopedPointer<VcsCommand> command(GitPlugin::client()->createCommand(m_directory)); QScopedPointer<VcsCommand> command(GitClient::instance()->createCommand(m_directory));
command->addFlags(VcsCommand::SilentOutput | VcsCommand::SuppressFailMessage); command->addFlags(VcsCommand::SilentOutput | VcsCommand::SuppressFailMessage);
command->setProgressiveOutput(true); command->setProgressiveOutput(true);
QFutureWatcher<FileSearchResultList> watcher; QFutureWatcher<FileSearchResultList> watcher;
@@ -195,7 +194,7 @@ public:
connect(&watcher, &QFutureWatcher<FileSearchResultList>::canceled, connect(&watcher, &QFutureWatcher<FileSearchResultList>::canceled,
command.data(), &VcsCommand::cancel); command.data(), &VcsCommand::cancel);
connect(command.data(), &VcsCommand::stdOutText, this, &GitGrepRunner::read); connect(command.data(), &VcsCommand::stdOutText, this, &GitGrepRunner::read);
SynchronousProcessResponse resp = command->runCommand({GitPlugin::client()->vcsBinary(), arguments}, 0); SynchronousProcessResponse resp = command->runCommand({GitClient::instance()->vcsBinary(), arguments}, 0);
switch (resp.result) { switch (resp.result) {
case SynchronousProcessResponse::TerminatedAbnormally: case SynchronousProcessResponse::TerminatedAbnormally:
case SynchronousProcessResponse::StartFailed: case SynchronousProcessResponse::StartFailed:

View File

@@ -1760,11 +1760,11 @@ void GitPluginPrivate::updateCurrentBranch()
QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory, QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory,
const QStringList &) const QStringList &)
{ {
if (!GitPlugin::client() || options.size() < 2) if (options.size() < 2)
return nullptr; return nullptr;
if (options.first() == "-git-show") if (options.first() == "-git-show")
GitPlugin::client()->show(workingDirectory, options.at(1)); dd->m_gitClient.show(workingDirectory, options.at(1));
return nullptr; return nullptr;
} }

View File

@@ -88,8 +88,8 @@ CommitDataFetchResult CommitDataFetchResult::fetch(CommitType commitType, const
CommitDataFetchResult result; CommitDataFetchResult result;
result.commitData.commitType = commitType; result.commitData.commitType = commitType;
QString commitTemplate; QString commitTemplate;
result.success = GitPlugin::client()->getCommitData(workingDirectory, &commitTemplate, result.success = GitClient::instance()->getCommitData(
result.commitData, &result.errorMessage); workingDirectory, &commitTemplate, result.commitData, &result.errorMessage);
return result; return result;
} }
@@ -202,15 +202,15 @@ void GitSubmitEditor::slotDiffSelected(const QList<int> &rows)
} }
} }
if (!unstagedFiles.empty() || !stagedFiles.empty()) if (!unstagedFiles.empty() || !stagedFiles.empty())
GitPlugin::client()->diffFiles(m_workingDirectory, unstagedFiles, stagedFiles); GitClient::instance()->diffFiles(m_workingDirectory, unstagedFiles, stagedFiles);
if (!unmergedFiles.empty()) if (!unmergedFiles.empty())
GitPlugin::client()->merge(m_workingDirectory, unmergedFiles); GitClient::instance()->merge(m_workingDirectory, unmergedFiles);
} }
void GitSubmitEditor::showCommit(const QString &commit) void GitSubmitEditor::showCommit(const QString &commit)
{ {
if (!m_workingDirectory.isEmpty()) if (!m_workingDirectory.isEmpty())
GitPlugin::client()->show(m_workingDirectory, commit); GitClient::instance()->show(m_workingDirectory, commit);
} }
void GitSubmitEditor::updateFileModel() void GitSubmitEditor::updateFileModel()
@@ -230,7 +230,7 @@ void GitSubmitEditor::updateFileModel()
Core::ProgressManager::addTask(m_fetchWatcher.future(), tr("Refreshing Commit Data"), Core::ProgressManager::addTask(m_fetchWatcher.future(), tr("Refreshing Commit Data"),
TASK_UPDATE_COMMIT); TASK_UPDATE_COMMIT);
GitPlugin::client()->addFuture(m_fetchWatcher.future()); GitClient::instance()->addFuture(m_fetchWatcher.future());
} }
void GitSubmitEditor::forceUpdateFileModel() void GitSubmitEditor::forceUpdateFileModel()

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "logchangedialog.h" #include "logchangedialog.h"
#include "gitplugin.h"
#include "gitclient.h" #include "gitclient.h"
#include <vcsbase/vcsoutputwindow.h> #include <vcsbase/vcsoutputwindow.h>
@@ -79,7 +78,7 @@ bool LogChangeWidget::init(const QString &repository, const QString &commit, Log
return true; return true;
if (!(flags & Silent)) { if (!(flags & Silent)) {
VcsOutputWindow::appendError( VcsOutputWindow::appendError(
GitPlugin::client()->msgNoCommits(flags & IncludeRemotes)); GitClient::instance()->msgNoCommits(flags & IncludeRemotes));
} }
return false; return false;
} }
@@ -159,8 +158,10 @@ bool LogChangeWidget::populateLog(const QString &repository, const QString &comm
arguments << "--not" << "--remotes"; arguments << "--not" << "--remotes";
arguments << "--"; arguments << "--";
QString output; QString output;
if (!GitPlugin::client()->synchronousLog(repository, arguments, &output, nullptr, VcsCommand::NoOutput)) if (!GitClient::instance()->synchronousLog(
repository, arguments, &output, nullptr, VcsCommand::NoOutput)) {
return false; return false;
}
const QStringList lines = output.split('\n'); const QStringList lines = output.split('\n');
for (const QString &line : lines) { for (const QString &line : lines) {
const int colonPos = line.indexOf(':'); const int colonPos = line.indexOf(':');
@@ -211,8 +212,8 @@ LogChangeDialog::LogChangeDialog(bool isReset, QWidget *parent) :
m_resetTypeComboBox->addItem(tr("Hard"), "--hard"); m_resetTypeComboBox->addItem(tr("Hard"), "--hard");
m_resetTypeComboBox->addItem(tr("Mixed"), "--mixed"); m_resetTypeComboBox->addItem(tr("Mixed"), "--mixed");
m_resetTypeComboBox->addItem(tr("Soft"), "--soft"); m_resetTypeComboBox->addItem(tr("Soft"), "--soft");
m_resetTypeComboBox->setCurrentIndex(GitPlugin::client()->settings().intValue( m_resetTypeComboBox->setCurrentIndex(
GitSettings::lastResetIndexKey)); GitClient::instance()->settings().intValue(GitSettings::lastResetIndexKey));
popUpLayout->addWidget(m_resetTypeComboBox); popUpLayout->addWidget(m_resetTypeComboBox);
popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored));
} }
@@ -239,8 +240,8 @@ bool LogChangeDialog::runDialog(const QString &repository,
if (QDialog::exec() == QDialog::Accepted) { if (QDialog::exec() == QDialog::Accepted) {
if (m_resetTypeComboBox) { if (m_resetTypeComboBox) {
GitPlugin::client()->settings().setValue(GitSettings::lastResetIndexKey, GitClient::instance()->settings().setValue(
m_resetTypeComboBox->currentIndex()); GitSettings::lastResetIndexKey, m_resetTypeComboBox->currentIndex());
} }
return true; return true;
} }

View File

@@ -60,7 +60,7 @@ bool MergeTool::start(const QString &workingDirectory, const QStringList &files)
m_process->setWorkingDirectory(workingDirectory); m_process->setWorkingDirectory(workingDirectory);
m_process->setProcessEnvironment(env); m_process->setProcessEnvironment(env);
m_process->setProcessChannelMode(QProcess::MergedChannels); m_process->setProcessChannelMode(QProcess::MergedChannels);
const Utils::FilePath binary = GitPlugin::client()->vcsBinary(); const Utils::FilePath binary = GitClient::instance()->vcsBinary();
VcsOutputWindow::appendCommand(workingDirectory, {binary, arguments}); VcsOutputWindow::appendCommand(workingDirectory, {binary, arguments});
m_process->start(binary.toString(), arguments); m_process->start(binary.toString(), arguments);
if (m_process->waitForStarted()) { if (m_process->waitForStarted()) {
@@ -263,7 +263,7 @@ void MergeTool::done()
VcsOutputWindow::appendError(tr("Merge tool process terminated with exit code %1") VcsOutputWindow::appendError(tr("Merge tool process terminated with exit code %1")
.arg(exitCode)); .arg(exitCode));
} }
GitPlugin::client()->continueCommandIfNeeded(workingDirectory, exitCode == 0); GitClient::instance()->continueCommandIfNeeded(workingDirectory, exitCode == 0);
GitPlugin::emitRepositoryChanged(workingDirectory); GitPlugin::emitRepositoryChanged(workingDirectory);
deleteLater(); deleteLater();
} }

View File

@@ -203,7 +203,7 @@ void RemoteDialog::pushToRemote()
const int row = indexList.at(0).row(); const int row = indexList.at(0).row();
const QString remoteName = m_remoteModel->remoteName(row); const QString remoteName = m_remoteModel->remoteName(row);
GitPlugin::client()->push(m_remoteModel->workingDirectory(), {remoteName}); GitClient::instance()->push(m_remoteModel->workingDirectory(), {remoteName});
} }
void RemoteDialog::fetchFromRemote() void RemoteDialog::fetchFromRemote()
@@ -214,7 +214,7 @@ void RemoteDialog::fetchFromRemote()
int row = indexList.at(0).row(); int row = indexList.at(0).row();
const QString remoteName = m_remoteModel->remoteName(row); const QString remoteName = m_remoteModel->remoteName(row);
GitPlugin::client()->fetch(m_remoteModel->workingDirectory(), remoteName); GitClient::instance()->fetch(m_remoteModel->workingDirectory(), remoteName);
} }
void RemoteDialog::updateButtonState() void RemoteDialog::updateButtonState()

View File

@@ -24,7 +24,6 @@
****************************************************************************/ ****************************************************************************/
#include "remotemodel.h" #include "remotemodel.h"
#include "gitplugin.h"
#include "gitclient.h" #include "gitclient.h"
#include <utils/algorithm.h> #include <utils/algorithm.h>
@@ -55,7 +54,7 @@ bool RemoteModel::removeRemote(int row)
{ {
QString output; QString output;
QString error; QString error;
bool success = GitPlugin::client()->synchronousRemoteCmd( bool success = GitClient::instance()->synchronousRemoteCmd(
m_workingDirectory, {"rm", remoteName(row)}, &output, &error); m_workingDirectory, {"rm", remoteName(row)}, &output, &error);
if (success) if (success)
success = refresh(m_workingDirectory, &error); success = refresh(m_workingDirectory, &error);
@@ -69,7 +68,7 @@ bool RemoteModel::addRemote(const QString &name, const QString &url)
if (name.isEmpty() || url.isEmpty()) if (name.isEmpty() || url.isEmpty())
return false; return false;
bool success = GitPlugin::client()->synchronousRemoteCmd( bool success = GitClient::instance()->synchronousRemoteCmd(
m_workingDirectory, {"add", name, url}, &output, &error); m_workingDirectory, {"add", name, url}, &output, &error);
if (success) if (success)
success = refresh(m_workingDirectory, &error); success = refresh(m_workingDirectory, &error);
@@ -80,7 +79,7 @@ bool RemoteModel::renameRemote(const QString &oldName, const QString &newName)
{ {
QString output; QString output;
QString error; QString error;
bool success = GitPlugin::client()->synchronousRemoteCmd( bool success = GitClient::instance()->synchronousRemoteCmd(
m_workingDirectory, {"rename", oldName, newName}, &output, &error); m_workingDirectory, {"rename", oldName, newName}, &output, &error);
if (success) if (success)
success = refresh(m_workingDirectory, &error); success = refresh(m_workingDirectory, &error);
@@ -91,7 +90,7 @@ bool RemoteModel::updateUrl(const QString &name, const QString &newUrl)
{ {
QString output; QString output;
QString error; QString error;
bool success = GitPlugin::client()->synchronousRemoteCmd( bool success = GitClient::instance()->synchronousRemoteCmd(
m_workingDirectory, {"set-url", name, newUrl}, &output, &error); m_workingDirectory, {"set-url", name, newUrl}, &output, &error);
if (success) if (success)
success = refresh(m_workingDirectory, &error); success = refresh(m_workingDirectory, &error);
@@ -186,7 +185,7 @@ bool RemoteModel::refresh(const QString &workingDirectory, QString *errorMessage
// get list of remotes. // get list of remotes.
QMap<QString,QString> remotesList QMap<QString,QString> remotesList
= GitPlugin::client()->synchronousRemotesList(workingDirectory, errorMessage); = GitClient::instance()->synchronousRemotesList(workingDirectory, errorMessage);
beginResetModel(); beginResetModel();
m_remotes.clear(); m_remotes.clear();

View File

@@ -161,7 +161,7 @@ void StashDialog::refresh(const QString &repository, bool force)
m_model->setStashes(QList<Stash>()); m_model->setStashes(QList<Stash>());
} else { } else {
QList<Stash> stashes; QList<Stash> stashes;
GitPlugin::client()->synchronousStashList(m_repository, &stashes); GitClient::instance()->synchronousStashList(m_repository, &stashes);
m_model->setStashes(stashes); m_model->setStashes(stashes);
if (!stashes.isEmpty()) { if (!stashes.isEmpty()) {
for (int c = 0; c < ColumnCount; c++) for (int c = 0; c < ColumnCount; c++)
@@ -177,7 +177,7 @@ void StashDialog::deleteAll()
if (!ask(title, tr("Do you want to delete all stashes?"))) if (!ask(title, tr("Do you want to delete all stashes?")))
return; return;
QString errorMessage; QString errorMessage;
if (GitPlugin::client()->synchronousStashRemove(m_repository, QString(), &errorMessage)) if (GitClient::instance()->synchronousStashRemove(m_repository, QString(), &errorMessage))
refresh(m_repository, true); refresh(m_repository, true);
else else
warning(title, errorMessage); warning(title, errorMessage);
@@ -194,7 +194,7 @@ void StashDialog::deleteSelection()
QStringList errors; QStringList errors;
// Delete in reverse order as stashes rotate // Delete in reverse order as stashes rotate
for (int r = rows.size() - 1; r >= 0; r--) for (int r = rows.size() - 1; r >= 0; r--)
if (!GitPlugin::client()->synchronousStashRemove(m_repository, m_model->at(rows.at(r)).name, &errorMessage)) if (!GitClient::instance()->synchronousStashRemove(m_repository, m_model->at(rows.at(r)).name, &errorMessage))
errors.push_back(errorMessage); errors.push_back(errorMessage);
refresh(m_repository, true); refresh(m_repository, true);
if (!errors.isEmpty()) if (!errors.isEmpty())
@@ -205,7 +205,7 @@ void StashDialog::showCurrent()
{ {
const int index = currentRow(); const int index = currentRow();
QTC_ASSERT(index >= 0, return); QTC_ASSERT(index >= 0, return);
GitPlugin::client()->show(m_repository, QString(m_model->at(index).name)); GitClient::instance()->show(m_repository, QString(m_model->at(index).name));
} }
// Suggest Branch name to restore 'stash@{0}' -> 'stash0-date' // Suggest Branch name to restore 'stash@{0}' -> 'stash0-date'
@@ -266,7 +266,8 @@ bool StashDialog::promptForRestore(QString *stash,
{ {
const QString stashIn = *stash; const QString stashIn = *stash;
bool modifiedPromptShown = false; bool modifiedPromptShown = false;
switch (GitPlugin::client()->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules), nullptr, errorMessage)) { switch (GitClient::instance()->gitStatus(
m_repository, StatusMode(NoUntracked | NoSubmodules), nullptr, errorMessage)) {
case GitClient::StatusFailed: case GitClient::StatusFailed:
return false; return false;
case GitClient::StatusChanged: { case GitClient::StatusChanged: {
@@ -274,13 +275,15 @@ bool StashDialog::promptForRestore(QString *stash,
case ModifiedRepositoryCancel: case ModifiedRepositoryCancel:
return false; return false;
case ModifiedRepositoryStash: case ModifiedRepositoryStash:
if (GitPlugin::client()->synchronousStash(m_repository, QString(), GitClient::StashPromptDescription).isEmpty()) if (GitClient::instance()->synchronousStash(
m_repository, QString(), GitClient::StashPromptDescription).isEmpty()) {
return false; return false;
}
*stash = nextStash(*stash); // Our stash id to be restored changed *stash = nextStash(*stash); // Our stash id to be restored changed
QTC_ASSERT(!stash->isEmpty(), return false); QTC_ASSERT(!stash->isEmpty(), return false);
break; break;
case ModifiedRepositoryDiscard: case ModifiedRepositoryDiscard:
if (!GitPlugin::client()->synchronousReset(m_repository)) if (!GitClient::instance()->synchronousReset(m_repository))
return false; return false;
break; break;
} }
@@ -317,7 +320,7 @@ void StashDialog::restoreCurrent()
// Make sure repository is not modified, restore. The command will // Make sure repository is not modified, restore. The command will
// output to window on success. // output to window on success.
if (promptForRestore(&name, nullptr, &errorMessage) if (promptForRestore(&name, nullptr, &errorMessage)
&& GitPlugin::client()->synchronousStashRestore(m_repository, name)) { && GitClient::instance()->synchronousStashRestore(m_repository, name)) {
refresh(m_repository, true); // Might have stashed away local changes. refresh(m_repository, true); // Might have stashed away local changes.
} else if (!errorMessage.isEmpty()) { } else if (!errorMessage.isEmpty()) {
warning(msgRestoreFailedTitle(name), errorMessage); warning(msgRestoreFailedTitle(name), errorMessage);
@@ -332,7 +335,7 @@ void StashDialog::restoreCurrentInBranch()
QString branch; QString branch;
QString name = m_model->at(index).name; QString name = m_model->at(index).name;
if (promptForRestore(&name, &branch, &errorMessage) if (promptForRestore(&name, &branch, &errorMessage)
&& GitPlugin::client()->synchronousStashRestore(m_repository, name, false, branch)) { && GitClient::instance()->synchronousStashRestore(m_repository, name, false, branch)) {
refresh(m_repository, true); // git deletes the stash, unfortunately. refresh(m_repository, true); // git deletes the stash, unfortunately.
} else if (!errorMessage.isEmpty()) { } else if (!errorMessage.isEmpty()) {
warning(msgRestoreFailedTitle(name), errorMessage); warning(msgRestoreFailedTitle(name), errorMessage);