diff options
author | hjk <hjk@qt.io> | 2020-01-23 17:22:05 +0100 |
---|---|---|
committer | hjk <hjk@qt.io> | 2020-01-24 09:47:28 +0000 |
commit | 1cd936c53145f520fb9a3817a6548d9d25c399f0 (patch) | |
tree | 2c1cc9c375b986b5d9a7abf3f982781256ae612d /src/plugins/git | |
parent | 01e4f573e812c9c855a11d0cb199f9d9bed8de49 (diff) | |
download | qt-creator-1cd936c53145f520fb9a3817a6548d9d25c399f0.tar.gz |
Vcs: Pimpl plugins
Essentially rename all *Plugin into *PluginPrivate, and pull out
the actual IPlugin related pieces into new *Plugin classes.
Shift the construction of the PluginPrivate to initialize(),
following the general pattern.
I tried to keep the patch as mechanical as possible, giving
room to some obvious but less mechanical cleanup needs,
that are intentionally left out of this here.
Change-Id: Iac662bf73338f9f7669064ed67b960246875c23c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git')
23 files changed, 307 insertions, 284 deletions
diff --git a/src/plugins/git/branchadddialog.cpp b/src/plugins/git/branchadddialog.cpp index 8a131a363c..09e18fbe0e 100644 --- a/src/plugins/git/branchadddialog.cpp +++ b/src/plugins/git/branchadddialog.cpp @@ -50,7 +50,7 @@ class BranchNameValidator : public QValidator public: BranchNameValidator(const QStringList &localBranches, QObject *parent = nullptr) : QValidator(parent), - m_invalidChars(GitPlugin::invalidBranchAndRemoteNamePattern()), + m_invalidChars(GitPluginPrivate::invalidBranchAndRemoteNamePattern()), m_localBranches(localBranches) { } diff --git a/src/plugins/git/branchview.cpp b/src/plugins/git/branchview.cpp index 62429182c5..efbfd15b61 100644 --- a/src/plugins/git/branchview.cpp +++ b/src/plugins/git/branchview.cpp @@ -82,7 +82,7 @@ BranchView::BranchView() : m_refreshButton(new QToolButton(this)), m_repositoryLabel(new Utils::ElidingLabel(this)), m_branchView(new Utils::NavigationTreeView(this)), - m_model(new BranchModel(GitPlugin::client(), this)), + m_model(new BranchModel(GitPluginPrivate::client(), this)), m_filterModel(new BranchFilterModel(this)) { m_addButton->setIcon(Utils::Icons::PLUS_TOOLBAR.icon()); @@ -122,7 +122,7 @@ BranchView::BranchView() : this, &BranchView::setIncludeOldEntries); m_includeTagsAction->setCheckable(true); m_includeTagsAction->setChecked( - GitPlugin::client()->settings().boolValue(GitSettings::showTagsKey)); + GitPluginPrivate::client()->settings().boolValue(GitSettings::showTagsKey)); connect(m_includeTagsAction, &QAction::toggled, this, &BranchView::setIncludeTags); @@ -138,7 +138,7 @@ BranchView::BranchView() : this, &BranchView::expandAndResize); m_branchView->selectionModel()->clear(); - m_repository = GitPlugin::instance()->currentState().topLevel(); + m_repository = GitPluginPrivate::instance()->currentState().topLevel(); refreshCurrentRepository(); } @@ -160,7 +160,7 @@ void BranchView::refresh(const QString &repository, bool force) m_branchView->setEnabled(false); } else { m_repositoryLabel->setText(QDir::toNativeSeparators(m_repository)); - m_repositoryLabel->setToolTip(GitPlugin::msgRepositoryLabel(m_repository)); + m_repositoryLabel->setToolTip(GitPluginPrivate::msgRepositoryLabel(m_repository)); m_addButton->setToolTip(tr("Add Branch...")); m_branchView->setEnabled(true); } @@ -214,17 +214,17 @@ void BranchView::slotCustomContextMenu(const QPoint &point) const Utils::optional<QString> remote = m_model->remoteName(index); if (remote.has_value()) { contextMenu.addAction(tr("&Fetch"), this, [this, &remote]() { - GitPlugin::client()->fetch(m_repository, *remote); + GitPluginPrivate::client()->fetch(m_repository, *remote); }); contextMenu.addSeparator(); if (!remote->isEmpty()) { contextMenu.addAction(tr("Remove &Stale Branches"), this, [this, &remote]() { - GitPlugin::client()->removeStaleRemoteBranches(m_repository, *remote); + GitPluginPrivate::client()->removeStaleRemoteBranches(m_repository, *remote); }); contextMenu.addSeparator(); } - contextMenu.addAction(tr("Manage &Remotes..."), GitPlugin::instance(), - &GitPlugin::manageRemotes); + contextMenu.addAction(tr("Manage &Remotes..."), GitPluginPrivate::instance(), + &GitPluginPrivate::manageRemotes); } if (hasActions) { if (!currentSelected && (isLocal || isTag)) @@ -237,7 +237,7 @@ void BranchView::slotCustomContextMenu(const QPoint &point) contextMenu.addAction(tr("&Diff"), this, [this] { const QString fullName = m_model->fullName(selectedIndex(), true); if (!fullName.isEmpty()) - GitPlugin::client()->diffBranch(m_repository, fullName); + GitPluginPrivate::client()->diffBranch(m_repository, fullName); }); contextMenu.addAction(tr("&Log"), this, [this] { log(selectedIndex()); }); contextMenu.addSeparator(); @@ -287,7 +287,7 @@ void BranchView::setIncludeOldEntries(bool filter) void BranchView::setIncludeTags(bool includeTags) { - GitPlugin::client()->settings().setValue(GitSettings::showTagsKey, includeTags); + GitPluginPrivate::client()->settings().setValue(GitSettings::showTagsKey, includeTags); refreshCurrentRepository(); } @@ -302,7 +302,7 @@ QModelIndex BranchView::selectedIndex() bool BranchView::add() { if (m_repository.isEmpty()) { - GitPlugin::instance()->initRepository(); + GitPluginPrivate::instance()->initRepository(); return true; } @@ -363,7 +363,7 @@ bool BranchView::checkout() ' ' + nextBranch + "-AutoStash "; BranchCheckoutDialog branchCheckoutDialog(this, currentBranch, nextBranch); - GitClient *client = GitPlugin::client(); + GitClient *client = GitPluginPrivate::client(); if (client->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules)) != GitClient::StatusChanged) branchCheckoutDialog.foundNoLocalChanges(); @@ -498,7 +498,7 @@ bool BranchView::reset(const QByteArray &resetType) if (QMessageBox::question(this, tr("Git Reset"), tr("Reset branch \"%1\" to \"%2\"?") .arg(currentName).arg(branchName), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - GitPlugin::client()->reset(m_repository, QLatin1String("--" + resetType), branchName); + GitPluginPrivate::client()->reset(m_repository, QLatin1String("--" + resetType), branchName); return true; } return false; @@ -510,7 +510,7 @@ bool BranchView::isFastForwardMerge() QTC_CHECK(selected != m_model->currentBranch()); const QString branch = m_model->fullName(selected, true); - return GitPlugin::client()->isFastForwardMerge(m_repository, branch); + return GitPluginPrivate::client()->isFastForwardMerge(m_repository, branch); } bool BranchView::merge(bool allowFastForward) @@ -521,7 +521,7 @@ bool BranchView::merge(bool allowFastForward) QTC_CHECK(selected != m_model->currentBranch()); const QString branch = m_model->fullName(selected, true); - GitClient *client = GitPlugin::client(); + GitClient *client = GitPluginPrivate::client(); if (client->beginStashScope(m_repository, "merge", AllowUnstashed)) return client->synchronousMerge(m_repository, branch, allowFastForward); @@ -536,7 +536,7 @@ void BranchView::rebase() QTC_CHECK(selected != m_model->currentBranch()); const QString baseBranch = m_model->fullName(selected, true); - GitClient *client = GitPlugin::client(); + GitClient *client = GitPluginPrivate::client(); if (client->beginStashScope(m_repository, "rebase")) client->rebase(m_repository, baseBranch); } @@ -549,14 +549,14 @@ bool BranchView::cherryPick() QTC_CHECK(selected != m_model->currentBranch()); const QString branch = m_model->fullName(selected, true); - return GitPlugin::client()->synchronousCherryPick(m_repository, branch); + return GitPluginPrivate::client()->synchronousCherryPick(m_repository, branch); } void BranchView::log(const QModelIndex &idx) { const QString branchName = m_model->fullName(idx, true); if (!branchName.isEmpty()) - GitPlugin::client()->log(m_repository, QString(), false, {branchName}); + GitPluginPrivate::client()->log(m_repository, QString(), false, {branchName}); } void BranchView::push() @@ -572,7 +572,7 @@ void BranchView::push() const QString remoteBranch = fullTargetName.mid(pos + 1); const QStringList pushArgs = {remoteName, localBranch + ':' + remoteBranch}; - GitPlugin::client()->push(m_repository, pushArgs); + GitPluginPrivate::client()->push(m_repository, pushArgs); } BranchViewFactory::BranchViewFactory() diff --git a/src/plugins/git/changeselectiondialog.cpp b/src/plugins/git/changeselectiondialog.cpp index 47a55be5c5..9f7585cd0d 100644 --- a/src/plugins/git/changeselectiondialog.cpp +++ b/src/plugins/git/changeselectiondialog.cpp @@ -58,12 +58,12 @@ ChangeSelectionDialog::ChangeSelectionDialog(const QString &workingDirectory, Co QDialog(parent), m_ui(new Ui::ChangeSelectionDialog) { setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); - m_gitExecutable = GitPlugin::client()->vcsBinary(); + m_gitExecutable = GitPluginPrivate::client()->vcsBinary(); m_ui->setupUi(this); m_ui->workingDirectoryChooser->setExpectedKind(PathChooser::ExistingDirectory); m_ui->workingDirectoryChooser->setPromptDialogTitle(tr("Select Git Directory")); m_ui->workingDirectoryChooser->setPath(workingDirectory); - m_gitEnvironment = GitPlugin::client()->processEnvironment(); + m_gitEnvironment = GitPluginPrivate::client()->processEnvironment(); m_ui->changeNumberEdit->setFocus(); m_ui->changeNumberEdit->selectAll(); @@ -204,7 +204,7 @@ void ChangeSelectionDialog::recalculateCompletion() if (workingDir.isEmpty()) return; - GitClient *client = GitPlugin::client(); + GitClient *client = GitPluginPrivate::client(); VcsBase::VcsCommand *command = client->asyncForEachRefCmd( workingDir, {"--format=%(refname:short)"}); connect(this, &QObject::destroyed, command, &VcsBase::VcsCommand::abort); diff --git a/src/plugins/git/gerrit/branchcombobox.cpp b/src/plugins/git/gerrit/branchcombobox.cpp index 6cc866ce3f..6505066a3b 100644 --- a/src/plugins/git/gerrit/branchcombobox.cpp +++ b/src/plugins/git/gerrit/branchcombobox.cpp @@ -36,7 +36,7 @@ BranchComboBox::BranchComboBox(QWidget *parent) : QComboBox(parent) void BranchComboBox::init(const QString &repository) { m_repository = repository; - QString currentBranch = GitPlugin::client()->synchronousCurrentLocalBranch(repository); + QString currentBranch = GitPluginPrivate::client()->synchronousCurrentLocalBranch(repository); if (currentBranch.isEmpty()) { m_detached = true; currentBranch = "HEAD"; @@ -44,7 +44,7 @@ void BranchComboBox::init(const QString &repository) } QString output; const QString branchPrefix("refs/heads/"); - if (!GitPlugin::client()->synchronousForEachRefCmd( + if (!GitPluginPrivate::client()->synchronousForEachRefCmd( m_repository, {"--format=%(refname)", branchPrefix}, &output)) { return; } diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp index 402c29763a..26babec2a1 100644 --- a/src/plugins/git/gerrit/gerritdialog.cpp +++ b/src/plugins/git/gerrit/gerritdialog.cpp @@ -139,7 +139,7 @@ void GerritDialog::setCurrentPath(const QString &path) if (path == m_repository) return; m_repository = path; - m_ui->repositoryLabel->setText(Git::Internal::GitPlugin::msgRepositoryLabel(path)); + m_ui->repositoryLabel->setText(Git::Internal::GitPluginPrivate::msgRepositoryLabel(path)); updateRemotes(); } diff --git a/src/plugins/git/gerrit/gerritmodel.cpp b/src/plugins/git/gerrit/gerritmodel.cpp index a9be6358cc..694e25dc91 100644 --- a/src/plugins/git/gerrit/gerritmodel.cpp +++ b/src/plugins/git/gerrit/gerritmodel.cpp @@ -295,7 +295,7 @@ QueryContext::QueryContext(const QString &query, connect(&m_process, &QProcess::errorOccurred, this, &QueryContext::processError); connect(&m_watcher, &QFutureWatcherBase::canceled, this, &QueryContext::terminate); m_watcher.setFuture(m_progress.future()); - m_process.setProcessEnvironment(Git::Internal::GitPlugin::client()->processEnvironment()); + m_process.setProcessEnvironment(Git::Internal::GitPluginPrivate::client()->processEnvironment()); m_progress.setProgressRange(0, 1); m_timer.setInterval(timeOutMS); diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index f0aebf59d8..d3fe5e0d4b 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -149,7 +149,7 @@ FetchContext::FetchContext(const QSharedPointer<GerritChange> &change, connect(&m_watcher, &QFutureWatcher<void>::canceled, this, &FetchContext::terminate); m_watcher.setFuture(m_progress.future()); m_process.setWorkingDirectory(repository); - m_process.setProcessEnvironment(GitPlugin::client()->processEnvironment()); + m_process.setProcessEnvironment(GitPluginPrivate::client()->processEnvironment()); m_process.closeWriteChannel(); } @@ -241,7 +241,7 @@ void FetchContext::show() { const QString title = QString::number(m_change->number) + '/' + QString::number(m_change->currentPatchSet.patchSetNumber); - GitPlugin::client()->show(m_repository, "FETCH_HEAD", title); + GitPluginPrivate::client()->show(m_repository, "FETCH_HEAD", title); } void FetchContext::cherryPick() @@ -249,12 +249,12 @@ void FetchContext::cherryPick() // Point user to errors. VcsBase::VcsOutputWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus); - GitPlugin::client()->synchronousCherryPick(m_repository, "FETCH_HEAD"); + GitPluginPrivate::client()->synchronousCherryPick(m_repository, "FETCH_HEAD"); } void FetchContext::checkout() { - GitPlugin::client()->checkout(m_repository, "FETCH_HEAD"); + GitPluginPrivate::client()->checkout(m_repository, "FETCH_HEAD"); } void FetchContext::terminate() @@ -272,7 +272,7 @@ GerritPlugin::GerritPlugin(QObject *parent) GerritPlugin::~GerritPlugin() = default; -bool GerritPlugin::initialize(ActionContainer *ac) +void GerritPlugin::initialize(ActionContainer *ac) { m_parameters->fromSettings(ICore::settings()); @@ -296,7 +296,6 @@ bool GerritPlugin::initialize(ActionContainer *ac) if (m_dialog) m_dialog->scheduleUpdateRemotes(); }); - return true; } void GerritPlugin::updateActions(const VcsBase::VcsBasePluginState &state) @@ -330,12 +329,12 @@ void GerritPlugin::push(const QString &topLevel) dialog.storeTopic(); m_reviewers = dialog.reviewers(); - GitPlugin::client()->push(topLevel, {dialog.selectedRemoteName(), dialog.pushTarget()}); + GitPluginPrivate::client()->push(topLevel, {dialog.selectedRemoteName(), dialog.pushTarget()}); } static QString currentRepository() { - return GitPlugin::instance()->currentState().topLevel(); + return GitPluginPrivate::instance()->currentState().topLevel(); } // Open or raise the Gerrit dialog window. @@ -377,19 +376,19 @@ void GerritPlugin::push() Utils::FilePath GerritPlugin::gitBinDirectory() { - return GitPlugin::client()->gitBinDirectory(); + return GitPluginPrivate::client()->gitBinDirectory(); } // Find the branch of a repository. QString GerritPlugin::branch(const QString &repository) { - return GitPlugin::client()->synchronousCurrentLocalBranch(repository); + return GitPluginPrivate::client()->synchronousCurrentLocalBranch(repository); } void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) { // Locate git. - const Utils::FilePath git = GitPlugin::client()->vcsBinary(); + const Utils::FilePath git = GitPluginPrivate::client()->vcsBinary(); if (git.isEmpty()) { VcsBase::VcsOutputWindow::appendError(tr("Git is not available.")); return; @@ -402,7 +401,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) if (!repository.isEmpty()) { // 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 = GitPluginPrivate::client()->synchronousRemotesList(repository); if (!remotesList.isEmpty()) { const QStringList remotes = remotesList.values(); for (QString remote : remotes) { @@ -415,7 +414,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) } if (!verifiedRepository) { - const SubmoduleDataMap submodules = GitPlugin::client()->submoduleList(repository); + const SubmoduleDataMap submodules = GitPluginPrivate::client()->submoduleList(repository); for (const SubmoduleData &submoduleData : submodules) { QString remote = submoduleData.url; if (remote.endsWith(".git")) @@ -474,7 +473,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode) // Try to find a matching repository for a project by asking the VcsManager. QString GerritPlugin::findLocalRepository(QString project, const QString &branch) const { - const QStringList gitRepositories = VcsManager::repositories(GitPlugin::instance()->gitVersionControl()); + const QStringList gitRepositories = VcsManager::repositories(GitPluginPrivate::instance()->gitVersionControl()); // Determine key (file name) to look for (qt/qtbase->'qtbase'). const int slashPos = project.lastIndexOf('/'); if (slashPos != -1) diff --git a/src/plugins/git/gerrit/gerritplugin.h b/src/plugins/git/gerrit/gerritplugin.h index 3c6ebb5335..356d23e632 100644 --- a/src/plugins/git/gerrit/gerritplugin.h +++ b/src/plugins/git/gerrit/gerritplugin.h @@ -55,7 +55,7 @@ public: explicit GerritPlugin(QObject *parent = nullptr); ~GerritPlugin() override; - bool initialize(Core::ActionContainer *ac); + void initialize(Core::ActionContainer *ac); static Utils::FilePath gitBinDirectory(); static QString branch(const QString &repository); diff --git a/src/plugins/git/gerrit/gerritpushdialog.cpp b/src/plugins/git/gerrit/gerritpushdialog.cpp index 9a251b5eda..305581ae40 100644 --- a/src/plugins/git/gerrit/gerritpushdialog.cpp +++ b/src/plugins/git/gerrit/gerritpushdialog.cpp @@ -70,7 +70,7 @@ QString GerritPushDialog::determineRemoteBranch(const QString &localBranch) QString output; QString error; - if (!GitPlugin::client()->synchronousBranchCmd( + if (!GitPluginPrivate::client()->synchronousBranchCmd( m_workingDir, {"-r", "--contains", earliestCommit + '^'}, &output, &error)) { return QString(); } @@ -79,7 +79,7 @@ QString GerritPushDialog::determineRemoteBranch(const QString &localBranch) QString remoteTrackingBranch; if (localBranch != "HEAD") - remoteTrackingBranch = GitPlugin::client()->synchronousTrackingBranch(m_workingDir, localBranch); + remoteTrackingBranch = GitPluginPrivate::client()->synchronousTrackingBranch(m_workingDir, localBranch); QString remoteBranch; for (const QString &reference : refs) { @@ -103,7 +103,7 @@ void GerritPushDialog::initRemoteBranches() const QString head = "/HEAD"; QString remotesPrefix("refs/remotes/"); - if (!GitPlugin::client()->synchronousForEachRefCmd( + if (!GitPluginPrivate::client()->synchronousForEachRefCmd( m_workingDir, {"--format=%(refname)\t%(committerdate:raw)", remotesPrefix}, &output)) { return; } @@ -187,7 +187,7 @@ QString GerritPushDialog::calculateChangeRange(const QString &branch) QString number; QString error; - GitPlugin::client()->synchronousRevListCmd(m_workingDir, { remote + ".." + branch, "--count" }, + GitPluginPrivate::client()->synchronousRevListCmd(m_workingDir, { remote + ".." + branch, "--count" }, &number, &error); number.chop(1); @@ -304,7 +304,7 @@ QString GerritPushDialog::pushTarget() const void GerritPushDialog::storeTopic() { const QString branch = m_ui->localBranchComboBox->currentText(); - GitPlugin::client()->setConfigValue(m_workingDir, QString("branch.%1.topic").arg(branch), + GitPluginPrivate::client()->setConfigValue(m_workingDir, QString("branch.%1.topic").arg(branch), selectedTopic()); } @@ -317,7 +317,7 @@ void GerritPushDialog::setRemoteBranches(bool includeOld) const QString remoteName = selectedRemoteName(); if (!m_remoteBranches.contains(remoteName)) { const QStringList remoteBranches = - GitPlugin::client()->synchronousRepositoryBranches(remoteName, m_workingDir); + GitPluginPrivate::client()->synchronousRepositoryBranches(remoteName, m_workingDir); for (const QString &branch : remoteBranches) m_remoteBranches.insertMulti(remoteName, qMakePair(branch, QDate())); if (remoteBranches.isEmpty()) { @@ -355,7 +355,7 @@ void GerritPushDialog::updateCommits(int index) { const QString branch = m_ui->localBranchComboBox->itemText(index); m_hasLocalCommits = m_ui->commitView->init(m_workingDir, branch, LogChangeWidget::Silent); - QString topic = GitPlugin::client()->readConfigValue( + QString topic = GitPluginPrivate::client()->readConfigValue( m_workingDir, QString("branch.%1.topic").arg(branch)); if (!topic.isEmpty()) m_ui->topicLineEdit->setText(topic); diff --git a/src/plugins/git/gerrit/gerritremotechooser.cpp b/src/plugins/git/gerrit/gerritremotechooser.cpp index 8e5e7cd882..f7c4d779a6 100644 --- a/src/plugins/git/gerrit/gerritremotechooser.cpp +++ b/src/plugins/git/gerrit/gerritremotechooser.cpp @@ -104,7 +104,7 @@ bool GerritRemoteChooser::updateRemotes(bool forceReload) m_remotes.clear(); QString errorMessage; // Mute errors. We'll just fallback to the defaults const QMap<QString, QString> remotesList = - Git::Internal::GitPlugin::client()->synchronousRemotesList(m_repository, &errorMessage); + Git::Internal::GitPluginPrivate::client()->synchronousRemotesList(m_repository, &errorMessage); for (auto mapIt = remotesList.cbegin(), end = remotesList.cend(); mapIt != end; ++mapIt) { GerritServer server; if (!server.fillFromRemote(mapIt.value(), *m_parameters, forceReload)) diff --git a/src/plugins/git/gerrit/gerritserver.cpp b/src/plugins/git/gerrit/gerritserver.cpp index f642b1f9d6..c47cd281f3 100644 --- a/src/plugins/git/gerrit/gerritserver.cpp +++ b/src/plugins/git/gerrit/gerritserver.cpp @@ -240,7 +240,7 @@ QStringList GerritServer::curlArguments() const int GerritServer::testConnection() { - static GitClient *const client = GitPlugin::client(); + static GitClient *const client = GitPluginPrivate::client(); const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC); const SynchronousProcessResponse resp = client->vcsFullySynchronousExec( QString(), {curlBinary, arguments}, @@ -332,7 +332,7 @@ bool GerritServer::resolveRoot() void GerritServer::resolveVersion(const GerritParameters &p, bool forceReload) { - static GitClient *const client = GitPlugin::client(); + static GitClient *const client = GitPluginPrivate::client(); QSettings *settings = Core::ICore::settings(); const QString fullVersionKey = "Gerrit/" + host + '/' + versionKey; version = settings->value(fullVersionKey).toString(); diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index 2f511e02af..a680b46fc7 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -285,7 +285,7 @@ private: }; GitDiffEditorController::GitDiffEditorController(IDocument *document, const QString &workingDirectory) : - VcsBaseDiffEditorController(document, GitPlugin::client(), workingDirectory), + VcsBaseDiffEditorController(document, GitPluginPrivate::client(), workingDirectory), m_watcher(this), m_decorator(&m_watcher) { @@ -301,7 +301,7 @@ void GitDiffEditorController::updateBranchList() return; const QString workingDirectory = baseDirectory(); - VcsCommand *command = GitPlugin::client()->vcsExec( + VcsCommand *command = GitPluginPrivate::client()->vcsExec( workingDirectory, {"branch", noColorOption, "-a", "--contains", revision}, nullptr, false, 0, workingDirectory); connect(command, &VcsCommand::stdOutText, this, [this](const QString &text) { @@ -376,7 +376,7 @@ QStringList GitDiffEditorController::addHeadWhenCommandInProgress() const // 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 // instead of showing unsupported combined diff format. - GitClient::CommandInProgress commandInProgress = GitPlugin::client()->checkCommandInProgress(workingDirectory()); + GitClient::CommandInProgress commandInProgress = GitPluginPrivate::client()->checkCommandInProgress(workingDirectory()); if (commandInProgress != GitClient::NoCommand) return {HEAD}; return QStringList(); @@ -533,7 +533,7 @@ void ShowController::reload() // stage 1 m_state = GettingDescription; const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id}; - runCommand(QList<QStringList>() << args, GitPlugin::client()->encoding(workingDirectory(), "i18n.commitEncoding")); + runCommand(QList<QStringList>() << args, GitPluginPrivate::client()->encoding(workingDirectory(), "i18n.commitEncoding")); setStartupFile(VcsBase::source(document())); } @@ -541,7 +541,7 @@ void ShowController::processCommandOutput(const QString &output) { QTC_ASSERT(m_state != Idle, return); if (m_state == GettingDescription) { - setDescription(GitPlugin::client()->extendedShowDescription(workingDirectory(), output)); + setDescription(GitPluginPrivate::client()->extendedShowDescription(workingDirectory(), output)); // stage 2 m_state = GettingDiff; const QStringList args = {"show", "--format=format:", // omit header, already generated @@ -680,7 +680,7 @@ private: { // If interactive rebase editor window is closed, plugin is terminated // but referenced here when the command ends - if (GitPlugin *plugin = GitPlugin::instance()) { + if (GitPluginPrivate *plugin = GitPluginPrivate::instance()) { GitClient *client = plugin->client(); if (m_commit.isEmpty() && m_files.isEmpty()) { if (client->checkCommandInProgress(m_workingDirectory) == GitClient::NoCommand) @@ -1324,7 +1324,7 @@ void GitClient::removeStaleRemoteBranches(const QString &workingDirectory, const VcsCommand::ShowSuccessMessage); connect(command, &VcsCommand::success, - this, [workingDirectory]() { GitPlugin::instance()->updateBranches(workingDirectory); }); + this, [workingDirectory]() { GitPluginPrivate::instance()->updateBranches(workingDirectory); }); } void GitClient::recoverDeletedFiles(const QString &workingDirectory) @@ -2277,7 +2277,7 @@ GitClient::CommandInProgress GitClient::checkCommandInProgress(const QString &wo void GitClient::continueCommandIfNeeded(const QString &workingDirectory, bool allowContinue) { - if (GitPlugin::instance()->isCommitEditorOpen()) + if (GitPluginPrivate::instance()->isCommitEditorOpen()) return; CommandInProgress command = checkCommandInProgress(workingDirectory); ContinueCommandMode continueMode; @@ -2350,7 +2350,7 @@ void GitClient::continuePreviousGitCommand(const QString &workingDirectory, if (isRebase) rebase(workingDirectory, QLatin1String(hasChanges ? "--continue" : "--skip")); else - GitPlugin::instance()->startCommit(); + GitPluginPrivate::instance()->startCommit(); } } @@ -2843,7 +2843,7 @@ bool GitClient::addAndCommit(const QString &repositoryDirectory, if (resp.result == SynchronousProcessResponse::Finished) { VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount)); VcsOutputWindow::appendError(stdErr); - GitPlugin::instance()->updateCurrentBranch(); + GitPluginPrivate::instance()->updateCurrentBranch(); return true; } else { VcsOutputWindow::appendError(tr("Cannot commit %n files: %1\n", nullptr, commitCount).arg(stdErr)); @@ -2945,7 +2945,7 @@ void GitClient::revert(const QStringList &files, bool revertStaging) QString errorMessage; switch (revertI(files, &isDirectory, &errorMessage, revertStaging)) { case RevertOk: - GitPlugin::instance()->gitVersionControl()->emitFilesChanged(files); + GitPluginPrivate::instance()->gitVersionControl()->emitFilesChanged(files); break; case RevertCanceled: break; @@ -2966,7 +2966,7 @@ void GitClient::fetch(const QString &workingDirectory, const QString &remote) VcsCommand *command = vcsExec(workingDirectory, arguments, nullptr, true, VcsCommand::ShowSuccessMessage); connect(command, &VcsCommand::success, - this, [workingDirectory]() { GitPlugin::instance()->updateBranches(workingDirectory); }); + this, [workingDirectory]() { GitPluginPrivate::instance()->updateBranches(workingDirectory); }); } bool GitClient::executeAndHandleConflicts(const QString &workingDirectory, @@ -3180,7 +3180,7 @@ void GitClient::push(const QString &workingDirectory, const QStringList &pushArg QStringList({"push", "--force-with-lease"}) + pushArgs, nullptr, true, VcsCommand::ShowSuccessMessage); connect(rePushCommand, &VcsCommand::success, - this, []() { GitPlugin::instance()->updateCurrentBranch(); }); + this, []() { GitPluginPrivate::instance()->updateCurrentBranch(); }); } break; } @@ -3201,13 +3201,13 @@ void GitClient::push(const QString &workingDirectory, const QStringList &pushArg fallbackCommandParts.mid(1), nullptr, true, VcsCommand::ShowSuccessMessage); connect(rePushCommand, &VcsCommand::success, this, [workingDirectory]() { - GitPlugin::instance()->updateBranches(workingDirectory); + GitPluginPrivate::instance()->updateBranches(workingDirectory); }); } break; } } else { - GitPlugin::instance()->updateCurrentBranch(); + GitPluginPrivate::instance()->updateCurrentBranch(); } }); } @@ -3469,7 +3469,7 @@ bool GitClient::StashInfo::init(const QString &workingDirectory, const QString & m_pushAction = pushAction; QString errorMessage; QString statusOutput; - switch (GitPlugin::client()->gitStatus(m_workingDir, StatusMode(NoUntracked | NoSubmodules), + switch (GitPluginPrivate::client()->gitStatus(m_workingDir, StatusMode(NoUntracked | NoSubmodules), &statusOutput, &errorMessage)) { case GitClient::StatusChanged: if (m_flags & NoPrompt) @@ -3522,14 +3522,14 @@ void GitClient::StashInfo::stashPrompt(const QString &command, const QString &st msgBox.exec(); if (msgBox.clickedButton() == discardButton) { - m_stashResult = GitPlugin::client()->synchronousReset(m_workingDir, QStringList(), errorMessage) ? + m_stashResult = GitPluginPrivate::client()->synchronousReset(m_workingDir, QStringList(), errorMessage) ? StashUnchanged : StashFailed; } else if (msgBox.clickedButton() == ignoreButton) { // At your own risk, so. m_stashResult = NotStashed; } else if (msgBox.clickedButton() == cancelButton) { m_stashResult = StashCanceled; } else if (msgBox.clickedButton() == stashButton) { - const bool result = GitPlugin::client()->executeSynchronousStash( + const bool result = GitPluginPrivate::client()->executeSynchronousStash( m_workingDir, creatorStashMessage(command), false, errorMessage); m_stashResult = result ? StashUnchanged : StashFailed; } else if (msgBox.clickedButton() == stashAndPopButton) { @@ -3540,7 +3540,7 @@ void GitClient::StashInfo::stashPrompt(const QString &command, const QString &st void GitClient::StashInfo::executeStash(const QString &command, QString *errorMessage) { m_message = creatorStashMessage(command); - if (!GitPlugin::client()->executeSynchronousStash(m_workingDir, m_message, false, errorMessage)) + if (!GitPluginPrivate::client()->executeSynchronousStash(m_workingDir, m_message, false, errorMessage)) m_stashResult = StashFailed; else m_stashResult = Stashed; @@ -3563,14 +3563,14 @@ void GitClient::StashInfo::end() { if (m_stashResult == Stashed) { QString stashName; - if (GitPlugin::client()->stashNameFromMessage(m_workingDir, m_message, &stashName)) - GitPlugin::client()->stashPop(m_workingDir, stashName); + if (GitPluginPrivate::client()->stashNameFromMessage(m_workingDir, m_message, &stashName)) + GitPluginPrivate::client()->stashPop(m_workingDir, stashName); } if (m_pushAction == NormalPush) - GitPlugin::client()->push(m_workingDir); + GitPluginPrivate::client()->push(m_workingDir); else if (m_pushAction == PushToGerrit) - GitPlugin::instance()->gerritPlugin()->push(m_workingDir); + GitPluginPrivate::instance()->gerritPlugin()->push(m_workingDir); m_pushAction = NoPush; m_stashResult = NotStashed; diff --git a/src/plugins/git/giteditor.cpp b/src/plugins/git/giteditor.cpp index 670d8986c4..53b41479e6 100644 --- a/src/plugins/git/giteditor.cpp +++ b/src/plugins/git/giteditor.cpp @@ -126,7 +126,7 @@ static QString sanitizeBlameOutput(const QString &b) if (b.isEmpty()) return b; - const bool omitDate = GitPlugin::client()->settings().boolValue( + const bool omitDate = GitPluginPrivate::client()->settings().boolValue( GitSettings::omitAnnotationDateKey); const QChar space(' '); const int parenPos = b.indexOf(')'); @@ -192,7 +192,7 @@ void GitEditorWidget::setPlainText(const QString &text) void GitEditorWidget::resetChange(const QByteArray &resetType) { - GitPlugin::client()->reset( + GitPluginPrivate::client()->reset( sourceWorkingDirectory(), QLatin1String("--" + resetType), m_currentChange); } @@ -211,7 +211,7 @@ void GitEditorWidget::applyDiffChunk(const DiffChunk& chunk, bool revert) if (revert) args << "--reverse"; QString errorMessage; - if (GitPlugin::client()->synchronousApplyPatch(baseDir, patchFile.fileName(), &errorMessage, args)) { + if (GitPluginPrivate::client()->synchronousApplyPatch(baseDir, patchFile.fileName(), &errorMessage, args)) { if (errorMessage.isEmpty()) VcsOutputWindow::append(tr("Chunk successfully staged")); else @@ -260,14 +260,14 @@ void GitEditorWidget::aboutToOpen(const QString &fileName, const QString &realFi const QString gitPath = fi.absolutePath(); setSource(gitPath); textDocument()->setCodec( - GitPlugin::client()->encoding(gitPath, "i18n.commitEncoding")); + GitPluginPrivate::client()->encoding(gitPath, "i18n.commitEncoding")); } } QString GitEditorWidget::decorateVersion(const QString &revision) const { // Format verbose, SHA1 being first token - return GitPlugin::client()->synchronousShortDescription(sourceWorkingDirectory(), revision); + return GitPluginPrivate::client()->synchronousShortDescription(sourceWorkingDirectory(), revision); } QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision) const @@ -275,7 +275,7 @@ QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision) QStringList revisions; QString errorMessage; // Get the SHA1's of the file. - if (!GitPlugin::client()->synchronousParentRevisions(sourceWorkingDirectory(), + if (!GitPluginPrivate::client()->synchronousParentRevisions(sourceWorkingDirectory(), revision, &revisions, &errorMessage)) { VcsOutputWindow::appendSilently(errorMessage); return QStringList(); @@ -285,7 +285,7 @@ QStringList GitEditorWidget::annotationPreviousVersions(const QString &revision) bool GitEditorWidget::isValidRevision(const QString &revision) const { - return GitPlugin::client()->isValidRevision(revision); + return GitPluginPrivate::client()->isValidRevision(revision); } void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change) @@ -295,25 +295,25 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change) return; menu->addAction(tr("Cherr&y-Pick Change %1").arg(change), this, [this] { - GitPlugin::client()->synchronousCherryPick(sourceWorkingDirectory(), m_currentChange); + GitPluginPrivate::client()->synchronousCherryPick(sourceWorkingDirectory(), m_currentChange); }); menu->addAction(tr("Re&vert Change %1").arg(change), this, [this] { - GitPlugin::client()->synchronousRevert(sourceWorkingDirectory(), m_currentChange); + GitPluginPrivate::client()->synchronousRevert(sourceWorkingDirectory(), m_currentChange); }); menu->addAction(tr("C&heckout Change %1").arg(change), this, [this] { - GitPlugin::client()->checkout(sourceWorkingDirectory(), m_currentChange); + GitPluginPrivate::client()->checkout(sourceWorkingDirectory(), m_currentChange); }); connect(menu->addAction(tr("&Interactive Rebase from Change %1...").arg(change)), &QAction::triggered, this, [this] { - GitPlugin::instance()->startRebaseFromCommit(sourceWorkingDirectory(), m_currentChange); + GitPluginPrivate::instance()->startRebaseFromCommit(sourceWorkingDirectory(), m_currentChange); }); menu->addAction(tr("&Log for Change %1").arg(change), this, [this] { - GitPlugin::client()->log(sourceWorkingDirectory(), QString(), false, {m_currentChange}); + GitPluginPrivate::client()->log(sourceWorkingDirectory(), QString(), false, {m_currentChange}); }); menu->addAction(tr("Add &Tag for Change %1...").arg(change), this, [this] { QString output; QString errorMessage; - GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(), QStringList(), + GitPluginPrivate::client()->synchronousTagCmd(sourceWorkingDirectory(), QStringList(), &output, &errorMessage); const QStringList tags = output.split('\n'); @@ -322,7 +322,7 @@ void GitEditorWidget::addChangeActions(QMenu *menu, const QString &change) if (dialog.exec() == QDialog::Rejected) return; - GitPlugin::client()->synchronousTagCmd(sourceWorkingDirectory(), + GitPluginPrivate::client()->synchronousTagCmd(sourceWorkingDirectory(), {dialog.branchName(), m_currentChange}, &output, &errorMessage); VcsOutputWindow::append(output); diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp index 056903f855..35fd7abc64 100644 --- a/src/plugins/git/gitgrep.cpp +++ b/src/plugins/git/gitgrep.cpp @@ -158,7 +158,7 @@ public: void exec() { - GitClient *client = GitPlugin::client(); + GitClient *client = GitPluginPrivate::client(); QStringList arguments = { "-c", "color.grep.match=bold red", "-c", "color.grep=always", @@ -248,7 +248,7 @@ GitGrep::GitGrep(QObject *parent) const QRegularExpression refExpression("[\\S]*"); m_treeLineEdit->setValidator(new QRegularExpressionValidator(refExpression, this)); layout->addWidget(m_treeLineEdit); - if (GitPlugin::client()->gitVersion() >= 0x021300) { + if (GitPluginPrivate::client()->gitVersion() >= 0x021300) { m_recurseSubmodules = new QCheckBox(tr("Recurse submodules")); layout->addWidget(m_recurseSubmodules); } @@ -320,7 +320,7 @@ IEditor *GitGrep::openEditor(const SearchResultItem &item, QByteArray content; const QString topLevel = parameters.additionalParameters.toString(); const QString relativePath = QDir(topLevel).relativeFilePath(path); - if (!GitPlugin::client()->synchronousShow(topLevel, params.ref + ":./" + relativePath, + if (!GitPluginPrivate::client()->synchronousShow(topLevel, params.ref + ":./" + relativePath, &content, nullptr)) { return nullptr; } diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index 3f08a20760..9779a5cb45 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -129,25 +129,23 @@ const VcsBaseEditorParameters editorParameters[] = { // GitPlugin -static GitPlugin *m_instance = nullptr; +static GitPluginPrivate *dd = nullptr; -GitPlugin::GitPlugin() +GitPluginPrivate::~GitPluginPrivate() { - m_instance = this; - m_fileActions.reserve(10); - m_projectActions.reserve(10); - m_repositoryActions.reserve(50); + cleanCommitMessageFile(); + delete m_gitClient; + delete m_branchViewFactory; } + GitPlugin::~GitPlugin() { - cleanCommitMessageFile(); - delete m_gitClient; - delete m_branchViewFactory; - m_instance = nullptr; + delete dd; + dd = nullptr; } -void GitPlugin::cleanCommitMessageFile() +void GitPluginPrivate::cleanCommitMessageFile() { if (!m_commitMessageFileName.isEmpty()) { QFile::remove(m_commitMessageFileName); @@ -155,22 +153,22 @@ void GitPlugin::cleanCommitMessageFile() } } -bool GitPlugin::isCommitEditorOpen() const +bool GitPluginPrivate::isCommitEditorOpen() const { return !m_commitMessageFileName.isEmpty(); } -GitPlugin *GitPlugin::instance() +GitPluginPrivate *GitPluginPrivate::instance() { - return m_instance; + return dd; } -GitClient *GitPlugin::client() +GitClient *GitPluginPrivate::client() { - return m_instance->m_gitClient; + return dd->m_gitClient; } -QString GitPlugin::msgRepositoryLabel(const QString &repository) +QString GitPluginPrivate::msgRepositoryLabel(const QString &repository) { return repository.isEmpty() ? tr("<No repository>") : @@ -179,7 +177,7 @@ QString GitPlugin::msgRepositoryLabel(const QString &repository) // Returns a regular expression pattern with characters not allowed // in branch and remote names. -QString GitPlugin::invalidBranchAndRemoteNamePattern() +QString GitPluginPrivate::invalidBranchAndRemoteNamePattern() { return QLatin1String( "\\s" // no whitespace @@ -206,7 +204,7 @@ const VcsBaseSubmitEditorParameters submitParameters = { VcsBaseSubmitEditorParameters::DiffRows }; -Command *GitPlugin::createCommand(QAction *action, ActionContainer *ac, Id id, +Command *GitPluginPrivate::createCommand(QAction *action, ActionContainer *ac, Id id, const Context &context, bool addToLocator, const std::function<void()> &callback, const QKeySequence &keys) { @@ -222,7 +220,7 @@ Command *GitPlugin::createCommand(QAction *action, ActionContainer *ac, Id id, } // Create a parameter action -ParameterAction *GitPlugin::createParameterAction(ActionContainer *ac, +ParameterAction *GitPluginPrivate::createParameterAction(ActionContainer *ac, const QString &defaultText, const QString ¶meterText, Id id, const Context &context, bool addToLocator, const std::function<void()> &callback, @@ -235,7 +233,7 @@ ParameterAction *GitPlugin::createParameterAction(ActionContainer *ac, } // Create an action to act on a file. -QAction *GitPlugin::createFileAction(ActionContainer *ac, +QAction *GitPluginPrivate::createFileAction(ActionContainer *ac, const QString &defaultText, const QString ¶meterText, Id id, const Context &context, bool addToLocator, const std::function<void()> &callback, @@ -247,9 +245,9 @@ QAction *GitPlugin::createFileAction(ActionContainer *ac, return action; } -QAction *GitPlugin::createProjectAction(ActionContainer *ac, const QString &defaultText, +QAction *GitPluginPrivate::createProjectAction(ActionContainer *ac, const QString &defaultText, const QString ¶meterText, Id id, const Context &context, - bool addToLocator, void (GitPlugin::*func)(), + bool addToLocator, void (GitPluginPrivate::*func)(), const QKeySequence &keys) { ParameterAction *action = createParameterAction(ac, defaultText, parameterText, id, context, @@ -259,7 +257,7 @@ QAction *GitPlugin::createProjectAction(ActionContainer *ac, const QString &defa } // Create an action to act on the repository -QAction *GitPlugin::createRepositoryAction(ActionContainer *ac, const QString &text, Id id, +QAction *GitPluginPrivate::createRepositoryAction(ActionContainer *ac, const QString &text, Id id, const Context &context, bool addToLocator, const std::function<void()> &callback, const QKeySequence &keys) @@ -270,17 +268,17 @@ QAction *GitPlugin::createRepositoryAction(ActionContainer *ac, const QString &t return action; } -QAction *GitPlugin::createChangeRelatedRepositoryAction(const QString &text, Id id, +QAction *GitPluginPrivate::createChangeRelatedRepositoryAction(const QString &text, Id id, const Context &context) { return createRepositoryAction(nullptr, text, id, context, true, - std::bind(&GitPlugin::startChangeRelatedAction, this, id), + std::bind(&GitPluginPrivate::startChangeRelatedAction, this, id), QKeySequence()); } // Action to act on the repository forwarded to a git client member function // taking the directory. -QAction *GitPlugin::createRepositoryAction(ActionContainer *ac, const QString &text, Id id, +QAction *GitPluginPrivate::createRepositoryAction(ActionContainer *ac, const QString &text, Id id, const Context &context, bool addToLocator, GitClientMemberFunc func, const QKeySequence &keys) { @@ -296,6 +294,29 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) { Q_UNUSED(errorMessage) + dd = new GitPluginPrivate; + + auto cmdContext = new QObject(this); + connect(Core::ICore::instance(), &Core::ICore::coreOpened, cmdContext, [this, cmdContext, arguments] { + remoteCommand(arguments, QDir::currentPath(), {}); + cmdContext->deleteLater(); + }); + + return true; +} + +void GitPlugin::extensionsInitialized() +{ + dd->extensionsInitialized() ; +} + +GitPluginPrivate::GitPluginPrivate() +{ + dd = this; + m_fileActions.reserve(10); + m_projectActions.reserve(10); + m_repositoryActions.reserve(50); + Context context(Constants::GIT_CONTEXT); m_gitClient = new GitClient; @@ -306,7 +327,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) // Create the settings Page auto settingsPage = new SettingsPage(vc, this); connect(settingsPage, &SettingsPage::settingsChanged, - this, &GitPlugin::updateRepositoryBrowserAction); + this, &GitPluginPrivate::updateRepositoryBrowserAction); new GitGrep(this); m_branchViewFactory = new BranchViewFactory; @@ -340,33 +361,33 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) gitContainer->addMenu(currentFileMenu); createFileAction(currentFileMenu, tr("Diff Current File"), tr("Diff of \"%1\""), - "Git.Diff", context, true, std::bind(&GitPlugin::diffCurrentFile, this), + "Git.Diff", context, true, std::bind(&GitPluginPrivate::diffCurrentFile, this), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+D") : tr("Alt+G,Alt+D"))); createFileAction(currentFileMenu, tr("Log Current File"), tr("Log of \"%1\""), - "Git.Log", context, true, std::bind(&GitPlugin::logFile, this), + "Git.Log", context, true, std::bind(&GitPluginPrivate::logFile, this), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+L") : tr("Alt+G,Alt+L"))); createFileAction(currentFileMenu, tr("Blame Current File"), tr("Blame for \"%1\""), - "Git.Blame", context, true, std::bind(&GitPlugin::blameFile, this), + "Git.Blame", context, true, std::bind(&GitPluginPrivate::blameFile, this), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+B") : tr("Alt+G,Alt+B"))); currentFileMenu->addSeparator(context); createFileAction(currentFileMenu, tr("Stage File for Commit"), tr("Stage \"%1\" for Commit"), - "Git.Stage", context, true, std::bind(&GitPlugin::stageFile, this), + "Git.Stage", context, true, std::bind(&GitPluginPrivate::stageFile, this), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+A") : tr("Alt+G,Alt+A"))); createFileAction(currentFileMenu, tr("Unstage File from Commit"), tr("Unstage \"%1\" from Commit"), - "Git.Unstage", context, true, std::bind(&GitPlugin::unstageFile, this)); + "Git.Unstage", context, true, std::bind(&GitPluginPrivate::unstageFile, this)); createFileAction(currentFileMenu, tr("Undo Unstaged Changes"), tr("Undo Unstaged Changes for \"%1\""), "Git.UndoUnstaged", context, - true, std::bind(&GitPlugin::undoFileChanges, this, false)); + true, std::bind(&GitPluginPrivate::undoFileChanges, this, false)); createFileAction(currentFileMenu, tr("Undo Uncommitted Changes"), tr("Undo Uncommitted Changes for \"%1\""), "Git.Undo", context, - true, std::bind(&GitPlugin::undoFileChanges, this, true), + true, std::bind(&GitPluginPrivate::undoFileChanges, this, true), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+U") : tr("Alt+G,Alt+U"))); @@ -376,15 +397,15 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) gitContainer->addMenu(currentProjectMenu); createProjectAction(currentProjectMenu, tr("Diff Current Project"), tr("Diff Project \"%1\""), - "Git.DiffProject", context, true, &GitPlugin::diffCurrentProject, + "Git.DiffProject", context, true, &GitPluginPrivate::diffCurrentProject, QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+Shift+D") : tr("Alt+G,Alt+Shift+D"))); createProjectAction(currentProjectMenu, tr("Log Project"), tr("Log Project \"%1\""), - "Git.LogProject", context, true, &GitPlugin::logProject, + "Git.LogProject", context, true, &GitPluginPrivate::logProject, QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+K") : tr("Alt+G,Alt+K"))); createProjectAction(currentProjectMenu, tr("Clean Project..."), tr("Clean Project \"%1\"..."), - "Git.CleanProject", context, true, &GitPlugin::cleanProject); + "Git.CleanProject", context, true, &GitPluginPrivate::cleanProject); /* "Local Repository" menu */ @@ -396,7 +417,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) context, true, &GitClient::diffRepository); createRepositoryAction(localRepositoryMenu, tr("Log"), "Git.LogRepository", - context, true, std::bind(&GitPlugin::logRepository, this)); + context, true, std::bind(&GitPluginPrivate::logRepository, this)); createRepositoryAction(localRepositoryMenu, tr("Reflog"), "Git.ReflogRepository", context, true, &GitClient::reflog); @@ -411,88 +432,88 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) localRepositoryMenu->addSeparator(context); createRepositoryAction(localRepositoryMenu, tr("Commit..."), "Git.Commit", - context, true, std::bind(&GitPlugin::startCommit, this, SimpleCommit), + context, true, std::bind(&GitPluginPrivate::startCommit, this, SimpleCommit), QKeySequence(useMacShortcuts ? tr("Meta+G,Meta+C") : tr("Alt+G,Alt+C"))); createRepositoryAction(localRepositoryMenu, tr("Amend Last Commit..."), "Git.AmendCommit", - context, true, std::bind(&GitPlugin::startCommit, this, AmendCommit)); + context, true, std::bind(&GitPluginPrivate::startCommit, this, AmendCommit)); m_fixupCommitAction = createRepositoryAction(localRepositoryMenu, tr("Fixup Previous Commit..."), "Git.FixupCommit", context, true, - std::bind(&GitPlugin::startCommit, this, FixupCommit)); + std::bind(&GitPluginPrivate::startCommit, this, FixupCommit)); // -------------- localRepositoryMenu->addSeparator(context); createRepositoryAction(localRepositoryMenu, tr("Reset..."), "Git.Reset", - context, true, std::bind(&GitPlugin::resetRepository, this)); + context, true, std::bind(&GitPluginPrivate::resetRepository, this)); createRepositoryAction(localRepositoryMenu, tr("Recover Deleted Files"), "Git.RecoverDeleted", - context, true, std::bind(&GitPlugin::recoverDeletedFiles, this)); + context, true, std::bind(&GitPluginPrivate::recoverDeletedFiles, this)); m_interactiveRebaseAction = createRepositoryAction(localRepositoryMenu, tr("Interactive Rebase..."), "Git.InteractiveRebase", - context, true, std::bind(&GitPlugin::startRebase, this)); + context, true, std::bind(&GitPluginPrivate::startRebase, this)); m_submoduleUpdateAction = createRepositoryAction(localRepositoryMenu, tr("Update Submodules"), "Git.SubmoduleUpdate", - context, true, std::bind(&GitPlugin::updateSubmodules, this)); + context, true, std::bind(&GitPluginPrivate::updateSubmodules, this)); m_abortMergeAction = createRepositoryAction(localRepositoryMenu, tr("Abort Merge"), "Git.MergeAbort", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_abortRebaseAction = createRepositoryAction(localRepositoryMenu, tr("Abort Rebase"), "Git.RebaseAbort", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_abortCherryPickAction = createRepositoryAction(localRepositoryMenu, tr("Abort Cherry Pick"), "Git.CherryPickAbort", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_abortRevertAction = createRepositoryAction(localRepositoryMenu, tr("Abort Revert"), "Git.RevertAbort", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_continueRebaseAction = createRepositoryAction(localRepositoryMenu, tr("Continue Rebase"), "Git.RebaseContinue", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_skipRebaseAction = createRepositoryAction(localRepositoryMenu, tr("Skip Rebase"), "Git.RebaseSkip", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_continueCherryPickAction = createRepositoryAction(localRepositoryMenu, tr("Continue Cherry Pick"), "Git.CherryPickContinue", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); m_continueRevertAction = createRepositoryAction(localRepositoryMenu, tr("Continue Revert"), "Git.RevertContinue", context, true, - std::bind(&GitPlugin::continueOrAbortCommand, this)); + std::bind(&GitPluginPrivate::continueOrAbortCommand, this)); // -------------- localRepositoryMenu->addSeparator(context); createRepositoryAction(localRepositoryMenu, tr("Branches..."), "Git.BranchList", - context, true, std::bind(&GitPlugin::branchList, this)); + context, true, std::bind(&GitPluginPrivate::branchList, this)); // -------------- localRepositoryMenu->addSeparator(context); @@ -507,9 +528,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) = createParameterAction(patchMenu, tr("Apply from Editor"), tr("Apply \"%1\""), "Git.ApplyCurrentFilePatch", - context, true, std::bind(&GitPlugin::applyCurrentFilePatch, this)); + context, true, std::bind(&GitPluginPrivate::applyCurrentFilePatch, this)); createRepositoryAction(patchMenu, tr("Apply from File..."), "Git.ApplyPatch", - context, true, std::bind(&GitPlugin::promptApplyPatch, this)); + context, true, std::bind(&GitPluginPrivate::promptApplyPatch, this)); // "Stash" menu ActionContainer *stashMenu = ActionManager::createMenu("Git.StashMenu"); @@ -517,27 +538,27 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) localRepositoryMenu->addMenu(stashMenu); createRepositoryAction(stashMenu, tr("Stashes..."), "Git.StashList", - context, false, std::bind(&GitPlugin::stashList, this)); + context, false, std::bind(&GitPluginPrivate::stashList, this)); stashMenu->addSeparator(context); QAction *action = createRepositoryAction(stashMenu, tr("Stash"), "Git.Stash", - context, true, std::bind(&GitPlugin::stash, this, false)); + context, true, std::bind(&GitPluginPrivate::stash, this, false)); action->setToolTip(tr("Saves the current state of your work and resets the repository.")); action = createRepositoryAction(stashMenu, tr("Stash Unstaged Files"), "Git.StashUnstaged", - context, true, std::bind(&GitPlugin::stashUnstaged, this)); + context, true, std::bind(&GitPluginPrivate::stashUnstaged, this)); action->setToolTip(tr("Saves the current state of your unstaged files and resets the repository " "to its staged state.")); action = createRepositoryAction(stashMenu, tr("Take Snapshot..."), "Git.StashSnapshot", - context, true, std::bind(&GitPlugin::stashSnapshot, this)); + context, true, std::bind(&GitPluginPrivate::stashSnapshot, this)); action->setToolTip(tr("Saves the current state of your work.")); stashMenu->addSeparator(context); action = createRepositoryAction(stashMenu, tr("Stash Pop"), "Git.StashPop", - context, true, std::bind(&GitPlugin::stashPop, this)); + context, true, std::bind(&GitPluginPrivate::stashPop, this)); action->setToolTip(tr("Restores changes saved to the stash list using \"Stash\".")); @@ -551,13 +572,13 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) gitContainer->addMenu(remoteRepositoryMenu); createRepositoryAction(remoteRepositoryMenu, tr("Fetch"), "Git.Fetch", - context, true, std::bind(&GitPlugin::fetch, this)); + context, true, std::bind(&GitPluginPrivate::fetch, this)); createRepositoryAction(remoteRepositoryMenu, tr("Pull"), "Git.Pull", - context, true, std::bind(&GitPlugin::pull, this)); + context, true, std::bind(&GitPluginPrivate::pull, this)); createRepositoryAction(remoteRepositoryMenu, tr("Push"), "Git.Push", - context, true, std::bind(&GitPlugin::push, this)); + context, true, std::bind(&GitPluginPrivate::push, this)); // -------------- remoteRepositoryMenu->addSeparator(context); @@ -580,7 +601,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) remoteRepositoryMenu->addSeparator(context); createRepositoryAction(remoteRepositoryMenu, tr("Manage Remotes..."), "Git.RemoteList", - context, false, std::bind(&GitPlugin::manageRemotes, this)); + context, false, std::bind(&GitPluginPrivate::manageRemotes, this)); /* \"Remote Repository" menu */ @@ -594,9 +615,9 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) createChangeRelatedRepositoryAction(tr("Archive..."), "Git.Archive", context); createRepositoryAction(nullptr, tr("Rebase..."), "Git.Rebase", context, true, - std::bind(&GitPlugin::branchList, this)); + std::bind(&GitPluginPrivate::branchList, this)); createRepositoryAction(nullptr, tr("Merge..."), "Git.Merge", context, true, - std::bind(&GitPlugin::branchList, this)); + std::bind(&GitPluginPrivate::branchList, this)); /* \Actions only in locator */ // -------------- @@ -610,16 +631,16 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) context, true, &GitClient::launchGitK); createFileAction(gitToolsMenu, tr("Gitk Current File"), tr("Gitk of \"%1\""), - "Git.GitkFile", context, true, std::bind(&GitPlugin::gitkForCurrentFile, this)); + "Git.GitkFile", context, true, std::bind(&GitPluginPrivate::gitkForCurrentFile, this)); createFileAction(gitToolsMenu, tr("Gitk for folder of Current File"), tr("Gitk for folder of \"%1\""), - "Git.GitkFolder", context, true, std::bind(&GitPlugin::gitkForCurrentFolder, this)); + "Git.GitkFolder", context, true, std::bind(&GitPluginPrivate::gitkForCurrentFolder, this)); // -------------- gitToolsMenu->addSeparator(context); createRepositoryAction(gitToolsMenu, tr("Git Gui"), "Git.GitGui", - context, true, std::bind(&GitPlugin::gitGui, this)); + context, true, std::bind(&GitPluginPrivate::gitGui, this)); // -------------- gitToolsMenu->addSeparator(context); @@ -631,7 +652,7 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) m_mergeToolAction = createRepositoryAction(gitToolsMenu, tr("Merge Tool"), "Git.MergeTool", - context, true, std::bind(&GitPlugin::startMergeTool, this)); + context, true, std::bind(&GitPluginPrivate::startMergeTool, this)); /* \"Git Tools" menu */ @@ -648,42 +669,34 @@ bool GitPlugin::initialize(const QStringList &arguments, QString *errorMessage) QAction *createRepositoryAction = new QAction(tr("Create Repository..."), this); Command *createRepositoryCommand = ActionManager::registerAction( createRepositoryAction, "Git.CreateRepository"); - connect(createRepositoryAction, &QAction::triggered, this, &GitPlugin::createRepository); + connect(createRepositoryAction, &QAction::triggered, this, &GitPluginPrivate::createRepository); gitContainer->addAction(createRepositoryCommand); connect(VcsManager::instance(), &VcsManager::repositoryChanged, - this, &GitPlugin::updateContinueAndAbortCommands); + this, &GitPluginPrivate::updateContinueAndAbortCommands); connect(VcsManager::instance(), &VcsManager::repositoryChanged, - this, &GitPlugin::updateBranches, Qt::QueuedConnection); + this, &GitPluginPrivate::updateBranches, Qt::QueuedConnection); /* "Gerrit" */ m_gerritPlugin = new Gerrit::Internal::GerritPlugin(this); - const bool ok = m_gerritPlugin->initialize(remoteRepositoryMenu); + m_gerritPlugin->initialize(remoteRepositoryMenu); m_gerritPlugin->updateActions(currentState()); m_gerritPlugin->addToLocator(m_commandLocator); - - auto cmdContext = new QObject(this); - connect(Core::ICore::instance(), &Core::ICore::coreOpened, cmdContext, [this, cmdContext, arguments] { - remoteCommand(arguments, QDir::currentPath(), {}); - cmdContext->deleteLater(); - }); - - return ok; } -GitVersionControl *GitPlugin::gitVersionControl() const +GitVersionControl *GitPluginPrivate::gitVersionControl() const { return static_cast<GitVersionControl *>(versionControl()); } -void GitPlugin::diffCurrentFile() +void GitPluginPrivate::diffCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); m_gitClient->diffFile(state.currentFileTopLevel(), state.relativeCurrentFile()); } -void GitPlugin::diffCurrentProject() +void GitPluginPrivate::diffCurrentProject() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasProject(), return); @@ -694,14 +707,14 @@ void GitPlugin::diffCurrentProject() m_gitClient->diffProject(state.currentProjectTopLevel(), relativeProject); } -void GitPlugin::logFile() +void GitPluginPrivate::logFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); m_gitClient->log(state.currentFileTopLevel(), state.relativeCurrentFile(), true); } -void GitPlugin::blameFile() +void GitPluginPrivate::blameFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); @@ -740,21 +753,21 @@ void GitPlugin::blameFile() editor->setFirstLineNumber(firstLine); } -void GitPlugin::logProject() +void GitPluginPrivate::logProject() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasProject(), return); m_gitClient->log(state.currentProjectTopLevel(), state.relativeCurrentProject()); } -void GitPlugin::logRepository() +void GitPluginPrivate::logRepository() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); m_gitClient->log(state.topLevel()); } -void GitPlugin::undoFileChanges(bool revertStaging) +void GitPluginPrivate::undoFileChanges(bool revertStaging) { if (IDocument *document = EditorManager::currentDocument()) { if (!DocumentManager::saveModifiedDocumentSilently(document)) @@ -793,7 +806,7 @@ protected: } }; -void GitPlugin::resetRepository() +void GitPluginPrivate::resetRepository() { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -808,7 +821,7 @@ void GitPlugin::resetRepository() m_gitClient->reset(topLevel, dialog.resetFlag(), dialog.commit()); } -void GitPlugin::recoverDeletedFiles() +void GitPluginPrivate::recoverDeletedFiles() { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -817,7 +830,7 @@ void GitPlugin::recoverDeletedFiles() m_gitClient->recoverDeletedFiles(state.topLevel()); } -void GitPlugin::startRebase() +void GitPluginPrivate::startRebase() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); @@ -826,7 +839,7 @@ void GitPlugin::startRebase() startRebaseFromCommit(topLevel, QString()); } -void GitPlugin::startRebaseFromCommit(const QString &workingDirectory, QString commit) +void GitPluginPrivate::startRebaseFromCommit(const QString &workingDirectory, QString commit) { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -846,7 +859,7 @@ void GitPlugin::startRebaseFromCommit(const QString &workingDirectory, QString c m_gitClient->interactiveRebase(workingDirectory, commit, false); } -void GitPlugin::startChangeRelatedAction(const Id &id) +void GitPluginPrivate::startChangeRelatedAction(const Id &id) { const VcsBasePluginState state = currentState(); @@ -890,28 +903,28 @@ void GitPlugin::startChangeRelatedAction(const Id &id) } } -void GitPlugin::stageFile() +void GitPluginPrivate::stageFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); m_gitClient->addFile(state.currentFileTopLevel(), state.relativeCurrentFile()); } -void GitPlugin::unstageFile() +void GitPluginPrivate::unstageFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); m_gitClient->synchronousReset(state.currentFileTopLevel(), {state.relativeCurrentFile()}); } -void GitPlugin::gitkForCurrentFile() +void GitPluginPrivate::gitkForCurrentFile() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); m_gitClient->launchGitK(state.currentFileTopLevel(), state.relativeCurrentFile()); } -void GitPlugin::gitkForCurrentFolder() +void GitPluginPrivate::gitkForCurrentFolder() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasFile(), return); @@ -941,14 +954,14 @@ void GitPlugin::gitkForCurrentFolder() } } -void GitPlugin::gitGui() +void GitPluginPrivate::gitGui() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); m_gitClient->launchGitGui(state.topLevel()); } -void GitPlugin::startCommit(CommitType commitType) +void GitPluginPrivate::startCommit(CommitType commitType) { if (!promptBeforeCommit()) return; @@ -987,7 +1000,7 @@ void GitPlugin::startCommit(CommitType commitType) openSubmitEditor(m_commitMessageFileName, data); } -void GitPlugin::updateVersionWarning() +void GitPluginPrivate::updateVersionWarning() { unsigned version = m_gitClient->gitVersion(); if (!version || version >= minimumRequiredVersion) @@ -1005,7 +1018,7 @@ void GitPlugin::updateVersionWarning() InfoBarEntry::GlobalSuppression::Enabled)); } -IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &cd) +IEditor *GitPluginPrivate::openSubmitEditor(const QString &fileName, const CommitData &cd) { IEditor *editor = EditorManager::openEditor(fileName, Constants::GITSUBMITEDITOR_ID); auto submitEditor = qobject_cast<GitSubmitEditor*>(editor); @@ -1030,7 +1043,7 @@ IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData & return editor; } -void GitPlugin::commitFromEditor() +void GitPluginPrivate::commitFromEditor() { // Close the submit editor m_submitActionTriggered = true; @@ -1038,7 +1051,7 @@ void GitPlugin::commitFromEditor() EditorManager::closeDocument(submitEditor()->document()); } -bool GitPlugin::submitEditorAboutToClose() +bool GitPluginPrivate::submitEditorAboutToClose() { if (!isCommitEditorOpen()) return true; @@ -1096,7 +1109,7 @@ bool GitPlugin::submitEditorAboutToClose() if (editor->panelData().pushAction == NormalPush) { m_gitClient->push(m_submitRepository); } else if (editor->panelData().pushAction == PushToGerrit) { - connect(editor, &QObject::destroyed, this, &GitPlugin::delayedPushToGerrit, + connect(editor, &QObject::destroyed, this, &GitPluginPrivate::delayedPushToGerrit, Qt::QueuedConnection); } } @@ -1104,12 +1117,12 @@ bool GitPlugin::submitEditorAboutToClose() return true; } -void GitPlugin::fetch() +void GitPluginPrivate::fetch() { m_gitClient->fetch(currentState().topLevel(), QString()); } -void GitPlugin::pull() +void GitPluginPrivate::pull() { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -1132,21 +1145,21 @@ void GitPlugin::pull() m_gitClient->pull(topLevel, rebase); } -void GitPlugin::push() +void GitPluginPrivate::push() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); m_gitClient->push(state.topLevel()); } -void GitPlugin::startMergeTool() +void GitPluginPrivate::startMergeTool() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); m_gitClient->merge(state.topLevel()); } -void GitPlugin::continueOrAbortCommand() +void GitPluginPrivate::continueOrAbortCommand() { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -1174,21 +1187,21 @@ void GitPlugin::continueOrAbortCommand() updateContinueAndAbortCommands(); } -void GitPlugin::cleanProject() +void GitPluginPrivate::cleanProject() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasProject(), return); cleanRepository(state.currentProjectPath()); } -void GitPlugin::cleanRepository() +void GitPluginPrivate::cleanRepository() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); cleanRepository(state.topLevel()); } -void GitPlugin::cleanRepository(const QString &directory) +void GitPluginPrivate::cleanRepository(const QString &directory) { // Find files to be deleted QString errorMessage; @@ -1214,7 +1227,7 @@ void GitPlugin::cleanRepository(const QString &directory) dialog.exec(); } -void GitPlugin::updateSubmodules() +void GitPluginPrivate::updateSubmodules() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); @@ -1227,7 +1240,7 @@ static bool ensureFileSaved(const QString &fileName) return DocumentManager::saveModifiedDocument(DocumentModel::documentForFilePath(fileName)); } -void GitPlugin::applyCurrentFilePatch() +void GitPluginPrivate::applyCurrentFilePatch() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasPatchFile() && state.hasTopLevel(), return); @@ -1237,14 +1250,14 @@ void GitPlugin::applyCurrentFilePatch() applyPatch(state.topLevel(), patchFile); } -void GitPlugin::promptApplyPatch() +void GitPluginPrivate::promptApplyPatch() { const VcsBasePluginState state = currentState(); QTC_ASSERT(state.hasTopLevel(), return); applyPatch(state.topLevel(), QString()); } -void GitPlugin::applyPatch(const QString &workingDirectory, QString file) +void GitPluginPrivate::applyPatch(const QString &workingDirectory, QString file) { // Ensure user has been notified about pending changes if (!m_gitClient->beginStashScope(workingDirectory, "Apply-Patch", AllowUnstashed)) @@ -1271,7 +1284,7 @@ void GitPlugin::applyPatch(const QString &workingDirectory, QString file) m_gitClient->endStashScope(workingDirectory); } -void GitPlugin::stash(bool unstagedOnly) +void GitPluginPrivate::stash(bool unstagedOnly) { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -1285,12 +1298,12 @@ void GitPlugin::stash(bool unstagedOnly) m_stashDialog->refresh(topLevel, true); } -void GitPlugin::stashUnstaged() +void GitPluginPrivate::stashUnstaged() { stash(true); } -void GitPlugin::stashSnapshot() +void GitPluginPrivate::stashSnapshot() { // Prompt for description, restore immediately and keep on working. const VcsBasePluginState state = currentState(); @@ -1301,7 +1314,7 @@ void GitPlugin::stashSnapshot() m_stashDialog->refresh(state.topLevel(), true); } -void GitPlugin::stashPop() +void GitPluginPrivate::stashPop() { if (!DocumentManager::saveAllModifiedDocuments()) return; @@ -1326,28 +1339,28 @@ template <class NonModalDialog> } } -void GitPlugin::branchList() +void GitPluginPrivate::branchList() { ModeManager::activateMode(Core::Constants::MODE_EDIT); NavigationWidget::activateSubWidget(Constants::GIT_BRANCH_VIEW_ID, Side::Right); } -void GitPlugin::manageRemotes() +void GitPluginPrivate::manageRemotes() { showNonModalDialog(currentState().topLevel(), m_remoteDialog); } -void GitPlugin::initRepository() +void GitPluginPrivate::initRepository() { createRepository(); } -void GitPlugin::stashList() +void GitPluginPrivate::stashList() { showNonModalDialog(currentState().topLevel(), m_stashDialog); } -void GitPlugin::updateActions(VcsBasePlugin::ActionState as) +void GitPluginPrivate::updateActions(VcsBasePluginPrivate::ActionState as) { const VcsBasePluginState state = currentState(); const bool repositoryEnabled = state.hasTopLevel(); @@ -1386,7 +1399,7 @@ void GitPlugin::updateActions(VcsBasePlugin::ActionState as) m_gerritPlugin->updateActions(state); } -void GitPlugin::updateContinueAndAbortCommands() +void GitPluginPrivate::updateContinueAndAbortCommands() { if (currentState().hasTopLevel()) { GitClient::CommandInProgress gitCommandInProgress = @@ -1419,18 +1432,18 @@ void GitPlugin::updateContinueAndAbortCommands() } } -void GitPlugin::delayedPushToGerrit() +void GitPluginPrivate::delayedPushToGerrit() { m_gerritPlugin->push(m_submitRepository); } -void GitPlugin::updateBranches(const QString &repository) +void GitPluginPrivate::updateBranches(const QString &repository) { if (m_branchViewFactory && m_branchViewFactory->view()) m_branchViewFactory->view()->refreshIfSame(repository); } -void GitPlugin::updateCurrentBranch() +void GitPluginPrivate::updateCurrentBranch() { if (m_branchViewFactory && m_branchViewFactory->view()) m_branchViewFactory->view()->refreshCurrentBranch(); @@ -1439,15 +1452,15 @@ void GitPlugin::updateCurrentBranch() QObject *GitPlugin::remoteCommand(const QStringList &options, const QString &workingDirectory, const QStringList &) { - if (!m_gitClient || options.size() < 2) + if (!GitPluginPrivate::client() || options.size() < 2) return nullptr; if (options.first() == "-git-show") - m_gitClient->show(workingDirectory, options.at(1)); + GitPluginPrivate::client()->show(workingDirectory, options.at(1)); return nullptr; } -void GitPlugin::updateRepositoryBrowserAction() +void GitPluginPrivate::updateRepositoryBrowserAction() { const bool repositoryEnabled = currentState().hasTopLevel(); const bool hasRepositoryBrowserCmd @@ -1455,7 +1468,7 @@ void GitPlugin::updateRepositoryBrowserAction() m_repositoryBrowserAction->setEnabled(repositoryEnabled && hasRepositoryBrowserCmd); } -Gerrit::Internal::GerritPlugin *GitPlugin::gerritPlugin() const +Gerrit::Internal::GerritPlugin *GitPluginPrivate::gerritPlugin() const { return m_gerritPlugin; } diff --git a/src/plugins/git/gitplugin.h b/src/plugins/git/gitplugin.h index 1054adffe7..7ea9b34e56 100644 --- a/src/plugins/git/gitplugin.h +++ b/src/plugins/git/gitplugin.h @@ -67,20 +67,17 @@ class RemoteDialog; using GitClientMemberFunc = void (GitClient::*)(const QString &); -class GitPlugin : public VcsBase::VcsBasePlugin +class GitPluginPrivate final : public VcsBase::VcsBasePluginPrivate { Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Git.json") public: - GitPlugin(); - ~GitPlugin() override; + GitPluginPrivate(); + ~GitPluginPrivate() final; - static GitPlugin *instance(); + static GitPluginPrivate *instance(); static GitClient *client(); - bool initialize(const QStringList &arguments, QString *errorMessage) override; - GitVersionControl *gitVersionControl() const; Gerrit::Internal::GerritPlugin *gerritPlugin() const; @@ -91,27 +88,14 @@ public: void updateBranches(const QString &repository); void updateCurrentBranch(); - QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, - const QStringList &args) override; void manageRemotes(); void initRepository(); void startRebaseFromCommit(const QString &workingDirectory, QString commit); protected: - void updateActions(VcsBase::VcsBasePlugin::ActionState) override; + void updateActions(VcsBase::VcsBasePluginPrivate::ActionState) override; bool submitEditorAboutToClose() override; -#ifdef WITH_TESTS -private slots: - void testStatusParsing_data(); - void testStatusParsing(); - void testDiffFileResolving_data(); - void testDiffFileResolving(); - void testLogResolving(); - void testGitRemote_data(); - void testGitRemote(); -#endif - private: void diffCurrentFile(); void diffCurrentProject(); @@ -169,7 +153,7 @@ private: QAction *createProjectAction(Core::ActionContainer *ac, const QString &defaultText, const QString ¶meterText, Core::Id id, const Core::Context &context, bool addToLocator, - void (GitPlugin::*func)(), + void (GitPluginPrivate::*func)(), const QKeySequence &keys = QKeySequence()); QAction *createRepositoryAction(Core::ActionContainer *ac, const QString &text, Core::Id id, @@ -222,5 +206,32 @@ private: bool m_submitActionTriggered = false; }; +class GitPlugin final : public ExtensionSystem::IPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QtCreatorPlugin" FILE "Git.json") + +public: + ~GitPlugin() final; + + bool initialize(const QStringList &arguments, QString *errorMessage) final; + void extensionsInitialized() final; + + QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, + const QStringList &args) final; + +#ifdef WITH_TESTS +private slots: + void testStatusParsing_data(); + void testStatusParsing(); + void testDiffFileResolving_data(); + void testDiffFileResolving(); + void testLogResolving(); + void testGitRemote_data(); + void testGitRemote(); +#endif + +}; + } // namespace Internal } // namespace Git diff --git a/src/plugins/git/gitsubmiteditor.cpp b/src/plugins/git/gitsubmiteditor.cpp index be37166844..08541b846c 100644 --- a/src/plugins/git/gitsubmiteditor.cpp +++ b/src/plugins/git/gitsubmiteditor.cpp @@ -88,7 +88,7 @@ CommitDataFetchResult CommitDataFetchResult::fetch(CommitType commitType, const CommitDataFetchResult result; result.commitData.commitType = commitType; QString commitTemplate; - result.success = GitPlugin::client()->getCommitData(workingDirectory, &commitTemplate, + result.success = GitPluginPrivate::client()->getCommitData(workingDirectory, &commitTemplate, result.commitData, &result.errorMessage); return result; } @@ -103,7 +103,7 @@ GitSubmitEditor::GitSubmitEditor(const VcsBaseSubmitEditorParameters *parameters { connect(this, &VcsBaseSubmitEditor::diffSelectedRows, this, &GitSubmitEditor::slotDiffSelected); connect(submitEditorWidget(), &GitSubmitEditorWidget::show, this, &GitSubmitEditor::showCommit); - connect(GitPlugin::instance()->versionControl(), &Core::IVersionControl::repositoryChanged, + connect(GitPluginPrivate::instance()->versionControl(), &Core::IVersionControl::repositoryChanged, this, &GitSubmitEditor::forceUpdateFileModel); connect(&m_fetchWatcher, &QFutureWatcher<CommitDataFetchResult>::finished, this, &GitSubmitEditor::commitDataRetrieved); @@ -202,15 +202,15 @@ void GitSubmitEditor::slotDiffSelected(const QList<int> &rows) } } if (!unstagedFiles.empty() || !stagedFiles.empty()) - GitPlugin::client()->diffFiles(m_workingDirectory, unstagedFiles, stagedFiles); + GitPluginPrivate::client()->diffFiles(m_workingDirectory, unstagedFiles, stagedFiles); if (!unmergedFiles.empty()) - GitPlugin::client()->merge(m_workingDirectory, unmergedFiles); + GitPluginPrivate::client()->merge(m_workingDirectory, unmergedFiles); } void GitSubmitEditor::showCommit(const QString &commit) { if (!m_workingDirectory.isEmpty()) - GitPlugin::client()->show(m_workingDirectory, commit); + GitPluginPrivate::client()->show(m_workingDirectory, commit); } void GitSubmitEditor::updateFileModel() @@ -230,7 +230,7 @@ void GitSubmitEditor::updateFileModel() Core::ProgressManager::addTask(m_fetchWatcher.future(), tr("Refreshing Commit Data"), TASK_UPDATE_COMMIT); - GitPlugin::client()->addFuture(m_fetchWatcher.future()); + GitPluginPrivate::client()->addFuture(m_fetchWatcher.future()); } void GitSubmitEditor::forceUpdateFileModel() diff --git a/src/plugins/git/logchangedialog.cpp b/src/plugins/git/logchangedialog.cpp index e57dda49e0..93186c01e1 100644 --- a/src/plugins/git/logchangedialog.cpp +++ b/src/plugins/git/logchangedialog.cpp @@ -79,7 +79,7 @@ bool LogChangeWidget::init(const QString &repository, const QString &commit, Log return true; if (!(flags & Silent)) { VcsOutputWindow::appendError( - GitPlugin::client()->msgNoCommits(flags & IncludeRemotes)); + GitPluginPrivate::client()->msgNoCommits(flags & IncludeRemotes)); } return false; } @@ -159,7 +159,7 @@ bool LogChangeWidget::populateLog(const QString &repository, const QString &comm arguments << "--not" << "--remotes"; arguments << "--"; QString output; - if (!GitPlugin::client()->synchronousLog(repository, arguments, &output, nullptr, VcsCommand::NoOutput)) + if (!GitPluginPrivate::client()->synchronousLog(repository, arguments, &output, nullptr, VcsCommand::NoOutput)) return false; const QStringList lines = output.split('\n'); for (const QString &line : lines) { @@ -211,7 +211,7 @@ LogChangeDialog::LogChangeDialog(bool isReset, QWidget *parent) : m_resetTypeComboBox->addItem(tr("Hard"), "--hard"); m_resetTypeComboBox->addItem(tr("Mixed"), "--mixed"); m_resetTypeComboBox->addItem(tr("Soft"), "--soft"); - m_resetTypeComboBox->setCurrentIndex(GitPlugin::client()->settings().intValue( + m_resetTypeComboBox->setCurrentIndex(GitPluginPrivate::client()->settings().intValue( GitSettings::lastResetIndexKey)); popUpLayout->addWidget(m_resetTypeComboBox); popUpLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Ignored)); @@ -240,7 +240,7 @@ bool LogChangeDialog::runDialog(const QString &repository, if (QDialog::exec() == QDialog::Accepted) { if (m_resetTypeComboBox) { - GitPlugin::client()->settings().setValue(GitSettings::lastResetIndexKey, + GitPluginPrivate::client()->settings().setValue(GitSettings::lastResetIndexKey, m_resetTypeComboBox->currentIndex()); } return true; diff --git a/src/plugins/git/mergetool.cpp b/src/plugins/git/mergetool.cpp index 9878ad900b..dae5d6939c 100644 --- a/src/plugins/git/mergetool.cpp +++ b/src/plugins/git/mergetool.cpp @@ -61,7 +61,7 @@ bool MergeTool::start(const QString &workingDirectory, const QStringList &files) m_process->setWorkingDirectory(workingDirectory); m_process->setProcessEnvironment(env); m_process->setProcessChannelMode(QProcess::MergedChannels); - const Utils::FilePath binary = GitPlugin::client()->vcsBinary(); + const Utils::FilePath binary = GitPluginPrivate::client()->vcsBinary(); VcsOutputWindow::appendCommand(workingDirectory, {binary, arguments}); m_process->start(binary.toString(), arguments); if (m_process->waitForStarted()) { @@ -264,8 +264,8 @@ void MergeTool::done() VcsOutputWindow::appendError(tr("Merge tool process terminated with exit code %1") .arg(exitCode)); } - GitPlugin::client()->continueCommandIfNeeded(workingDirectory, exitCode == 0); - GitPlugin::instance()->gitVersionControl()->emitRepositoryChanged(workingDirectory); + GitPluginPrivate::client()->continueCommandIfNeeded(workingDirectory, exitCode == 0); + GitPluginPrivate::instance()->gitVersionControl()->emitRepositoryChanged(workingDirectory); deleteLater(); } diff --git a/src/plugins/git/remotedialog.cpp b/src/plugins/git/remotedialog.cpp index 50b7a994f2..47432b05e5 100644 --- a/src/plugins/git/remotedialog.cpp +++ b/src/plugins/git/remotedialog.cpp @@ -49,7 +49,7 @@ class RemoteAdditionDialog : public QDialog { public: RemoteAdditionDialog(const QStringList &remoteNames) : - m_invalidRemoteNameChars(GitPlugin::invalidBranchAndRemoteNamePattern()), + m_invalidRemoteNameChars(GitPluginPrivate::invalidBranchAndRemoteNamePattern()), m_remoteNames(remoteNames) { m_ui.setupUi(this); @@ -157,7 +157,7 @@ void RemoteDialog::refresh(const QString &repository, bool force) if (m_remoteModel->workingDirectory() == repository && !force) return; // Refresh - m_ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); + m_ui->repositoryLabel->setText(GitPluginPrivate::msgRepositoryLabel(repository)); if (repository.isEmpty()) { m_remoteModel->clear(); } else { @@ -205,7 +205,7 @@ void RemoteDialog::pushToRemote() const int row = indexList.at(0).row(); const QString remoteName = m_remoteModel->remoteName(row); - GitPlugin::client()->push(m_remoteModel->workingDirectory(), {remoteName}); + GitPluginPrivate::client()->push(m_remoteModel->workingDirectory(), {remoteName}); } void RemoteDialog::fetchFromRemote() @@ -216,7 +216,7 @@ void RemoteDialog::fetchFromRemote() int row = indexList.at(0).row(); const QString remoteName = m_remoteModel->remoteName(row); - GitPlugin::client()->fetch(m_remoteModel->workingDirectory(), remoteName); + GitPluginPrivate::client()->fetch(m_remoteModel->workingDirectory(), remoteName); } void RemoteDialog::updateButtonState() diff --git a/src/plugins/git/remotemodel.cpp b/src/plugins/git/remotemodel.cpp index 0a0f30c1b4..69b9eb11ae 100644 --- a/src/plugins/git/remotemodel.cpp +++ b/src/plugins/git/remotemodel.cpp @@ -55,7 +55,7 @@ bool RemoteModel::removeRemote(int row) { QString output; QString error; - bool success = GitPlugin::client()->synchronousRemoteCmd( + bool success = GitPluginPrivate::client()->synchronousRemoteCmd( m_workingDirectory, {"rm", remoteName(row)}, &output, &error); if (success) success = refresh(m_workingDirectory, &error); @@ -69,7 +69,7 @@ bool RemoteModel::addRemote(const QString &name, const QString &url) if (name.isEmpty() || url.isEmpty()) return false; - bool success = GitPlugin::client()->synchronousRemoteCmd( + bool success = GitPluginPrivate::client()->synchronousRemoteCmd( m_workingDirectory, {"add", name, url}, &output, &error); if (success) success = refresh(m_workingDirectory, &error); @@ -80,7 +80,7 @@ bool RemoteModel::renameRemote(const QString &oldName, const QString &newName) { QString output; QString error; - bool success = GitPlugin::client()->synchronousRemoteCmd( + bool success = GitPluginPrivate::client()->synchronousRemoteCmd( m_workingDirectory, {"rename", oldName, newName}, &output, &error); if (success) success = refresh(m_workingDirectory, &error); @@ -91,7 +91,7 @@ bool RemoteModel::updateUrl(const QString &name, const QString &newUrl) { QString output; QString error; - bool success = GitPlugin::client()->synchronousRemoteCmd( + bool success = GitPluginPrivate::client()->synchronousRemoteCmd( m_workingDirectory, {"set-url", name, newUrl}, &output, &error); if (success) success = refresh(m_workingDirectory, &error); @@ -186,7 +186,7 @@ bool RemoteModel::refresh(const QString &workingDirectory, QString *errorMessage // get list of remotes. QMap<QString,QString> remotesList - = GitPlugin::client()->synchronousRemotesList(workingDirectory, errorMessage); + = GitPluginPrivate::client()->synchronousRemotesList(workingDirectory, errorMessage); beginResetModel(); m_remotes.clear(); diff --git a/src/plugins/git/settingspage.cpp b/src/plugins/git/settingspage.cpp index 2e54beb2b9..3e2ec951c6 100644 --- a/src/plugins/git/settingspage.cpp +++ b/src/plugins/git/settingspage.cpp @@ -124,7 +124,7 @@ void SettingsPageWidget::updateNoteField() // -------- SettingsPage SettingsPage::SettingsPage(Core::IVersionControl *control, QObject *parent) : - VcsClientOptionsPage(control, GitPlugin::client(), parent) + VcsClientOptionsPage(control, GitPluginPrivate::client(), parent) { setId(VcsBase::Constants::VCS_ID_GIT); setDisplayName(SettingsPageWidget::tr("Git")); diff --git a/src/plugins/git/stashdialog.cpp b/src/plugins/git/stashdialog.cpp index e20cb6dcc8..9ecb77168d 100644 --- a/src/plugins/git/stashdialog.cpp +++ b/src/plugins/git/stashdialog.cpp @@ -157,12 +157,12 @@ void StashDialog::refresh(const QString &repository, bool force) return; // Refresh m_repository = repository; - ui->repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); + ui->repositoryLabel->setText(GitPluginPrivate::msgRepositoryLabel(repository)); if (m_repository.isEmpty()) { m_model->setStashes(QList<Stash>()); } else { QList<Stash> stashes; - GitPlugin::client()->synchronousStashList(m_repository, &stashes); + GitPluginPrivate::client()->synchronousStashList(m_repository, &stashes); m_model->setStashes(stashes); if (!stashes.isEmpty()) { for (int c = 0; c < ColumnCount; c++) @@ -178,7 +178,7 @@ void StashDialog::deleteAll() if (!ask(title, tr("Do you want to delete all stashes?"))) return; QString errorMessage; - if (GitPlugin::client()->synchronousStashRemove(m_repository, QString(), &errorMessage)) + if (GitPluginPrivate::client()->synchronousStashRemove(m_repository, QString(), &errorMessage)) refresh(m_repository, true); else warning(title, errorMessage); @@ -195,7 +195,7 @@ void StashDialog::deleteSelection() QStringList errors; // Delete in reverse order as stashes rotate for (int r = rows.size() - 1; r >= 0; r--) - if (!GitPlugin::client()->synchronousStashRemove(m_repository, m_model->at(rows.at(r)).name, &errorMessage)) + if (!GitPluginPrivate::client()->synchronousStashRemove(m_repository, m_model->at(rows.at(r)).name, &errorMessage)) errors.push_back(errorMessage); refresh(m_repository, true); if (!errors.isEmpty()) @@ -206,7 +206,7 @@ void StashDialog::showCurrent() { const int index = currentRow(); QTC_ASSERT(index >= 0, return); - GitPlugin::client()->show(m_repository, QString(m_model->at(index).name)); + GitPluginPrivate::client()->show(m_repository, QString(m_model->at(index).name)); } // Suggest Branch name to restore 'stash@{0}' -> 'stash0-date' @@ -267,7 +267,7 @@ bool StashDialog::promptForRestore(QString *stash, { const QString stashIn = *stash; bool modifiedPromptShown = false; - switch (GitPlugin::client()->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules), nullptr, errorMessage)) { + switch (GitPluginPrivate::client()->gitStatus(m_repository, StatusMode(NoUntracked | NoSubmodules), nullptr, errorMessage)) { case GitClient::StatusFailed: return false; case GitClient::StatusChanged: { @@ -275,13 +275,13 @@ bool StashDialog::promptForRestore(QString *stash, case ModifiedRepositoryCancel: return false; case ModifiedRepositoryStash: - if (GitPlugin::client()->synchronousStash(m_repository, QString(), GitClient::StashPromptDescription).isEmpty()) + if (GitPluginPrivate::client()->synchronousStash(m_repository, QString(), GitClient::StashPromptDescription).isEmpty()) return false; *stash = nextStash(*stash); // Our stash id to be restored changed QTC_ASSERT(!stash->isEmpty(), return false); break; case ModifiedRepositoryDiscard: - if (!GitPlugin::client()->synchronousReset(m_repository)) + if (!GitPluginPrivate::client()->synchronousReset(m_repository)) return false; break; } @@ -318,7 +318,7 @@ void StashDialog::restoreCurrent() // Make sure repository is not modified, restore. The command will // output to window on success. if (promptForRestore(&name, nullptr, &errorMessage) - && GitPlugin::client()->synchronousStashRestore(m_repository, name)) { + && GitPluginPrivate::client()->synchronousStashRestore(m_repository, name)) { refresh(m_repository, true); // Might have stashed away local changes. } else if (!errorMessage.isEmpty()) { warning(msgRestoreFailedTitle(name), errorMessage); @@ -333,7 +333,7 @@ void StashDialog::restoreCurrentInBranch() QString branch; QString name = m_model->at(index).name; if (promptForRestore(&name, &branch, &errorMessage) - && GitPlugin::client()->synchronousStashRestore(m_repository, name, false, branch)) { + && GitPluginPrivate::client()->synchronousStashRestore(m_repository, name, false, branch)) { refresh(m_repository, true); // git deletes the stash, unfortunately. } else if (!errorMessage.isEmpty()) { warning(msgRestoreFailedTitle(name), errorMessage); |