Commit 3907824b authored by cerf's avatar cerf Committed by Tobias Hunger
Browse files

vcsbase: refactor status parsing in VCSBaseClient



This impacts Bazaar and Mercurial plugins

Change-Id: Ife1e83083b268e597928fbae30378e488e31ee96
Merge-request: 358
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/3335
parent 96819ddb
......@@ -234,48 +234,48 @@ QStringList BazaarClient::viewArguments(const QString &revision) const
return args;
}
QPair<QString, QString> BazaarClient::parseStatusLine(const QString &line) const
BazaarClient::StatusItem BazaarClient::parseStatusLine(const QString &line) const
{
QPair<QString, QString> status;
StatusItem item;
if (!line.isEmpty()) {
const QChar flagVersion = line[0];
if (flagVersion == QLatin1Char('+'))
status.first = QLatin1String("Versioned");
item.flags = QLatin1String("Versioned");
else if (flagVersion == QLatin1Char('-'))
status.first = QLatin1String("Unversioned");
item.flags = QLatin1String("Unversioned");
else if (flagVersion == QLatin1Char('R'))
status.first = QLatin1String("Renamed");
item.flags = QLatin1String("Renamed");
else if (flagVersion == QLatin1Char('?'))
status.first = QLatin1String("Unknown");
item.flags = QLatin1String("Unknown");
else if (flagVersion == QLatin1Char('X'))
status.first = QLatin1String("Nonexistent");
item.flags = QLatin1String("Nonexistent");
else if (flagVersion == QLatin1Char('C'))
status.first = QLatin1String("Conflict");
item.flags = QLatin1String("Conflict");
else if (flagVersion == QLatin1Char('P'))
status.first = QLatin1String("PendingMerge");
item.flags = QLatin1String("PendingMerge");
const int lineLength = line.length();
if (lineLength >= 2) {
const QChar flagContents = line[1];
if (flagContents == QLatin1Char('N'))
status.first = QLatin1String("Created");
item.flags = QLatin1String("Created");
else if (flagContents == QLatin1Char('D'))
status.first = QLatin1String("Deleted");
item.flags = QLatin1String("Deleted");
else if (flagContents == QLatin1Char('K'))
status.first = QLatin1String("KindChanged");
item.flags = QLatin1String("KindChanged");
else if (flagContents == QLatin1Char('M'))
status.first = QLatin1String("Modified");
item.flags = QLatin1String("Modified");
}
if (lineLength >= 3) {
const QChar flagExec = line[2];
if (flagExec == QLatin1Char('*'))
status.first = QLatin1String("ExecuteBitChanged");
item.flags = QLatin1String("ExecuteBitChanged");
}
// The status string should be similar to "xxx file_with_changes"
// so just should take the file name part and store it
status.second = line.mid(4);
item.file = line.mid(4);
}
return status;
return item;
}
// Collect all parameters required for a diff or log to be able to associate
......
......@@ -86,7 +86,7 @@ protected:
QStringList statusArguments(const QString &file) const;
QStringList viewArguments(const QString &revision) const;
QPair<QString, QString> parseStatusLine(const QString &line) const;
StatusItem parseStatusLine(const QString &line) const;
private:
friend class CloneWizard;
};
......
......@@ -541,17 +541,17 @@ void BazaarPlugin::commit()
m_submitRepository = state.topLevel();
connect(m_client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
connect(m_client, SIGNAL(parsedStatus(QList<VCSBase::VCSBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VCSBase::VCSBaseClient::StatusItem>)));
m_client->statusWithSignal(m_submitRepository);
}
void BazaarPlugin::showCommitWidget(const QList<QPair<QString, QString> > &status)
void BazaarPlugin::showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusItem> &status)
{
VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
//Once we receive our data release the connection so it can be reused elsewhere
disconnect(m_client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
disconnect(m_client, SIGNAL(parsedStatus(QList<VCSBase::VCSBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VCSBase::VCSBaseClient::StatusItem>)));
if (status.isEmpty()) {
outputWindow->appendError(tr("There are no changes to commit."));
......
......@@ -36,6 +36,7 @@
#include "bazaarsettings.h"
#include <vcsbase/vcsbaseclientsettings.h>
#include <vcsbase/vcsbaseclient.h>
#include <vcsbase/vcsbaseplugin.h>
#include <coreplugin/icontext.h>
......@@ -113,7 +114,7 @@ private slots:
void push();
void update();
void commit();
void showCommitWidget(const QList<QPair<QString, QString> > &status);
void showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusItem> &status);
void commitFromEditor();
void diffFromEditorSelected(const QStringList &files);
......
......@@ -62,7 +62,7 @@ BazaarCommitWidget *CommitEditor::commitWidget()
void CommitEditor::setFields(const BranchInfo &branch,
const QString &userName, const QString &email,
const QList<QPair<QString, QString> > &repoStatus)
const QList<VCSBase::VCSBaseClient::StatusItem> &repoStatus)
{
BazaarCommitWidget *bazaarWidget = commitWidget();
if (!bazaarWidget)
......@@ -71,9 +71,8 @@ void CommitEditor::setFields(const BranchInfo &branch,
bazaarWidget->setFields(branch, userName, email);
m_fileModel = new VCSBase::SubmitFileModel(this);
typedef QPair<QString, QString> StringPair;
foreach (const StringPair &status, repoStatus)
if (status.first != QLatin1String("Unknown"))
m_fileModel->addFile(status.second, status.first, true);
foreach (const VCSBase::VCSBaseClient::StatusItem &item, repoStatus)
if (item.flags != QLatin1String("Unknown"))
m_fileModel->addFile(item.file, item.flags, true);
setFileModel(m_fileModel);
}
......@@ -33,6 +33,7 @@
#ifndef COMMITEDITOR_H
#define COMMITEDITOR_H
#include <vcsbase/vcsbaseclient.h>
#include <vcsbase/vcsbasesubmiteditor.h>
namespace VCSBase {
......@@ -54,7 +55,7 @@ public:
void setFields(const BranchInfo &branch,
const QString &userName, const QString &email,
const QList<QPair<QString, QString> > &repoStatus);
const QList<VCSBase::VCSBaseClient::StatusItem> &repoStatus);
const BazaarCommitWidget *commitWidget() const;
......
......@@ -55,7 +55,7 @@ MercurialCommitWidget *CommitEditor::commitWidget()
void CommitEditor::setFields(const QFileInfo &repositoryRoot, const QString &branch,
const QString &userName, const QString &email,
const QList<QPair<QString, QString> > &repoStatus)
const QList<VCSBase::VCSBaseClient::StatusItem> &repoStatus)
{
MercurialCommitWidget *mercurialWidget = commitWidget();
if (!mercurialWidget)
......@@ -66,23 +66,22 @@ void CommitEditor::setFields(const QFileInfo &repositoryRoot, const QString &bra
fileModel = new VCSBase::SubmitFileModel(this);
//TODO Messy tidy this up
typedef QPair<QString, QString> StringStringPair;
QStringList shouldTrack;
foreach (const StringStringPair &status, repoStatus) {
if (status.first == QLatin1String("Untracked"))
shouldTrack.append(status.second);
foreach (const VCSBase::VCSBaseClient::StatusItem &item, repoStatus) {
if (item.flags == QLatin1String("Untracked"))
shouldTrack.append(item.file);
else
fileModel->addFile(status.second, status.first, false);
fileModel->addFile(item.file, item.flags, false);
}
VCSBase::VCSBaseSubmitEditor::filterUntrackedFilesOfProject(repositoryRoot.absoluteFilePath(),
&shouldTrack);
foreach (const QString &track, shouldTrack) {
foreach (const StringStringPair &status, repoStatus) {
if (status.second == track)
fileModel->addFile(status.second, status.first, false);
foreach (const VCSBase::VCSBaseClient::StatusItem &item, repoStatus) {
if (item.file == track)
fileModel->addFile(item.file, item.flags, false);
}
}
......
......@@ -33,6 +33,7 @@
#ifndef COMMITEDITOR_H
#define COMMITEDITOR_H
#include <vcsbase/vcsbaseclient.h>
#include <vcsbase/vcsbasesubmiteditor.h>
#include <QtCore/QFileInfo>
......@@ -55,7 +56,7 @@ public:
void setFields(const QFileInfo &repositoryRoot, const QString &branch,
const QString &userName, const QString &email,
const QList<QPair<QString, QString> > &repoStatus);
const QList<VCSBase::VCSBaseClient::StatusItem> &repoStatus);
QString committerInfo();
QString repoRoot();
......
......@@ -452,29 +452,29 @@ QStringList MercurialClient::viewArguments(const QString &revision) const
return args;
}
QPair<QString, QString> MercurialClient::parseStatusLine(const QString &line) const
MercurialClient::StatusItem MercurialClient::parseStatusLine(const QString &line) const
{
QPair<QString, QString> status;
StatusItem item;
if (!line.isEmpty())
{
if (line.startsWith(QLatin1Char('M')))
status.first = QLatin1String("Modified");
item.flags = QLatin1String("Modified");
else if (line.startsWith(QLatin1Char('A')))
status.first = QLatin1String("Added");
item.flags = QLatin1String("Added");
else if (line.startsWith(QLatin1Char('R')))
status.first = QLatin1String("Removed");
item.flags = QLatin1String("Removed");
else if (line.startsWith(QLatin1Char('!')))
status.first = QLatin1String("Deleted");
item.flags = QLatin1String("Deleted");
else if (line.startsWith(QLatin1Char('?')))
status.first = QLatin1String("Untracked");
item.flags = QLatin1String("Untracked");
else
return status;
return item;
//the status line should be similar to "M file_with_changes"
//so just should take the file name part and store it
status.second = line.mid(2);
item.file = line.mid(2);
}
return status;
return item;
}
// Collect all parameters required for a diff to be able to associate them
......
......@@ -100,7 +100,7 @@ protected:
QStringList statusArguments(const QString &file) const;
QStringList viewArguments(const QString &revision) const;
QPair<QString, QString> parseStatusLine(const QString &line) const;
StatusItem parseStatusLine(const QString &line) const;
};
} //namespace Internal
......
......@@ -566,18 +566,18 @@ void MercurialPlugin::commit()
m_submitRepository = state.topLevel();
connect(m_client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
connect(m_client, SIGNAL(parsedStatus(QList<VCSBase::VCSBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VCSBase::VCSBaseClient::StatusItem>)));
m_client->statusWithSignal(m_submitRepository);
}
void MercurialPlugin::showCommitWidget(const QList<QPair<QString, QString> > &status)
void MercurialPlugin::showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusItem> &status)
{
VCSBase::VCSBaseOutputWindow *outputWindow = VCSBase::VCSBaseOutputWindow::instance();
//Once we receive our data release the connection so it can be reused elsewhere
disconnect(m_client, SIGNAL(parsedStatus(QList<QPair<QString,QString> >)),
this, SLOT(showCommitWidget(QList<QPair<QString,QString> >)));
disconnect(m_client, SIGNAL(parsedStatus(QList<VCSBase::VCSBaseClient::StatusItem>)),
this, SLOT(showCommitWidget(QList<VCSBase::VCSBaseClient::StatusItem>)));
if (status.isEmpty()) {
outputWindow->appendError(tr("There are no changes to commit."));
......
......@@ -35,6 +35,7 @@
#include "mercurialsettings.h"
#include <vcsbase/vcsbaseclient.h>
#include <vcsbase/vcsbaseplugin.h>
#include <coreplugin/icontext.h>
......@@ -118,7 +119,7 @@ private slots:
void incoming();
void outgoing();
void commit();
void showCommitWidget(const QList<QPair<QString, QString> > &status);
void showCommitWidget(const QList<VCSBase::VCSBaseClient::StatusItem> &status);
void commitFromEditor();
void diffFromEditorSelected(const QStringList &files);
......
......@@ -102,17 +102,17 @@ VCSBaseClientPrivate::VCSBaseClientPrivate(VCSBaseClient *client, VCSBaseClientS
void VCSBaseClientPrivate::statusParser(QByteArray data)
{
QList<QPair<QString, QString> > statusList;
QList<VCSBaseClient::StatusItem> lineInfoList;
QStringList rawStatusList = QTextCodec::codecForLocale()->toUnicode(data).split(QLatin1Char('\n'));
foreach (const QString &string, rawStatusList) {
QPair<QString, QString> status = m_client->parseStatusLine(string);
if (!status.first.isEmpty() && !status.second.isEmpty())
statusList.append(status);
const VCSBaseClient::StatusItem lineInfo = m_client->parseStatusLine(string);
if (!lineInfo.flags.isEmpty() && !lineInfo.file.isEmpty())
lineInfoList.append(lineInfo);
}
emit m_client->parsedStatus(statusList);
emit m_client->parsedStatus(lineInfoList);
}
void VCSBaseClientPrivate::annotateRevision(QString source, QString change, int lineNumber)
......@@ -131,6 +131,15 @@ void VCSBaseClientPrivate::saveSettings()
m_clientSettings->writeSettings(m_core->settings());
}
VCSBaseClient::StatusItem::StatusItem()
{
}
VCSBaseClient::StatusItem::StatusItem(const QString &s, const QString &f) :
flags(s), file(f)
{
}
VCSBaseClient::VCSBaseClient(VCSBaseClientSettings *settings) :
d(new VCSBaseClientPrivate(this, settings))
{
......
......@@ -67,6 +67,14 @@ class VCSBASE_EXPORT VCSBaseClient : public QObject
{
Q_OBJECT
public:
struct VCSBASE_EXPORT StatusItem
{
StatusItem();
StatusItem(const QString &s, const QString &f);
QString flags;
QString file;
};
explicit VCSBaseClient(VCSBaseClientSettings *settings);
~VCSBaseClient();
virtual bool synchronousCreateRepository(const QString &workingDir);
......@@ -107,7 +115,7 @@ public:
virtual VCSBaseClientSettings *settings() const;
signals:
void parsedStatus(const QList<QPair<QString, QString> > &statusList);
void parsedStatus(const QList<VCSBase::VCSBaseClient::StatusItem> &statusList);
// Passes on changed signals from VCSJob to Control
void changed(const QVariant &v);
......@@ -166,7 +174,7 @@ protected:
virtual QStringList statusArguments(const QString &file) const = 0;
virtual QStringList viewArguments(const QString &revision) const = 0;
virtual QPair<QString, QString> parseStatusLine(const QString &line) const = 0;
virtual StatusItem parseStatusLine(const QString &line) const = 0;
QString vcsEditorTitle(const QString &vcsCmd, const QString &sourceId) const;
void enqueueJob(const QSharedPointer<VCSJob> &);
......
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