Vcs: Move static functions out of VcsPlugin "namespace"

Plan is to split VcsPlugin in the pure IPlugin and a new class
the remaining non-IPlugin bits of VcsPlugin, call it VcsPluginPrivate
and use that d-ptr for VcsPlugin. VcsPlugin-derived classes can
then use VcsPluginPrivate derived private, later pointer members
of the *Privates can be made proper members, moving towards the
otherwise predominant plugin setup pattern.

Change-Id: I62db9269e8ca50633c24b6d1d735d59c8fa8e5a5
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2020-01-22 13:29:46 +01:00
parent 8f96b4d161
commit 823c44de18
11 changed files with 63 additions and 66 deletions

View File

@@ -189,10 +189,8 @@ QString BazaarClient::findTopLevelForFile(const QFileInfo &file) const
const QString repositoryCheckFile =
QLatin1String(Constants::BAZAARREPO) + QLatin1String("/branch-format");
return file.isDir() ?
VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(),
repositoryCheckFile) :
VcsBasePlugin::findRepositoryForDirectory(file.absolutePath(),
repositoryCheckFile);
VcsBase::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
VcsBase::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
}
bool BazaarClient::managesFile(const QString &workingDirectory, const QString &fileName) const

View File

@@ -1453,7 +1453,7 @@ ClearCasePlugin::runCleartool(const QString &workingDir,
}
const SynchronousProcessResponse sp_resp =
VcsBasePlugin::runVcs(workingDir,
VcsBase::runVcs(workingDir,
{executable, arguments},
timeOutS,
flags, outputCodec);

View File

@@ -534,7 +534,7 @@ void ShowController::reload()
m_state = GettingDescription;
const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id};
runCommand(QList<QStringList>() << args, GitPlugin::client()->encoding(workingDirectory(), "i18n.commitEncoding"));
setStartupFile(VcsBasePlugin::source(document()));
setStartupFile(VcsBase::source(document()));
}
void ShowController::processCommandOutput(const QString &output)
@@ -955,7 +955,7 @@ void GitClient::requestReload(const QString &documentId, const QString &source,
connect(controller, &DiffEditorController::chunkActionsRequested,
this, &GitClient::chunkActionsRequested, Qt::DirectConnection);
VcsBasePlugin::setSource(document, sourceCopy);
VcsBase::setSource(document, sourceCopy);
EditorManager::activateEditorForDocument(document);
controller->requestReload();
}

View File

@@ -1025,7 +1025,7 @@ IEditor *GitPlugin::openSubmitEditor(const QString &fileName, const CommitData &
}
IDocument *document = submitEditor->document();
document->setPreferredDisplayName(title);
VcsBasePlugin::setSource(document, m_submitRepository);
VcsBase::setSource(document, m_submitRepository);
return editor;
}

View File

