Commit 7ce36831 authored by Friedemann Kleint's avatar Friedemann Kleint
Browse files

CVS: Use new VCSBasePlugin-class.

Make the diff-base directory a property of VCSBaseEditor and use
everywhere.
parent 0a5b2eed
......@@ -30,6 +30,8 @@
#include "cvscontrol.h"
#include "cvsplugin.h"
#include <QtCore/QFileInfo>
using namespace CVS;
using namespace CVS::Internal;
......@@ -66,12 +68,14 @@ bool CVSControl::vcsOpen(const QString & /* fileName */)
bool CVSControl::vcsAdd(const QString &fileName)
{
return m_plugin->vcsAdd(fileName);
const QFileInfo fi(fileName);
return m_plugin->vcsAdd(fi.absolutePath(), fi.fileName());
}
bool CVSControl::vcsDelete(const QString &fileName)
{
return m_plugin->vcsDelete(fileName);
const QFileInfo fi(fileName);
return m_plugin->vcsDelete(fi.absolutePath(), fi.fileName());
}
bool CVSControl::managesDirectory(const QString &directory) const
......@@ -93,4 +97,3 @@ void CVSControl::emitFilesChanged(const QStringList &l)
{
emit filesChanged(l);
}
......@@ -142,35 +142,11 @@ QString CVSEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) cons
const int tabIndex = diffFileName.indexOf(QLatin1Char('\t'));
if (tabIndex != -1)
diffFileName.truncate(tabIndex);
// Add base dir
if (!m_diffBaseDir.isEmpty()) {
diffFileName.insert(0, QLatin1Char('/'));
diffFileName.insert(0, m_diffBaseDir);
}
if (CVS::Constants::debug)
qDebug() << "fileNameFromDiffSpecification" << m_diffBaseDir << diffFileName;
return diffFileName;
return findDiffFile(diffFileName);
}
}
return QString();
}
QString CVSEditor::diffBaseDir() const
{
return m_diffBaseDir;
}
void CVSEditor::setDiffBaseDir(const QString &d)
{
m_diffBaseDir = d;
}
void CVSEditor::setDiffBaseDir(Core::IEditor *editor, const QString &db)
{
if (CVSEditor *cvsEditor = qobject_cast<CVSEditor*>(editor->widget()))
cvsEditor->setDiffBaseDir(db);
}
}
}
......@@ -45,13 +45,6 @@ public:
explicit CVSEditor(const VCSBase::VCSBaseEditorParameters *type,
QWidget *parent);
// Diff mode requires a base directory since CVS commands
// are run with relative paths (see plugin).
QString diffBaseDir() const;
void setDiffBaseDir(const QString &d);
static void setDiffBaseDir(Core::IEditor *editor, const QString &db);
private:
virtual QSet<QString> annotationChanges() const;
virtual QString changeUnderCursor(const QTextCursor &) const;
......
This diff is collapsed.
......@@ -50,10 +50,6 @@ namespace Utils {
class ParameterAction;
}
namespace ProjectExplorer {
class ProjectExplorerPlugin;
}
namespace VCSBase {
class VCSBaseSubmitEditor;
}
......@@ -73,16 +69,8 @@ struct CVSResponse
QString stdOut;
QString stdErr;
QString message;
QString workingDirectory;
};
/* This plugin differs from the other VCS plugins in that it
* runs CVS commands from a working directory using relative
* path specifications, which is a requirement imposed by
* Tortoise CVS. This has to be taken into account; for example,
* the diff editor has an additional property specifying the
* base directory for its interaction to work. */
class CVSPlugin : public VCSBase::VCSBasePlugin
{
Q_OBJECT
......@@ -94,7 +82,7 @@ public:
virtual bool initialize(const QStringList &arguments, QString *error_message);
virtual void extensionsInitialized();
void cvsDiff(const QStringList &files, QString diffname = QString());
void cvsDiff(const QString &workingDir, const QStringList &files);
CVSSubmitEditor *openCVSSubmitEditor(const QString &fileName);
......@@ -102,8 +90,8 @@ public:
void setSettings(const CVSSettings &s);
// IVersionControl
bool vcsAdd(const QString &fileName);
bool vcsDelete(const QString &fileName);
bool vcsAdd(const QString &workingDir, const QString &fileName);
bool vcsDelete(const QString &workingDir, const QString &fileName);
bool managesDirectory(const QString &directory) const;
QString findTopLevelForDirectory(const QString &directory) const;
......@@ -123,7 +111,7 @@ private slots:
void slotDescribe(const QString &source, const QString &changeNr);
void updateProject();
void submitCurrentLog();
void diffFiles(const QStringList &);
void diffCommitFiles(const QStringList &);
protected:
virtual void updateActions(VCSBase::VCSBasePlugin::ActionState);
......@@ -131,15 +119,9 @@ protected:
private:
bool isCommitEditorOpen() const;
QString currentFileName() const;
Core::IEditor * showOutputInEditor(const QString& title, const QString &output,
int editorType, const QString &source,
QTextCodec *codec);
CVSResponse runCVS(const QStringList &arguments,
QStringList fileArguments,
int timeOut,
bool showStdOutInOutputWindow, QTextCodec *outputCodec = 0,
bool mergeStderr = false);
CVSResponse runCVS(const QString &workingDirectory,
const QStringList &arguments,
......@@ -147,34 +129,33 @@ private:
bool showStdOutInOutputWindow, QTextCodec *outputCodec = 0,
bool mergeStderr = false);
void annotate(const QString &file);
void annotate(const QString &workingDir, const QString &file);
bool describe(const QString &source, const QString &changeNr, QString *errorMessage);
bool describe(const QString &toplevel, const QString &source, const QString &changeNr, QString *errorMessage);
bool describe(const QString &repository, QList<CVS_LogEntry> entries, QString *errorMessage);
void filelog(const QString &file);
void filelog(const QString &workingDir, const QStringList &files = QStringList());
bool managesDirectory(const QDir &directory) const;
QString findTopLevelForDirectoryI(const QString &directory) const;
QStringList currentProjectsTopLevels(QString *name = 0) const;
void startCommit(const QString &file);
void startCommit(const QString &workingDir, const QStringList &files = QStringList());
bool commit(const QString &messageFile, const QStringList &subVersionFileList);
void cleanCommitMessageFile();
inline CVSControl *cvsVersionControl() const;
CVSSettings m_settings;
QString m_commitMessageFileName;
ProjectExplorer::ProjectExplorerPlugin *m_projectExplorer;
QString m_commitRepository;
Utils::ParameterAction *m_addAction;
Utils::ParameterAction *m_deleteAction;
Utils::ParameterAction *m_revertAction;
QAction *m_diffProjectAction;
Utils::ParameterAction *m_diffProjectAction;
Utils::ParameterAction *m_diffCurrentAction;
QAction *m_commitAllAction;
Utils::ParameterAction *m_commitCurrentAction;
Utils::ParameterAction *m_filelogCurrentAction;
Utils::ParameterAction *m_annotateCurrentAction;
QAction *m_statusAction;
QAction *m_updateProjectAction;
Utils::ParameterAction *m_statusProjectAction;
Utils::ParameterAction *m_updateProjectAction;
QAction *m_submitCurrentLogAction;
QAction *m_submitDiffAction;
......
......@@ -196,6 +196,7 @@ void GitClient::diff(const QString &workingDirectory,
const QString title = tr("Git Diff");
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, workingDirectory, true, "originalFileName", workingDirectory);
editor->setDiffBaseDirectory(workingDirectory);
// Create a batch of 2 commands to be run after each other in case
// we have a mixture of staged/unstaged files as is the case
......
......@@ -30,9 +30,9 @@
#include "giteditor.h"
#include "annotationhighlighter.h"
#include "gitclient.h"
#include "gitconstants.h"
#include "gitplugin.h"
#include "gitsettings.h"
#include <QtCore/QTextCodec>
#include <coreplugin/editormanager/editormanager.h>
......@@ -122,21 +122,14 @@ VCSBase::BaseAnnotationHighlighter *GitEditor::createAnnotationHighlighter(const
QString GitEditor::fileNameFromDiffSpecification(const QTextBlock &inBlock) const
{
QString errorMessage;
// Check for "+++ b/src/plugins/git/giteditor.cpp" (blame and diff)
// Check for "+++ b/src/plugins/git/giteditor.cpp" (blame and diff)
// Go back chunks.
const QString newFileIndicator = QLatin1String("+++ b/");
for (QTextBlock block = inBlock; block.isValid(); block = block.previous()) {
QString diffFileName = block.text();
if (diffFileName.startsWith(newFileIndicator)) {
diffFileName.remove(0, newFileIndicator.size());
const QString fileOrDir = source();
const QString repo = QFileInfo(fileOrDir).isDir() ?
GitClient::findRepositoryForDirectory(fileOrDir) : GitClient::findRepositoryForFile(fileOrDir);
const QString absPath = QDir(repo).absoluteFilePath(diffFileName);
if (Git::Constants::debug)
qDebug() << "fileNameFromDiffSpecification" << repo << diffFileName << absPath;
return absPath;
return findDiffFile(diffFileName, GitPlugin::instance()->versionControl());
}
}
return QString();
......@@ -195,3 +188,4 @@ void GitEditor::commandFinishedGotoLine(bool ok, const QVariant &v)
} // namespace Internal
} // namespace Git
......@@ -190,6 +190,7 @@ void MercurialClient::diff(const QString &workingDir, const QStringList &files)
const QString source = VCSBase::VCSBaseEditor::getSource(workingDir, files);
VCSBase::VCSBaseEditor *editor = createVCSEditor(kind, title, source, true,
"diff", id);
editor->setDiffBaseDirectory(workingDir);
QSharedPointer<HgTask> job(new HgTask(workingDir, args, editor));
enqueueJob(job);
......
......@@ -30,7 +30,7 @@
#include "mercurialeditor.h"
#include "annotationhighlighter.h"
#include "constants.h"
#include "mercurialclient.h"
#include "mercurialplugin.h"
#include <coreplugin/editormanager/editormanager.h>
#include <vcsbase/diffhighlighter.h>
......@@ -103,10 +103,8 @@ QString MercurialEditor::fileNameFromDiffSpecification(const QTextBlock &diffFil
QTextFragment fragment = iterator.fragment();
if(fragment.isValid()) {
if (fragment.text().startsWith(filechangeId)) {
const QFileInfo sourceFile(source());
const QDir repository(MercurialClient::findTopLevelForFile(sourceFile));
const QString filename = fragment.text().remove(0, filechangeId.size());
return repository.absoluteFilePath(filename);
return findDiffFile(filename, MercurialPlugin::instance()->versionControl());
}
}
}
......
......@@ -451,6 +451,12 @@ void SubversionPlugin::diffCommitFiles(const QStringList &files)
svnDiff(m_commitRepository, files);
}
static inline void setDiffBaseDirectory(Core::IEditor *editor, const QString &db)
{
if (VCSBase::VCSBaseEditor *ve = qobject_cast<VCSBase::VCSBaseEditor*>(editor->widget()))
ve->setDiffBaseDirectory(db);
}
void SubversionPlugin::svnDiff(const QString &workingDir, const QStringList &files, QString diffname)
{
if (Subversion::Constants::debug)
......@@ -475,11 +481,13 @@ void SubversionPlugin::svnDiff(const QString &workingDir, const QStringList &fil
if (Core::IEditor *editor = locateEditor("originalFileName", files.front())) {
editor->createNew(response.stdOut);
Core::EditorManager::instance()->activateEditor(editor);
setDiffBaseDirectory(editor, workingDir);
return;
}
}
const QString title = QString::fromLatin1("svn diff %1").arg(diffname);
Core::IEditor *editor = showOutputInEditor(title, response.stdOut, VCSBase::DiffOutput, source, codec);
setDiffBaseDirectory(editor, workingDir);
if (files.count() == 1)
editor->setProperty("originalFileName", files.front());
}
......
......@@ -147,6 +147,7 @@ struct VCSBaseEditorPrivate
QAction *m_describeAction;
QString m_currentChange;
QString m_source;
QString m_diffBaseDirectory;
QRegExp m_diffFilePattern;
QList<int> m_diffSections; // line number where this section starts
......@@ -210,6 +211,16 @@ void VCSBaseEditor::setSource(const QString &source)
d->m_source = source;
}
QString VCSBaseEditor::diffBaseDirectory() const
{
return d->m_diffBaseDirectory;
}
void VCSBaseEditor::setDiffBaseDirectory(const QString &bd)
{
d->m_diffBaseDirectory = bd;
}
QTextCodec *VCSBaseEditor::codec() const
{
return baseTextDocument()->codec();
......@@ -678,18 +689,25 @@ QString VCSBaseEditor::getTitleId(const QString &workingDirectory, const QString
// Find the complete file from a diff relative specification.
QString VCSBaseEditor::findDiffFile(const QString &f, Core::IVersionControl *control /* = 0 */) const
{
// Try the file.
// Try the file itself, expand to absolute.
const QFileInfo in(f);
if (in.isAbsolute())
return in.isFile() ? f : QString();
if (in.isFile())
return in.absoluteFilePath();
// Try in source directory
// 1) Try base dir
const QChar slash = QLatin1Char('/');
if (!d->m_diffBaseDirectory.isEmpty()) {
const QFileInfo baseFileInfo(d->m_diffBaseDirectory + slash + f);
if (baseFileInfo.isFile())
return baseFileInfo.absoluteFilePath();
}
// 2) Try in source (which can be file or directory)
if (source().isEmpty())
return QString();
const QFileInfo sourceInfo(source());
const QString sourceDir = sourceInfo.isDir() ? sourceInfo.absoluteFilePath() : sourceInfo.absolutePath();
const QFileInfo sourceFileInfo(sourceDir + QLatin1Char('/') + f);
const QFileInfo sourceFileInfo(sourceDir + slash + f);
if (sourceFileInfo.isFile())
return sourceFileInfo.absoluteFilePath();
// Try to locate via repository.
......@@ -698,7 +716,7 @@ QString VCSBaseEditor::findDiffFile(const QString &f, Core::IVersionControl *con
const QString topLevel = control->findTopLevelForDirectory(sourceDir);
if (topLevel.isEmpty())
return QString();
const QFileInfo topLevelFileInfo(topLevel + QLatin1Char('/') + f);
const QFileInfo topLevelFileInfo(topLevel + slash + f);
if (topLevelFileInfo.isFile())
return topLevelFileInfo.absoluteFilePath();
return QString();
......
......@@ -87,6 +87,7 @@ struct VCSBASE_EXPORT VCSBaseEditorParameters {
class VCSBASE_EXPORT VCSBaseEditor : public TextEditor::BaseTextEditor
{
Q_PROPERTY(QString source READ source WRITE setSource)
Q_PROPERTY(QString diffBaseDirectory READ diffBaseDirectory WRITE setDiffBaseDirectory)
Q_PROPERTY(QTextCodec *codec READ codec WRITE setCodec)
Q_OBJECT
protected:
......@@ -105,6 +106,10 @@ public:
QTextCodec *codec() const;
void setCodec(QTextCodec *);
// Base directory for diff views
QString diffBaseDirectory() const;
void setDiffBaseDirectory(const QString &d);
bool isModified() const;
EditorContentType contentType() const;
......@@ -137,7 +142,7 @@ public:
// editor if one has a call consisting of working directory and file arguments.
// ('git diff XX' -> 'XX' , 'git diff XX file' -> 'XX/file').
static QString getSource(const QString &workingDirectory, const QString &fileName);
static QString getSource(const QString &workingDirectory, const QStringList &fileNames);
static QString getSource(const QString &workingDirectory, const QStringList &fileNames);
// Convenience functions to determine an title/id to identify the editor
// from the arguments (','-joined arguments or directory).
static QString getTitleId(const QString &workingDirectory, const QStringList &fileNames);
......@@ -171,8 +176,8 @@ private slots:
protected:
/* A helper that can be used to locate a file in a diff in case it
* is relative. Tries to derive the directory from source and
* version control. */
* is relative. Tries to derive the directory from base directory,
* source and version control. */
QString findDiffFile(const QString &f, Core::IVersionControl *control = 0) const;
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment