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:
BranchNameValidator(const QStringList &localBranches, QObject *parent = nullptr) :
QValidator(parent),
m_invalidChars('(' + GitPlugin::invalidBranchAndRemoteNamePattern() + ")+"),
m_invalidChars('(' + invalidBranchAndRemoteNamePattern() + ")+"),
m_localBranches(localBranches)
{
}

View File

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

View File

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

View File

@@ -224,7 +224,7 @@ void GerritPlugin::push(const FilePath &topLevel)
static FilePath currentRepository()
{
return GitPlugin::currentState().topLevel();
return currentState().topLevel();
}
// 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.
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').
const int slashPos = project.lastIndexOf('/');
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 auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory);
updateBranches(workingDirectory);
};
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
@@ -2276,7 +2276,7 @@ GitClient::CommandInProgress GitClient::checkCommandInProgress(const FilePath &w
void GitClient::continueCommandIfNeeded(const FilePath &workingDirectory, bool allowContinue)
{
if (GitPlugin::isCommitEditorOpen())
if (isCommitEditorOpen())
return;
CommandInProgress command = checkCommandInProgress(workingDirectory);
ContinueCommandMode continueMode;
@@ -2349,7 +2349,7 @@ void GitClient::continuePreviousGitCommand(const FilePath &workingDirectory,
if (isRebase)
rebase(workingDirectory, QLatin1String(hasChanges ? "--continue" : "--skip"));
else
GitPlugin::startCommit();
startCommit();
}
}
@@ -2845,7 +2845,7 @@ bool GitClient::addAndCommit(const FilePath &repositoryDirectory,
RunFlags::UseEventLoop);
if (result.result() == ProcessResult::FinishedWithSuccess) {
VcsOutputWindow::appendMessage(msgCommitted(amendSHA1, commitCount));
GitPlugin::updateCurrentBranch();
updateCurrentBranch();
return true;
}
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;
switch (revertI(files, &isDirectory, &errorMessage, revertStaging)) {
case RevertOk:
GitPlugin::emitFilesChanged(files);
emitFilesChanged(files);
break;
case RevertCanceled:
break;
@@ -2967,7 +2967,7 @@ void GitClient::fetch(const FilePath &workingDirectory, const QString &remote)
const QStringList arguments{"fetch", (remote.isEmpty() ? "--all" : remote)};
const auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory);
updateBranches(workingDirectory);
};
vcsExecWithHandler(workingDirectory, arguments, this, commandHandler,
RunFlags::ShowStdOut | RunFlags::ShowSuccessMessage);
@@ -3153,7 +3153,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
const PushFailure pushFailure = handleError(result.cleanedStdErr(),
&pushFallbackCommand);
if (result.result() == ProcessResult::FinishedWithSuccess) {
GitPlugin::updateCurrentBranch();
updateCurrentBranch();
return;
}
if (pushFailure == PushFailure::Unknown)
@@ -3172,7 +3172,7 @@ void GitClient::push(const FilePath &workingDirectory, const QStringList &pushAr
}
const auto commandHandler = [](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateCurrentBranch();
updateCurrentBranch();
};
vcsExecWithHandler(workingDirectory,
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 auto commandHandler = [workingDirectory](const CommandResult &result) {
if (result.result() == ProcessResult::FinishedWithSuccess)
GitPlugin::updateBranches(workingDirectory);
updateBranches(workingDirectory);
};
vcsExecWithHandler(workingDirectory, fallbackCommandParts.mid(1),
this, commandHandler,
@@ -3591,7 +3591,7 @@ void GitClient::StashInfo::end()
if (m_pushAction == NormalPush)
gitClient().push(m_workingDir);
else if (m_pushAction == PushToGerrit)
GitPlugin::gerritPush(m_workingDir);
gerritPush(m_workingDir);
m_pushAction = NoPush;
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)),
&QAction::triggered, [workingDir, change] {
GitPlugin::startRebaseFromCommit(workingDir, change);
startRebaseFromCommit(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();
}
IVersionControl *GitPlugin::versionControl()
IVersionControl *versionControl()
{
return dd;
}
const VcsBasePluginState &GitPlugin::currentState()
const VcsBasePluginState &currentState()
{
return dd->currentState();
}
QString GitPlugin::msgRepositoryLabel(const FilePath &repository)
QString msgRepositoryLabel(const FilePath &repository)
{
return repository.isEmpty() ?
Tr::tr("<No repository>") :
@@ -492,7 +492,7 @@ QString GitPlugin::msgRepositoryLabel(const FilePath &repository)
// Returns a regular expression pattern with characters not allowed
// in branch and remote names.
QString GitPlugin::invalidBranchAndRemoteNamePattern()
QString invalidBranchAndRemoteNamePattern()
{
return QLatin1String(
"\\s" // no whitespace
@@ -1886,52 +1886,54 @@ void GitPluginPrivate::vcsAnnotate(const FilePath &filePath, int 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);
}
void GitPlugin::emitRepositoryChanged(const FilePath &r)
void emitRepositoryChanged(const FilePath &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);
}
void GitPlugin::manageRemotes()
void manageRemotes()
{
dd->manageRemotes();
}
void GitPlugin::initRepository()
void initRepository()
{
dd->initRepository();
}
void GitPlugin::startCommit()
void startCommit()
{
dd->startCommit();
}
void GitPlugin::updateCurrentBranch()
void updateCurrentBranch()
{
dd->updateCurrentBranch();
}
void GitPlugin::updateBranches(const FilePath &repository)
void updateBranches(const FilePath &repository)
{
dd->updateBranches(repository);
}
void GitPlugin::gerritPush(const FilePath &topLevel)
void gerritPush(const FilePath &topLevel)
{
dd->m_gerritPlugin.push(topLevel);
}
bool GitPlugin::isCommitEditorOpen()
bool isCommitEditorOpen()
{
return dd->isCommitEditorOpen();
}

View File

@@ -17,6 +17,23 @@ namespace VcsBase { class VcsBasePluginState; }
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
{
Q_OBJECT
@@ -31,23 +48,6 @@ public:
QObject *remoteCommand(const QStringList &options, const QString &workingDirectory,
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
private slots:
void testStatusParsing_data();

View File

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

View File

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

View File

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

View File

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

View File

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