@@ -231,7 +231,7 @@ bool MercurialClient::synchronousPull(const QString &workingDir, const QString &
// cause mercurial doesn`t understand LANG
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert(QLatin1String("LANGUAGE"), QLatin1String("C"));
const SynchronousProcessResponse resp = VcsBasePlugin::runVcs(
const SynchronousProcessResponse resp = VcsBase::runVcs(
workingDir, {vcsBinary(), args}, vcsTimeoutS(), flags, nullptr, env);
const bool ok = resp.result == SynchronousProcessResponse::Finished;
@@ -459,8 +459,8 @@ QString MercurialClient::findTopLevelForFile(const QFileInfo &file) const
{
const QString repositoryCheckFile = QLatin1String(Constants::MERCURIALREPO) + QLatin1String("/requires");
return file.isDir() ?
VcsBasePlugin::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
VcsBasePlugin::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
VcsBase::findRepositoryForDirectory(file.absoluteFilePath(), repositoryCheckFile) :
VcsBase::findRepositoryForDirectory(file.absolutePath(), repositoryCheckFile);
}
Core::Id MercurialClient::vcsEditorKind(VcsCommandTag cmd) const
@@ -521,7 +521,7 @@ void MercurialClient::requestReload(const QString &documentId, const QString &so
DiffEditorController *controller = factory(document);
QTC_ASSERT(controller, return);
VcsBasePlugin::setSource(document, sourceCopy);
VcsBase::setSource(document, sourceCopy);
EditorManager::activateEditorForDocument(document);
controller->requestReload();
}

View File

@@ -278,7 +278,7 @@ SubversionDiffEditorController *SubversionClient::findOrCreateDiffEditor(const Q
DiffEditorController::controller(document));
if (!controller)
controller = new SubversionDiffEditorController(document, workingDirectory);
VcsBasePlugin::setSource(document, source);
VcsBase::setSource(document, source);
EditorManager::activateEditorForDocument(document);
return controller;
}

View File

@@ -145,7 +145,7 @@ void VcsBaseClientImpl::enqueueJob(VcsCommand *cmd, const QStringList &args,
QProcessEnvironment VcsBaseClientImpl::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
VcsBasePlugin::setProcessEnvironment(&environment, false);
VcsBase::setProcessEnvironment(&environment, false);
return environment;
}
@@ -232,8 +232,8 @@ SynchronousProcessResponse VcsBaseClientImpl::vcsSynchronousExec(const QString &
unsigned flags,
QTextCodec *outputCodec) const
{
return VcsBasePlugin::runVcs(workingDir, {vcsBinary(), args}, vcsTimeoutS(), flags,
outputCodec, processEnvironment());
return VcsBase::runVcs(workingDir, {vcsBinary(), args}, vcsTimeoutS(), flags,
outputCodec, processEnvironment());
}
int VcsBaseClientImpl::vcsTimeoutS() const

View File

@@ -769,12 +769,12 @@ void VcsBaseEditorWidget::setForceReadOnly(bool b)
QString VcsBaseEditorWidget::source() const
{
return VcsBasePlugin::source(textDocument());
return VcsBase::source(textDocument());
}
void VcsBaseEditorWidget::setSource(const QString &source)
{
VcsBasePlugin::setSource(textDocument(), source);
VcsBase::setSource(textDocument(), source);
}
QString VcsBaseEditorWidget::annotateRevisionTextFormat() const

View File

@@ -263,7 +263,7 @@ void StateListener::slotStateChanged()
if (currentDocument) {
state.currentFile = currentDocument->filePath().toString();
if (state.currentFile.isEmpty() || currentDocument->isTemporary())
state.currentFile = VcsBasePlugin::source(currentDocument);
state.currentFile = VcsBase::source(currentDocument);
}
// Get the file and its control. Do not use the file unless we find one
@@ -728,8 +728,7 @@ bool VcsBasePlugin::raiseSubmitEditor() const
// AutoFS is used (due its automatically creating mountpoints when querying
// a directory). In addition, bail out when reaching the home directory
// of the user or root (generally avoid '/', where mountpoints are created).
QString VcsBasePlugin::findRepositoryForDirectory(const QString &dirS,
const QString &checkFile)
QString findRepositoryForDirectory(const QString &dirS, const QString &checkFile)
{
qCDebug(findRepoLog) << ">" << dirS << checkFile;
QTC_ASSERT(!dirS.isEmpty() && !checkFile.isEmpty(), return QString());
@@ -753,32 +752,32 @@ QString VcsBasePlugin::findRepositoryForDirectory(const QString &dirS,
}
// Is SSH prompt configured?
QString VcsBasePlugin::sshPrompt()
QString sshPrompt()
{
return Internal::VcsPlugin::instance()->settings().sshPasswordPrompt;
}
bool VcsBasePlugin::isSshPromptConfigured()
bool isSshPromptConfigured()
{
return !sshPrompt().isEmpty();
}
static const char SOURCE_PROPERTY[] = "qtcreator_source";
void VcsBasePlugin::setSource(IDocument *document, const QString &source)
void setSource(IDocument *document, const QString &source)
{
document->setProperty(SOURCE_PROPERTY, source);
VcsBasePluginPrivate::m_listener->slotStateChanged();
}
QString VcsBasePlugin::source(IDocument *document)
QString source(IDocument *document)
{
return document->property(SOURCE_PROPERTY).toString();
}
void VcsBasePlugin::setProcessEnvironment(QProcessEnvironment *e,
bool forceCLocale,
const QString &sshPromptBinary)
void setProcessEnvironment(QProcessEnvironment *e,
bool forceCLocale,
const QString &sshPromptBinary)
{
if (forceCLocale) {
e->insert("LANG", "C");
@@ -790,12 +789,12 @@ void VcsBasePlugin::setProcessEnvironment(QProcessEnvironment *e,
// Run a process synchronously, returning Utils::SynchronousProcessResponse
// response struct and using the VcsBasePlugin flags as applicable
SynchronousProcessResponse VcsBasePlugin::runVcs(const QString &workingDir,
const CommandLine &cmd,
int timeOutS,
unsigned flags,
QTextCodec *outputCodec,
const QProcessEnvironment &env)
SynchronousProcessResponse runVcs(const QString &workingDir,
const CommandLine &cmd,
int timeOutS,
unsigned flags,
QTextCodec *outputCodec,
const QProcessEnvironment &env)
{
VcsCommand command(workingDir, env.isEmpty() ? QProcessEnvironment::systemEnvironment() : env);
command.addFlags(flags);

View File

@@ -123,6 +123,36 @@ inline bool operator==(const VcsBasePluginState &s1, const VcsBasePluginState &s
inline bool operator!=(const VcsBasePluginState &s1, const VcsBasePluginState &s2)
{ return !s1.equals(s2); }
// Convenience that searches for the repository specifically for version control
// systems that do not have directories like "CVS" in each managed subdirectory
// but have a directory at the top of the repository like ".git" containing
// a well known file. See implementation for gory details.
VCSBASE_EXPORT QString findRepositoryForDirectory(const QString &dir, const QString &checkFile);
// Returns SSH prompt configured in settings.
VCSBASE_EXPORT QString sshPrompt();
// Returns whether an SSH prompt is configured.
VCSBASE_EXPORT bool isSshPromptConfigured();
// Set up the environment for a version control command line call.
// Sets up SSH graphical password prompting (note that the latter
// requires a terminal-less process) and sets LANG to 'C' to force English
// (suppress LOCALE warnings/parse commands output) if desired.
VCSBASE_EXPORT void setProcessEnvironment(QProcessEnvironment *e,
bool forceCLocale,
const QString &sshPasswordPrompt = sshPrompt());
// Sets the source of editor contents, can be directory or file.
VCSBASE_EXPORT void setSource(Core::IDocument *document, const QString &source);
// Returns the source of editor contents.
VCSBASE_EXPORT QString source(Core::IDocument *document);
VCSBASE_EXPORT Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
const Utils::CommandLine &cmd,
int timeOutS,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr,
const QProcessEnvironment &env = {});
class VCSBASE_EXPORT VcsBasePlugin : public ExtensionSystem::IPlugin
{
Q_OBJECT
@@ -138,36 +168,6 @@ public:
const VcsBasePluginState &currentState() const;
Core::IVersionControl *versionControl() const;
// Convenience that searches for the repository specifically for version control
// systems that do not have directories like "CVS" in each managed subdirectory
// but have a directory at the top of the repository like ".git" containing
// a well known file. See implementation for gory details.
static QString findRepositoryForDirectory(const QString &dir, const QString &checkFile);
// Set up the environment for a version control command line call.
// Sets up SSH graphical password prompting (note that the latter
// requires a terminal-less process) and sets LANG to 'C' to force English
// (suppress LOCALE warnings/parse commands output) if desired.
static void setProcessEnvironment(QProcessEnvironment *e,
bool forceCLocale,
const QString &sshPasswordPrompt = sshPrompt());
// Returns SSH prompt configured in settings.
static QString sshPrompt();
// Returns whether an SSH prompt is configured.
static bool isSshPromptConfigured();
// Sets the source of editor contents, can be directory or file.
static void setSource(Core::IDocument *document, const QString &source);
// Returns the source of editor contents.
static QString source(Core::IDocument *document);
static Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
const Utils::CommandLine &cmd,
int timeOutS,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr,
const QProcessEnvironment &env = QProcessEnvironment());
// Display name of the commit action
virtual QString commitDisplayName() const;

View File

@@ -73,7 +73,7 @@ VcsCommand::VcsCommand(const QString &workingDirectory,
const QProcessEnvironment VcsCommand::processEnvironment() const
{
QProcessEnvironment env = Core::ShellCommand::processEnvironment();
VcsBasePlugin::setProcessEnvironment(&env, flags() & ForceCLocale, VcsBasePlugin::sshPrompt());
VcsBase::setProcessEnvironment(&env, flags() & ForceCLocale, VcsBase::sshPrompt());
return env;
}
@@ -99,7 +99,7 @@ void VcsCommand::emitRepositoryChanged(const QString &workingDirectory)
unsigned VcsCommand::processFlags() const
{
unsigned processFlags = 0;
if (!VcsBasePlugin::sshPrompt().isEmpty() && (flags() & SshPasswordPrompt))
if (!VcsBase::sshPrompt().isEmpty() && (flags() & SshPasswordPrompt))
processFlags |= SynchronousProcess::UnixTerminalDisabled;
return processFlags;
}