forked from qt-creator/qt-creator
VcsBasePlugin: Use more FilePath
Change-Id: I7bc80245b093b210439efdf3ea353b52b288dcc0 Reviewed-by: hjk <hjk@qt.io> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -196,7 +196,7 @@ void VcsManager::resetVersionControlForDirectory(const FilePath &inputDirectory)
|
||||
}
|
||||
|
||||
IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inputDirectory,
|
||||
QString *topLevelDirectory)
|
||||
FilePath *topLevelDirectory)
|
||||
{
|
||||
using StringVersionControlPair = QPair<QString, IVersionControl *>;
|
||||
using StringVersionControlPairs = QList<StringVersionControlPair>;
|
||||
@@ -217,7 +217,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inpu
|
||||
auto cachedData = d->findInCache(directory);
|
||||
if (cachedData) {
|
||||
if (topLevelDirectory)
|
||||
*topLevelDirectory = cachedData->topLevel;
|
||||
*topLevelDirectory = FilePath::fromString(cachedData->topLevel);
|
||||
return cachedData->versionControl;
|
||||
}
|
||||
|
||||
@@ -273,7 +273,7 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inpu
|
||||
|
||||
// return result
|
||||
if (topLevelDirectory)
|
||||
*topLevelDirectory = allThatCanManage.first().first;
|
||||
*topLevelDirectory = FilePath::fromString(allThatCanManage.first().first);
|
||||
IVersionControl *versionControl = allThatCanManage.first().second;
|
||||
const bool isVcsConfigured = versionControl->isConfigured();
|
||||
if (!isVcsConfigured || d->m_unconfiguredVcs) {
|
||||
@@ -308,9 +308,9 @@ IVersionControl* VcsManager::findVersionControlForDirectory(const FilePath &inpu
|
||||
|
||||
FilePath VcsManager::findTopLevelForDirectory(const FilePath &directory)
|
||||
{
|
||||
QString result;
|
||||
FilePath result;
|
||||
findVersionControlForDirectory(directory, &result);
|
||||
return FilePath::fromString(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList VcsManager::repositories(const IVersionControl *vc)
|
||||
@@ -568,14 +568,12 @@ void CorePlugin::testVcsManager()
|
||||
vcsA->setManagedDirectories(makeHash(dirsVcsA));
|
||||
vcsB->setManagedDirectories(makeHash(dirsVcsB));
|
||||
|
||||
QString realTopLevel = QLatin1String("ABC"); // Make sure this gets cleared if needed.
|
||||
|
||||
// From VCSes:
|
||||
int expectedCount = 0;
|
||||
for (const QString &result : qAsConst(results)) {
|
||||
// qDebug() << "Expecting:" << result;
|
||||
|
||||
QStringList split = result.split(QLatin1Char(':'));
|
||||
const QStringList split = result.split(QLatin1Char(':'));
|
||||
QCOMPARE(split.count(), 4);
|
||||
QVERIFY(split.at(3) == QLatin1String("*") || split.at(3) == QLatin1String("-"));
|
||||
|
||||
@@ -589,9 +587,10 @@ void CorePlugin::testVcsManager()
|
||||
++expectedCount;
|
||||
|
||||
IVersionControl *vcs;
|
||||
FilePath realTopLevel;
|
||||
vcs = VcsManager::findVersionControlForDirectory(
|
||||
FilePath::fromString(makeString(directory)), &realTopLevel);
|
||||
QCOMPARE(realTopLevel, makeString(topLevel));
|
||||
QCOMPARE(realTopLevel.toString(), makeString(topLevel));
|
||||
if (vcs)
|
||||
QCOMPARE(vcs->id().toString(), vcsId);
|
||||
else
|
||||
|
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
static void resetVersionControlForDirectory(const Utils::FilePath &inputDirectory);
|
||||
static IVersionControl *findVersionControlForDirectory(const Utils::FilePath &directory,
|
||||
QString *topLevelDirectory = nullptr);
|
||||
Utils::FilePath *topLevelDirectory = nullptr);
|
||||
static Utils::FilePath findTopLevelForDirectory(const Utils::FilePath &directory);
|
||||
|
||||
static QStringList repositories(const IVersionControl *);
|
||||
|
@@ -3847,10 +3847,10 @@ FilePath GitClient::fileWorkingDirectory(const QString &file)
|
||||
IEditor *GitClient::openShowEditor(const FilePath &workingDirectory, const QString &ref,
|
||||
const QString &path, ShowEditor showSetting)
|
||||
{
|
||||
QString topLevel;
|
||||
VcsManager::findVersionControlForDirectory(workingDirectory, &topLevel);
|
||||
const QString relativePath = QDir(topLevel).relativeFilePath(path);
|
||||
const QByteArray content = synchronousShow(FilePath::fromString(topLevel), ref + ":" + relativePath);
|
||||
const FilePath topLevel = VcsManager::findTopLevelForDirectory(workingDirectory);
|
||||
const QString topLevelString = topLevel.toString();
|
||||
const QString relativePath = QDir(topLevelString).relativeFilePath(path);
|
||||
const QByteArray content = synchronousShow(topLevel, ref + ":" + relativePath);
|
||||
if (showSetting == ShowEditor::OnlyIfDifferent) {
|
||||
if (content.isEmpty())
|
||||
return nullptr;
|
||||
@@ -3866,7 +3866,7 @@ IEditor *GitClient::openShowEditor(const FilePath &workingDirectory, const QStri
|
||||
}
|
||||
|
||||
const QString documentId = QLatin1String(Git::Constants::GIT_PLUGIN)
|
||||
+ QLatin1String(".GitShow.") + topLevel
|
||||
+ QLatin1String(".GitShow.") + topLevelString
|
||||
+ QLatin1String(".") + relativePath;
|
||||
QString title = tr("Git Show %1:%2").arg(ref).arg(relativePath);
|
||||
IEditor *editor = EditorManager::openEditorWithContents(Id(), &title, content, documentId,
|
||||
|
@@ -198,7 +198,7 @@ static bool isGitDirectory(const FilePath &path)
|
||||
{
|
||||
static IVersionControl *gitVc = VcsManager::versionControl(VcsBase::Constants::VCS_ID_GIT);
|
||||
QTC_ASSERT(gitVc, return false);
|
||||
return gitVc == VcsManager::findVersionControlForDirectory(path, nullptr);
|
||||
return gitVc == VcsManager::findVersionControlForDirectory(path);
|
||||
}
|
||||
|
||||
GitGrep::GitGrep(GitClient *client)
|
||||
|
@@ -721,7 +721,7 @@ bool FlatModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int r
|
||||
|
||||
struct VcsInfo {
|
||||
Core::IVersionControl *vcs = nullptr;
|
||||
QString repoDir;
|
||||
FilePath repoDir;
|
||||
bool operator==(const VcsInfo &other) const {
|
||||
return vcs == other.vcs && repoDir == other.repoDir;
|
||||
}
|
||||
|
@@ -311,9 +311,9 @@ void ProjectTree::updateFileWarning(Core::IDocument *document, const QString &te
|
||||
if (filePath.canonicalPath().isChildOf(projectDir.canonicalPath()))
|
||||
return;
|
||||
// External file. Test if it under the same VCS
|
||||
QString topLevel;
|
||||
FilePath topLevel;
|
||||
if (Core::VcsManager::findVersionControlForDirectory(projectDir, &topLevel)
|
||||
&& filePath.isChildOf(FilePath::fromString(topLevel))) {
|
||||
&& filePath.isChildOf(topLevel)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@@ -76,17 +76,17 @@ public:
|
||||
inline bool hasProject() const { return !currentProjectTopLevel.isEmpty(); }
|
||||
inline bool isEmpty() const { return !hasFile() && !hasProject(); }
|
||||
|
||||
QString currentFile;
|
||||
FilePath currentFile;
|
||||
QString currentFileName;
|
||||
QString currentPatchFile;
|
||||
FilePath currentPatchFile;
|
||||
QString currentPatchFileDisplayName;
|
||||
|
||||
QString currentFileDirectory;
|
||||
QString currentFileTopLevel;
|
||||
FilePath currentFileDirectory;
|
||||
FilePath currentFileTopLevel;
|
||||
|
||||
QString currentProjectPath;
|
||||
FilePath currentProjectPath;
|
||||
QString currentProjectName;
|
||||
QString currentProjectTopLevel;
|
||||
FilePath currentProjectTopLevel;
|
||||
};
|
||||
|
||||
void State::clearFile()
|
||||
@@ -218,15 +218,15 @@ QString StateListener::windowTitleVcsTopic(const FilePath &filePath)
|
||||
}
|
||||
if (searchPath.isEmpty())
|
||||
return QString();
|
||||
QString topLevelPath;
|
||||
FilePath topLevelPath;
|
||||
IVersionControl *vc = VcsManager::findVersionControlForDirectory(
|
||||
searchPath, &topLevelPath);
|
||||
return (vc && !topLevelPath.isEmpty()) ? vc->vcsTopic(FilePath::fromString(topLevelPath)) : QString();
|
||||
return (vc && !topLevelPath.isEmpty()) ? vc->vcsTopic(topLevelPath) : QString();
|
||||
}
|
||||
|
||||
static inline QString displayNameOfEditor(const QString &fileName)
|
||||
static inline QString displayNameOfEditor(const FilePath &fileName)
|
||||
{
|
||||
IDocument *document = DocumentModel::documentForFilePath(FilePath::fromString(fileName));
|
||||
IDocument *document = DocumentModel::documentForFilePath(fileName);
|
||||
if (document)
|
||||
return document->displayName();
|
||||
return QString();
|
||||
@@ -240,18 +240,16 @@ void StateListener::slotStateChanged()
|
||||
State state;
|
||||
IDocument *currentDocument = EditorManager::currentDocument();
|
||||
if (currentDocument) {
|
||||
state.currentFile = currentDocument->filePath().toString();
|
||||
state.currentFile = currentDocument->filePath();
|
||||
if (state.currentFile.isEmpty() || currentDocument->isTemporary())
|
||||
state.currentFile = VcsBase::source(currentDocument);
|
||||
state.currentFile = FilePath::fromString(VcsBase::source(currentDocument));
|
||||
}
|
||||
|
||||
// Get the file and its control. Do not use the file unless we find one
|
||||
IVersionControl *fileControl = nullptr;
|
||||
|
||||
if (!state.currentFile.isEmpty()) {
|
||||
QFileInfo currentFi(state.currentFile);
|
||||
|
||||
if (currentFi.exists()) {
|
||||
if (state.currentFile.exists()) {
|
||||
// Quick check: Does it look like a patch?
|
||||
const bool isPatch = state.currentFile.endsWith(".patch")
|
||||
|| state.currentFile.endsWith(".diff");
|
||||
@@ -261,18 +259,18 @@ void StateListener::slotStateChanged()
|
||||
state.currentPatchFile = state.currentFile;
|
||||
state.currentPatchFileDisplayName = displayNameOfEditor(state.currentPatchFile);
|
||||
if (state.currentPatchFileDisplayName.isEmpty())
|
||||
state.currentPatchFileDisplayName = currentFi.fileName();
|
||||
state.currentPatchFileDisplayName = state.currentFile.fileName();
|
||||
}
|
||||
|
||||
if (currentFi.isDir()) {
|
||||
if (state.currentFile.isDir()) {
|
||||
state.currentFile.clear();
|
||||
state.currentFileDirectory = currentFi.absoluteFilePath();
|
||||
state.currentFileDirectory = state.currentFile.absoluteFilePath();
|
||||
} else {
|
||||
state.currentFileDirectory = currentFi.absolutePath();
|
||||
state.currentFileName = currentFi.fileName();
|
||||
state.currentFileDirectory = state.currentFile.absolutePath();
|
||||
state.currentFileName = state.currentFile.fileName();
|
||||
}
|
||||
fileControl = VcsManager::findVersionControlForDirectory(
|
||||
FilePath::fromString(state.currentFileDirectory), &state.currentFileTopLevel);
|
||||
state.currentFileDirectory, &state.currentFileTopLevel);
|
||||
}
|
||||
|
||||
if (!fileControl)
|
||||
@@ -286,10 +284,10 @@ void StateListener::slotStateChanged()
|
||||
currentProject = SessionManager::startupProject();
|
||||
|
||||
if (currentProject) {
|
||||
state.currentProjectPath = currentProject->projectDirectory().toString();
|
||||
state.currentProjectPath = currentProject->projectDirectory();
|
||||
state.currentProjectName = currentProject->displayName();
|
||||
projectControl = VcsManager::findVersionControlForDirectory(
|
||||
FilePath::fromString(state.currentProjectPath), &state.currentProjectTopLevel);
|
||||
state.currentProjectPath, &state.currentProjectTopLevel);
|
||||
if (projectControl) {
|
||||
// If we have both, let the file's one take preference
|
||||
if (fileControl && projectControl != fileControl)
|
||||
@@ -353,7 +351,7 @@ VcsBasePluginState &VcsBasePluginState::operator=(const VcsBasePluginState &rhs)
|
||||
|
||||
QString VcsBasePluginState::currentFile() const
|
||||
{
|
||||
return data->m_state.currentFile;
|
||||
return data->m_state.currentFile.toString();
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::currentFileName() const
|
||||
@@ -363,23 +361,24 @@ QString VcsBasePluginState::currentFileName() const
|
||||
|
||||
FilePath VcsBasePluginState::currentFileTopLevel() const
|
||||
{
|
||||
return FilePath::fromString(data->m_state.currentFileTopLevel);
|
||||
return data->m_state.currentFileTopLevel;
|
||||
}
|
||||
|
||||
FilePath VcsBasePluginState::currentFileDirectory() const
|
||||
{
|
||||
return FilePath::fromString(data->m_state.currentFileDirectory);
|
||||
return data->m_state.currentFileDirectory;
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::relativeCurrentFile() const
|
||||
{
|
||||
QTC_ASSERT(hasFile(), return QString());
|
||||
return QDir(data->m_state.currentFileTopLevel).relativeFilePath(data->m_state.currentFile);
|
||||
QTC_ASSERT(hasFile(), return {});
|
||||
return QDir(data->m_state.currentFileTopLevel.toString()).relativeFilePath(
|
||||
data->m_state.currentFile.toString());
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::currentPatchFile() const
|
||||
{
|
||||
return data->m_state.currentPatchFile;
|
||||
return data->m_state.currentPatchFile.toString();
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::currentPatchFileDisplayName() const
|
||||
@@ -389,7 +388,7 @@ QString VcsBasePluginState::currentPatchFileDisplayName() const
|
||||
|
||||
FilePath VcsBasePluginState::currentProjectPath() const
|
||||
{
|
||||
return FilePath::fromString(data->m_state.currentProjectPath);
|
||||
return data->m_state.currentProjectPath;
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::currentProjectName() const
|
||||
@@ -399,15 +398,16 @@ QString VcsBasePluginState::currentProjectName() const
|
||||
|
||||
FilePath VcsBasePluginState::currentProjectTopLevel() const
|
||||
{
|
||||
return FilePath::fromString(data->m_state.currentProjectTopLevel);
|
||||
return data->m_state.currentProjectTopLevel;
|
||||
}
|
||||
|
||||
QString VcsBasePluginState::relativeCurrentProject() const
|
||||
{
|
||||
QTC_ASSERT(hasProject(), return QString());
|
||||
if (data->m_state.currentProjectTopLevel != data->m_state.currentProjectPath)
|
||||
return QDir(data->m_state.currentProjectTopLevel).relativeFilePath(data->m_state.currentProjectPath);
|
||||
return QString();
|
||||
if (data->m_state.currentProjectTopLevel == data->m_state.currentProjectPath)
|
||||
return {};
|
||||
return QDir(data->m_state.currentProjectTopLevel.toString()).relativeFilePath(
|
||||
data->m_state.currentProjectPath.toString());
|
||||
}
|
||||
|
||||
bool VcsBasePluginState::hasTopLevel() const
|
||||
@@ -417,7 +417,7 @@ bool VcsBasePluginState::hasTopLevel() const
|
||||
|
||||
FilePath VcsBasePluginState::topLevel() const
|
||||
{
|
||||
return FilePath::fromString(hasFile() ? data->m_state.currentFileTopLevel : data->m_state.currentProjectTopLevel);
|
||||
return hasFile() ? data->m_state.currentFileTopLevel : data->m_state.currentProjectTopLevel;
|
||||
}
|
||||
|
||||
bool VcsBasePluginState::equals(const Internal::State &rhs) const
|
||||
|
@@ -95,10 +95,10 @@ bool VcsPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
||||
tr("The current version control topic (branch or tag) identification of the current project."),
|
||||
[]() -> QString {
|
||||
IVersionControl *vc = nullptr;
|
||||
QString topLevel;
|
||||
FilePath topLevel;
|
||||
if (Project *project = ProjectTree::currentProject())
|
||||
vc = VcsManager::findVersionControlForDirectory(project->projectDirectory(), &topLevel);
|
||||
return vc ? vc->vcsTopic(FilePath::fromString(topLevel)) : QString();
|
||||
return vc ? vc->vcsTopic(topLevel) : QString();
|
||||
});
|
||||
|
||||
expander->registerVariable(Constants::VAR_VCS_TOPLEVELPATH,
|
||||
|
Reference in New Issue
Block a user