forked from qt-creator/qt-creator
Git: Do not rely on QProcess::readData/writeData in MergeTool
readData always returns 0 in Qt 5.7 (unless the process is not running)... Instead, write to the VCS output pane when reading from/writing to the process. Change-Id: Ie832d813d5a859b4ff5841fd2888783833c97945 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
0c187a2b12
commit
c64b3f9882
@@ -42,29 +42,6 @@ using namespace VcsBase;
|
|||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class MergeToolProcess : public QProcess
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
MergeToolProcess(QObject *parent = 0) : QProcess(parent)
|
|
||||||
{ }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
qint64 readData(char *data, qint64 maxlen) override
|
|
||||||
{
|
|
||||||
qint64 res = QProcess::readData(data, maxlen);
|
|
||||||
if (res > 0)
|
|
||||||
VcsOutputWindow::append(QString::fromLocal8Bit(data, int(res)));
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 writeData(const char *data, qint64 len) override
|
|
||||||
{
|
|
||||||
if (len > 0)
|
|
||||||
VcsOutputWindow::append(QString::fromLocal8Bit(data, int(len)));
|
|
||||||
return QProcess::writeData(data, len);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
MergeTool::MergeTool(QObject *parent) : QObject(parent)
|
MergeTool::MergeTool(QObject *parent) : QObject(parent)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -77,7 +54,7 @@ bool MergeTool::start(const QString &workingDirectory, const QStringList &files)
|
|||||||
{
|
{
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << "mergetool" << "-y" << files;
|
arguments << "mergetool" << "-y" << files;
|
||||||
m_process = new MergeToolProcess(this);
|
m_process = new QProcess(this);
|
||||||
m_process->setWorkingDirectory(workingDirectory);
|
m_process->setWorkingDirectory(workingDirectory);
|
||||||
const Utils::FileName binary = GitPlugin::client()->vcsBinary();
|
const Utils::FileName binary = GitPlugin::client()->vcsBinary();
|
||||||
VcsOutputWindow::appendCommand(workingDirectory, binary, arguments);
|
VcsOutputWindow::appendCommand(workingDirectory, binary, arguments);
|
||||||
@@ -98,7 +75,9 @@ MergeTool::FileState MergeTool::waitAndReadStatus(QString &extraInfo)
|
|||||||
QByteArray state;
|
QByteArray state;
|
||||||
for (int i = 0; i < 5; ++i) {
|
for (int i = 0; i < 5; ++i) {
|
||||||
if (m_process->canReadLine()) {
|
if (m_process->canReadLine()) {
|
||||||
state = m_process->readLine().trimmed();
|
const QByteArray line = m_process->readLine();
|
||||||
|
VcsOutputWindow::append(QString::fromLocal8Bit(line));
|
||||||
|
QByteArray state = line.trimmed();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
m_process->waitForReadyRead(500);
|
m_process->waitForReadyRead(500);
|
||||||
@@ -209,8 +188,7 @@ void MergeTool::chooseAction()
|
|||||||
key = QVariant('a'); // abort
|
key = QVariant('a'); // abort
|
||||||
ba.append(key.toChar().toLatin1());
|
ba.append(key.toChar().toLatin1());
|
||||||
ba.append('\n');
|
ba.append('\n');
|
||||||
m_process->write(ba);
|
write(ba);
|
||||||
m_process->waitForBytesWritten();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MergeTool::addButton(QMessageBox *msgBox, const QString &text, char key)
|
void MergeTool::addButton(QMessageBox *msgBox, const QString &text, char key)
|
||||||
@@ -223,17 +201,17 @@ void MergeTool::prompt(const QString &title, const QString &question)
|
|||||||
if (QMessageBox::question(Core::ICore::dialogParent(), title, question,
|
if (QMessageBox::question(Core::ICore::dialogParent(), title, question,
|
||||||
QMessageBox::Yes | QMessageBox::No,
|
QMessageBox::Yes | QMessageBox::No,
|
||||||
QMessageBox::No) == QMessageBox::Yes) {
|
QMessageBox::No) == QMessageBox::Yes) {
|
||||||
m_process->write("y\n");
|
write("y\n");
|
||||||
} else {
|
} else {
|
||||||
m_process->write("n\n");
|
write("n\n");
|
||||||
}
|
}
|
||||||
m_process->waitForBytesWritten();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MergeTool::readData()
|
void MergeTool::readData()
|
||||||
{
|
{
|
||||||
while (m_process->bytesAvailable()) {
|
while (m_process->bytesAvailable()) {
|
||||||
QByteArray line = m_process->canReadLine() ? m_process->readLine() : m_process->readAllStandardOutput();
|
QByteArray line = m_process->canReadLine() ? m_process->readLine() : m_process->readAllStandardOutput();
|
||||||
|
VcsOutputWindow::append(QString::fromLocal8Bit(line));
|
||||||
// {Normal|Deleted|Submodule|Symbolic link} merge conflict for 'foo.cpp'
|
// {Normal|Deleted|Submodule|Symbolic link} merge conflict for 'foo.cpp'
|
||||||
int index = line.indexOf(" merge conflict for ");
|
int index = line.indexOf(" merge conflict for ");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
@@ -266,5 +244,12 @@ void MergeTool::done()
|
|||||||
deleteLater();
|
deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MergeTool::write(const QByteArray &bytes)
|
||||||
|
{
|
||||||
|
m_process->write(bytes);
|
||||||
|
m_process->waitForBytesWritten();
|
||||||
|
VcsOutputWindow::append(QString::fromLocal8Bit(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Git
|
} // namespace Git
|
||||||
|
@@ -30,12 +30,12 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QMessageBox;
|
class QMessageBox;
|
||||||
|
class QProcess;
|
||||||
QT_END_NAMESPACE
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
class MergeToolProcess;
|
|
||||||
class GitClient;
|
class GitClient;
|
||||||
|
|
||||||
class MergeTool : public QObject
|
class MergeTool : public QObject
|
||||||
@@ -67,6 +67,7 @@ private:
|
|||||||
void prompt(const QString &title, const QString &question);
|
void prompt(const QString &title, const QString &question);
|
||||||
void readData();
|
void readData();
|
||||||
void done();
|
void done();
|
||||||
|
void write(const QByteArray &bytes);
|
||||||
|
|
||||||
FileState waitAndReadStatus(QString &extraInfo);
|
FileState waitAndReadStatus(QString &extraInfo);
|
||||||
QString mergeTypeName();
|
QString mergeTypeName();
|
||||||
@@ -74,7 +75,7 @@ private:
|
|||||||
void chooseAction();
|
void chooseAction();
|
||||||
void addButton(QMessageBox *msgBox, const QString &text, char key);
|
void addButton(QMessageBox *msgBox, const QString &text, char key);
|
||||||
|
|
||||||
MergeToolProcess *m_process = nullptr;
|
QProcess *m_process = nullptr;
|
||||||
MergeType m_mergeType = NormalMerge;
|
MergeType m_mergeType = NormalMerge;
|
||||||
QString m_fileName;
|
QString m_fileName;
|
||||||
FileState m_localState = UnknownState;
|
FileState m_localState = UnknownState;
|
||||||
|
Reference in New Issue
Block a user