Git: Separate internal plugin access API from plugin class

Plan is to hide the plugin class definition to the .cpp later.

Change-Id: I27f6d2dd23adb4f3ab47d99b0626956889d2750f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2024-01-15 10:48:03 +01:00
parent 4434b09d49
commit 892e7c0f3a
12 changed files with 59 additions and 59 deletions

View File

@@ -34,7 +34,7 @@ class BranchNameValidator : public QValidator
public: public:
BranchNameValidator(const QStringList &localBranches, QObject *parent = nullptr) : BranchNameValidator(const QStringList &localBranches, QObject *parent = nullptr) :
QValidator(parent), QValidator(parent),
m_invalidChars('(' + GitPlugin::invalidBranchAndRemoteNamePattern() + ")+"), m_invalidChars('(' + invalidBranchAndRemoteNamePattern() + ")+"),
m_localBranches(localBranches) m_localBranches(localBranches)
{ {
} }

View File

@@ -134,7 +134,7 @@ BranchView::BranchView()
this, &BranchView::expandAndResize); this, &BranchView::expandAndResize);
m_branchView->selectionModel()->clear(); m_branchView->selectionModel()->clear();
m_repository = GitPlugin::currentState().topLevel(); m_repository = currentState().topLevel();
} }
void BranchView::refreshIfSame(const FilePath &repository) void BranchView::refreshIfSame(const FilePath &repository)
@@ -159,7 +159,7 @@ void BranchView::refresh(const FilePath &repository, bool force)
m_branchView->setEnabled(false); m_branchView->setEnabled(false);
} else { } else {
m_repositoryLabel->setText(m_repository.toUserOutput()); m_repositoryLabel->setText(m_repository.toUserOutput());
m_repositoryLabel->setToolTip(GitPlugin::msgRepositoryLabel(m_repository)); m_repositoryLabel->setToolTip(msgRepositoryLabel(m_repository));
m_addAction->setToolTip(Tr::tr("Add Branch...")); m_addAction->setToolTip(Tr::tr("Add Branch..."));
m_branchView->setEnabled(true); m_branchView->setEnabled(true);
} }
@@ -249,9 +249,7 @@ void BranchView::slotCustomContextMenu(const QPoint &point)
}); });
contextMenu.addSeparator(); contextMenu.addSeparator();
} }
contextMenu.addAction(Tr::tr("Manage &Remotes..."), this, [] { contextMenu.addAction(Tr::tr("Manage &Remotes..."), this, &manageRemotes);
GitPlugin::manageRemotes();
});
} }
if (hasActions) { if (hasActions) {
if (!currentSelected && (isLocal || isTag)) if (!currentSelected && (isLocal || isTag))
@@ -343,7 +341,7 @@ QModelIndex BranchView::selectedIndex()
bool BranchView::add() bool BranchView::add()
{ {
if (m_repository.isEmpty()) { if (m_repository.isEmpty()) {
GitPlugin::initRepository(); initRepository();
return true; return true;
} }

View File

@@ -194,7 +194,7 @@ void GerritDialog::setCurrentPath(const FilePath &path)
if (path == m_repository) if (path == m_repository)
return; return;
m_repository = path; m_repository = path;
m_repositoryLabel->setText(Git::Internal::GitPlugin::msgRepositoryLabel(path)); m_repositoryLabel->setText(Git::Internal::msgRepositoryLabel(path));
updateRemotes(); updateRemotes();
} }

View File

@@ -224,7 +224,7 @@ void GerritPlugin::push(const FilePath &topLevel)
static FilePath currentRepository() static FilePath currentRepository()
{ {
return GitPlugin::currentState().topLevel(); return currentState().topLevel();
} }
// Open or raise the Gerrit dialog window. // Open or raise the Gerrit dialog window.
@@ -362,7 +362,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
// Try to find a matching repository for a project by asking the VcsManager. // Try to find a matching repository for a project by asking the VcsManager.
FilePath GerritPlugin::findLocalRepository(const QString &project, const QString &branch) const FilePath GerritPlugin::findLocalRepository(const QString &project, const QString &branch) const
{ {
const FilePaths gitRepositories = VcsManager::repositories(GitPlugin::versionControl()); const FilePaths gitRepositories = VcsManager::repositories(versionControl());
// Determine key (file name) to look for (qt/qtbase->'qtbase'). // Determine key (file name) to look for (qt/qtbase->'qtbase').
const int slashPos = project.lastIndexOf('/'); const int slashPos = project.lastIndexOf('/');
const QString fixedProject = (slashPos < 0) ? project : project.mid(slashPos + 1); const QString fixedProject = (slashPos < 0) ? project : project.mid(slashPos + 1);

View File

@@ -1365,7 +1365,7 @@ void GitClient::removeStaleRemoteBranches(const FilePath &workingDirectory, cons
const QStringList arguments = {"remote", "prune", remote}; const QStringList arguments = {"remote", "prune", remote};
const auto commandHandler = [workingDirectory](const CommandResult &result) { const auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess) if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory); updateBranches(workingDirectory);
}; };
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler, vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage); RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
@@ -2276,7 +2276,7 @@ GitClient::CommandInProgress GitClient::checkCommandInProgress(const FilePath &w
void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue) void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue)
{ {
if (GitPlugin::isCommitEditorOpen()) if (isCommitEditorOpen())
return; return;
CommandInProgress command = checkCommandInProgress(workingDirectory); CommandInProgress command = checkCommandInProgress(workingDirectory);
ContinueCommandMode continueMode; ContinueCommandMode continueMode;
@@ -2349,7 +2349,7 @@ void GitClient::continuePreviousGitCommand(const FilePath &workingDirectory,
if (isRebase) if (isRebase)
rebase(workingDirectory, QLatin1String(hasChanges ? "--continue" : "--skip")); rebase(workingDirectory, QLatin1String(hasChanges ? "--continue" : "--skip"));
else else
GitPlugin::startCommit(); startCommit();
} }
} }
@@ -2845,7 +2845,7 @@ bool GitClient::addAndCommit(const FilePath &repositoryDirectory,
RunFlags::UseEventLoop); RunFlags::UseEventLoop);
if (result.result() == ProcessResult::FinishedWithSuccess) { if (result.result() == ProcessResult::FinishedWithSuccess) {
VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount)); VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount));
GitPlugin::updateCurrentBranch(); updateCurrentBranch();
return true; return true;
} }
VcsOutputWindow::appendError(Tr::tr("Cannot commit %n file(s).", nullptr, commitCount) + "\n"); VcsOutputWindow::appendError(Tr::tr("Cannot commit %n file(s).", nullptr, commitCount) + "\n");
@@ -2947,7 +2947,7 @@ void GitClient::revertFiles(const QStringList &files, bool revertStaging)
QString errorMessage; QString errorMessage;
switch (revertI(files, &isDirectory, &errorMessage, revertStaging)) { switch (revertI(files, &isDirectory, &errorMessage, revertStaging)) {
case RevertOk: case RevertOk:
GitPlugin::emitFilesChanged(files); emitFilesChanged(files);
break; break;
case RevertCanceled: case RevertCanceled:
break; break;
@@ -2967,7 +2967,7 @@ void GitClient::fetch(const FilePath &workingDirectory, const QString &remote)
const QStringList arguments{"fetch", (remote.isEmpty() ? "--all" : remote)}; const QStringList arguments{"fetch", (remote.isEmpty() ? "--all" : remote)};
const auto commandHandler = [workingDirectory](const CommandResult &result) { const auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess) if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory); updateBranches(workingDirectory);
}; };
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler, vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage); RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
@@ -3153,7 +3153,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
const PushFailure pushFailure = handleError(result.cleanedStdErr(), const PushFailure pushFailure = handleError(result.cleanedStdErr(),
&pushFallbackCommand); &pushFallbackCommand);
if (result.result() == ProcessResult::FinishedWithSuccess) { if (result.result() == ProcessResult::FinishedWithSuccess) {
GitPlugin::updateCurrentBranch(); updateCurrentBranch();
return; return;
} }
if (pushFailure == PushFailure::Unknown) if (pushFailure == PushFailure::Unknown)
@@ -3172,7 +3172,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
} }
const auto commandHandler = [](const CommandResult &result) { const auto commandHandler = [](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess) if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateCurrentBranch(); updateCurrentBranch();
}; };
vcsExecWithHandler(workingDirectory, vcsExecWithHandler(workingDirectory,
QStringList{"push", "--force-with-lease"} + pushArgs, QStringList{"push", "--force-with-lease"} + pushArgs,
@@ -3194,7 +3194,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
const QStringList fallbackCommandParts = pushFallbackCommand.split(' ', Qt::SkipEmptyParts); const QStringList fallbackCommandParts = pushFallbackCommand.split(' ', Qt::SkipEmptyParts);
const auto commandHandler = [workingDirectory](const CommandResult &result) { const auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess) if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory); updateBranches(workingDirectory);
}; };
vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1), vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1),
this, commandHandler, this, commandHandler,
@@ -3591,7 +3591,7 @@ void GitClient::StashInfo::end()
if (m_pushAction == NormalPush) if (m_pushAction == NormalPush)
gitClient().push(m_workingDir); gitClient().push(m_workingDir);
else if (m_pushAction == PushToGerrit) else if (m_pushAction == PushToGerrit)
GitPlugin::gerritPush(m_workingDir); gerritPush(m_workingDir);
m_pushAction = NoPush; m_pushAction = NoPush;
m_stashResult = NotStashed; m_stashResult = NotStashed;
@@ -3645,7 +3645,7 @@ void GitClient::addChangeActions(QMenu *menu, const FilePath &source, const QStr
}); });
connect(menu->addAction(Tr::tr("&Interactive Rebase from %1...").arg(change)), connect(menu->addAction(Tr::tr("&Interactive Rebase from %1...").arg(change)),
&QAction::triggered, [workingDir, change] { &QAction::triggered, [workingDir, change] {
GitPlugin::startRebaseFromCommit(workingDir, change); startRebaseFromCommit(workingDir, change);
}); });
} }
QAction *logAction = menu->addAction(Tr::tr("&Log for %1").arg(change), [workingDir, change] { QAction *logAction = menu->addAction(Tr::tr("&Log for %1").arg(change), [workingDir, change] {

View File

@@ -473,17 +473,17 @@ bool GitPluginPrivate::isCommitEditorOpen() const
return !m_commitMessageFileName.isEmpty(); return !m_commitMessageFileName.isEmpty();
} }
IVersionControl *GitPlugin::versionControl() IVersionControl *versionControl()
{ {
return dd; return dd;
} }
const VcsBasePluginState &GitPlugin::currentState() const VcsBasePluginState &currentState()
{ {
return dd->currentState(); return dd->currentState();
} }
QString GitPlugin::msgRepositoryLabel(const FilePath &repository) QString msgRepositoryLabel(const FilePath &repository)
{ {
return repository.isEmpty() ? return repository.isEmpty() ?
Tr::tr("<No repository>") : Tr::tr("<No repository>") :
@@ -492,7 +492,7 @@ QString GitPlugin::msgRepositoryLabel(const FilePath &repository)
// Returns a regular expression pattern with characters not allowed // Returns a regular expression pattern with characters not allowed
// in branch and remote names. // in branch and remote names.
QString GitPlugin::invalidBranchAndRemoteNamePattern() QString invalidBranchAndRemoteNamePattern()
{ {
return QLatin1String( return QLatin1String(
"\\s" // no whitespace "\\s" // no whitespace
@@ -1886,52 +1886,54 @@ void GitPluginPrivate::vcsAnnotate(const FilePath &filePath, int line)
gitClient().annotate(filePath.absolutePath(), filePath.fileName(), line); gitClient().annotate(filePath.absolutePath(), filePath.fileName(), line);
} }
void GitPlugin::emitFilesChanged(const QStringList &l) // "Internal API"
void emitFilesChanged(const QStringList &l)
{ {
emit dd->filesChanged(l); emit dd->filesChanged(l);
} }
void GitPlugin::emitRepositoryChanged(const FilePath &r) void emitRepositoryChanged(const FilePath &r)
{ {
emit dd->repositoryChanged(r); emit dd->repositoryChanged(r);
} }
void GitPlugin::startRebaseFromCommit(const FilePath &workingDirectory, const QString &commit) void startRebaseFromCommit(const FilePath &workingDirectory, const QString &commit)
{ {
dd->startRebaseFromCommit(workingDirectory, commit); dd->startRebaseFromCommit(workingDirectory, commit);
} }
void GitPlugin::manageRemotes() void manageRemotes()
{ {
dd->manageRemotes(); dd->manageRemotes();
} }
void GitPlugin::initRepository() void initRepository()
{ {
dd->initRepository(); dd->initRepository();
} }
void GitPlugin::startCommit() void startCommit()
{ {
dd->startCommit(); dd->startCommit();
} }
void GitPlugin::updateCurrentBranch() void updateCurrentBranch()
{ {
dd->updateCurrentBranch(); dd->updateCurrentBranch();
} }
void GitPlugin::updateBranches(const FilePath &repository) void updateBranches(const FilePath &repository)
{ {
dd->updateBranches(repository); dd->updateBranches(repository);
} }
void GitPlugin::gerritPush(const FilePath &topLevel) void gerritPush(const FilePath &topLevel)
{ {
dd->m_gerritPlugin.push(topLevel); dd->m_gerritPlugin.push(topLevel);
} }
bool GitPlugin::isCommitEditorOpen() bool isCommitEditorOpen()
{ {
return dd->isCommitEditorOpen(); return dd->isCommitEditorOpen();
} }

View File

@@ -17,6 +17,23 @@ namespace VcsBase { class VcsBasePluginState; }
namespace Git::Internal { namespace Git::Internal {
Core::IVersionControl *versionControl();
const VcsBase::VcsBasePluginState &currentState();
QString msgRepositoryLabel(const Utils::FilePath &repository);
QString invalidBranchAndRemoteNamePattern();
bool isCommitEditorOpen();
void emitFilesChanged(const QStringList &);
void emitRepositoryChanged(const Utils::FilePath &);
void startRebaseFromCommit(const Utils::FilePath &workingDirectory, const QString &commit);
void manageRemotes();
void initRepository();
void startCommit();
void updateCurrentBranch();
void updateBranches(const Utils::FilePath &repository);
void gerritPush(const Utils::FilePath &topLevel);
class GITSHARED_EXPORT GitPlugin final : public ExtensionSystem::IPlugin class GITSHARED_EXPORT GitPlugin final : public ExtensionSystem::IPlugin
{ {
Q_OBJECT Q_OBJECT
@@ -31,23 +48,6 @@ public:
QObject *remoteCommand(const QStringList &options, const QString &workingDirectory, QObject *remoteCommand(const QStringList &options, const QString &workingDirectory,
const QStringList &args) final; const QStringList &args) final;
static Core::IVersionControl *versionControl();
static const VcsBase::VcsBasePluginState &currentState();
static QString msgRepositoryLabel(const Utils::FilePath &repository);
static QString invalidBranchAndRemoteNamePattern();
static bool isCommitEditorOpen();
static void emitFilesChanged(const QStringList &);
static void emitRepositoryChanged(const Utils::FilePath &);
static void startRebaseFromCommit(const Utils::FilePath &workingDirectory, const QString &commit);
static void manageRemotes();
static void initRepository();
static void startCommit();
static void updateCurrentBranch();
static void updateBranches(const Utils::FilePath &repository);
static void gerritPush(const Utils::FilePath &topLevel);
#ifdef WITH_TESTS #ifdef WITH_TESTS
private slots: private slots:
void testStatusParsing_data(); void testStatusParsing_data();

View File

@@ -84,7 +84,7 @@ GitSubmitEditor::GitSubmitEditor() :
{ {
connect(this, &VcsBaseSubmitEditor::diffSelectedRows, this, &GitSubmitEditor::slotDiffSelected); connect(this, &VcsBaseSubmitEditor::diffSelectedRows, this, &GitSubmitEditor::slotDiffSelected);
connect(submitEditorWidget(), &GitSubmitEditorWidget::showRequested, this, &GitSubmitEditor::showCommit); connect(submitEditorWidget(), &GitSubmitEditorWidget::showRequested, this, &GitSubmitEditor::showCommit);
connect(GitPlugin::versionControl(), &Core::IVersionControl::repositoryChanged, connect(versionControl(), &Core::IVersionControl::repositoryChanged,
this, &GitSubmitEditor::forceUpdateFileModel); this, &GitSubmitEditor::forceUpdateFileModel);
connect(&m_fetchWatcher, &QFutureWatcher<CommitDataFetchResult>::finished, connect(&m_fetchWatcher, &QFutureWatcher<CommitDataFetchResult>::finished,
this, &GitSubmitEditor::commitDataRetrieved); this, &GitSubmitEditor::commitDataRetrieved);

View File

@@ -128,7 +128,7 @@ void InstantBlame::setup()
if (qobject_cast<const VcsBaseEditorWidget *>(widget)) if (qobject_cast<const VcsBaseEditorWidget *>(widget))
return; // Skip in VCS editors like log or blame return; // Skip in VCS editors like log or blame
const Utils::FilePath workingDirectory = GitPlugin::currentState().currentFileTopLevel(); const FilePath workingDirectory = currentState().currentFileTopLevel();
if (!refreshWorkingDirectory(workingDirectory)) if (!refreshWorkingDirectory(workingDirectory))
return; return;
@@ -208,7 +208,7 @@ void InstantBlame::once()
connect(widget, &QPlainTextEdit::cursorPositionChanged, connect(widget, &QPlainTextEdit::cursorPositionChanged,
this, [this] { m_blameMark.reset(); }, Qt::SingleShotConnection); this, [this] { m_blameMark.reset(); }, Qt::SingleShotConnection);
const Utils::FilePath workingDirectory = GitPlugin::currentState().topLevel(); const FilePath workingDirectory = currentState().topLevel();
if (!refreshWorkingDirectory(workingDirectory)) if (!refreshWorkingDirectory(workingDirectory))
return; return;
} }

View File

@@ -225,7 +225,7 @@ void MergeTool::done()
const FilePath workingDirectory = m_process.workingDirectory(); const FilePath workingDirectory = m_process.workingDirectory();
gitClient().continueCommandIfNeeded(workingDirectory, success); gitClient().continueCommandIfNeeded(workingDirectory, success);
GitPlugin::emitRepositoryChanged(workingDirectory); emitRepositoryChanged(workingDirectory);
deleteLater(); deleteLater();
} }

View File

@@ -37,7 +37,7 @@ class RemoteAdditionDialog : public QDialog
{ {
public: public:
RemoteAdditionDialog(const QStringList &remoteNames) : RemoteAdditionDialog(const QStringList &remoteNames) :
m_invalidRemoteNameChars(GitPlugin::invalidBranchAndRemoteNamePattern()), m_invalidRemoteNameChars(invalidBranchAndRemoteNamePattern()),
m_remoteNames(remoteNames) m_remoteNames(remoteNames)
{ {
resize(381, 93); resize(381, 93);
@@ -200,7 +200,7 @@ void RemoteDialog::refresh(const FilePath &repository, bool force)
if (m_remoteModel->workingDirectory() == repository && !force) if (m_remoteModel->workingDirectory() == repository && !force)
return; return;
// Refresh // Refresh
m_repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); m_repositoryLabel->setText(msgRepositoryLabel(repository));
if (repository.isEmpty()) { if (repository.isEmpty()) {
m_remoteModel->clear(); m_remoteModel->clear();
} else { } else {

View File

@@ -165,7 +165,7 @@ void StashDialog::refresh(const FilePath &repository, bool force)
return; return;
// Refresh // Refresh
m_repository = repository; m_repository = repository;
m_repositoryLabel->setText(GitPlugin::msgRepositoryLabel(repository)); m_repositoryLabel->setText(msgRepositoryLabel(repository));
if (m_repository.isEmpty()) { if (m_repository.isEmpty()) {
m_model->setStashes(QList<Stash>()); m_model->setStashes(QList<Stash>());
} else { } else {