From 4ed00a348b55bb64332315ebdca2c7c8ec198a7c Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 8 Nov 2016 09:41:43 +0200 Subject: [PATCH] Git: Make mergetool parsing more robust Symbolic link conflict is printed in 2 phases: First " {remote}", and then "a symbolic link -> 'foo.cpp'". This happens because this message involves an additional cat process: elif is_symlink "$mode" then echo "a symbolic link -> '$(cat "$file")'" For local/remote line, wait for a full line before parsing. Change-Id: I641cde12aa44dee2f7dff8fdae70da0c443e55d3 Reviewed-by: Orgad Shaneh --- src/plugins/git/mergetool.cpp | 35 ++++++++++++++++++++++++----------- src/plugins/git/mergetool.h | 1 + 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/plugins/git/mergetool.cpp b/src/plugins/git/mergetool.cpp index 75d2f330b39..f25b9fd2d9b 100644 --- a/src/plugins/git/mergetool.cpp +++ b/src/plugins/git/mergetool.cpp @@ -200,26 +200,39 @@ void MergeTool::prompt(const QString &title, const QString &question) void MergeTool::readData() { + bool waitForFurtherInput = false; while (m_process->bytesAvailable()) { - QByteArray line = m_process->canReadLine() ? m_process->readLine() : m_process->readAllStandardOutput(); + const bool hasLine = m_process->canReadLine(); + const QByteArray line = hasLine ? m_process->readLine() : m_process->readAllStandardOutput(); VcsOutputWindow::append(QString::fromLocal8Bit(line)); + m_line += line; // {Normal|Deleted|Submodule|Symbolic link} merge conflict for 'foo.cpp' - int index = line.indexOf(" merge conflict for "); + const int index = m_line.indexOf(" merge conflict for "); if (index != -1) { - m_mergeType = mergeType(line.left(index)); - int quote = line.indexOf('\''); - m_fileName = QString::fromLocal8Bit(line.mid(quote + 1, line.lastIndexOf('\'') - quote - 1)); - } else if (line.startsWith(" {local}")) { - m_localState = parseStatus(line, m_localInfo); - } else if (line.startsWith(" {remote}")) { - m_remoteState = parseStatus(line, m_remoteInfo); + m_mergeType = mergeType(m_line.left(index)); + int quote = m_line.indexOf('\''); + m_fileName = QString::fromLocal8Bit(m_line.mid(quote + 1, m_line.lastIndexOf('\'') - quote - 1)); + } else if (m_line.startsWith(" {local}")) { + waitForFurtherInput = !hasLine; + if (waitForFurtherInput) + continue; + m_localState = parseStatus(m_line, m_localInfo); + m_line.clear(); + } else if (m_line.startsWith(" {remote}")) { + waitForFurtherInput = !hasLine; + if (waitForFurtherInput) + continue; + m_remoteState = parseStatus(m_line, m_remoteInfo); + m_line.clear(); chooseAction(); - } else if (line.startsWith("Was the merge successful")) { + } else if (m_line.startsWith("Was the merge successful")) { prompt(tr("Unchanged File"), tr("Was the merge successful?")); - } else if (line.startsWith("Continue merging")) { + } else if (m_line.startsWith("Continue merging")) { prompt(tr("Continue Merging"), tr("Continue merging other unresolved paths?")); } } + if (!waitForFurtherInput) + m_line.clear(); } void MergeTool::done() diff --git a/src/plugins/git/mergetool.h b/src/plugins/git/mergetool.h index 7217d473f83..f905cf25a03 100644 --- a/src/plugins/git/mergetool.h +++ b/src/plugins/git/mergetool.h @@ -82,6 +82,7 @@ private: QString m_localInfo; FileState m_remoteState = UnknownState; QString m_remoteInfo; + QByteArray m_line; bool m_merging = false; };