Commit 63861c44 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

DiffEditor: Fix parsing of mode-only change in patch

If one of the files has mode-only change, the entire patch
fails as a git patch, and is parsed as a text patch.

Because of that, the prefixes (a/, b/) are not stripped and
jumping to a change by double-clicking does not work.

Change-Id: Ib54ce4fa7aad02cb956af1f7de73d3c732ac5a89
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@qt.io>
parent 8bc3ac91
......@@ -1347,6 +1347,22 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
QTest::newRow("Binary files") << patch
<< fileDataList8;
//////////////
patch = _("diff --git a/script.sh b/script.sh\n"
"old mode 100644\n"
"new mode 100755\n"
);
fileData1 = FileData();
fileData1.leftFileInfo = DiffFileInfo("script.sh");
fileData1.rightFileInfo = DiffFileInfo("script.sh");
fileData1.fileOperation = FileData::ChangeMode;
QList<FileData> fileDataList9;
fileDataList9 << fileData1;
QTest::newRow("Mode change") << patch << fileDataList9;
//////////////
// Subversion New
......@@ -1362,10 +1378,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
chunkData1.leftStartingLineNumber = -1;
chunkData1.rightStartingLineNumber = 124;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList9;
fileDataList9 << fileData1;
QList<FileData> fileDataList21;
fileDataList21 << fileData1;
QTest::newRow("Subversion New") << patch
<< fileDataList9;
<< fileDataList21;
//////////////
......@@ -1382,10 +1398,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
chunkData1.leftStartingLineNumber = 0;
chunkData1.rightStartingLineNumber = -1;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList10;
fileDataList10 << fileData1;
QList<FileData> fileDataList22;
fileDataList22 << fileData1;
QTest::newRow("Subversion Deleted") << patch
<< fileDataList10;
<< fileDataList22;
//////////////
......@@ -1402,10 +1418,10 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
chunkData1.leftStartingLineNumber = 119;
chunkData1.rightStartingLineNumber = 119;
fileData1.chunks << chunkData1;
QList<FileData> fileDataList11;
fileDataList11 << fileData1;
QList<FileData> fileDataList23;
fileDataList23 << fileData1;
QTest::newRow("Subversion Normal") << patch
<< fileDataList11;
<< fileDataList23;
}
void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
......
......@@ -1025,10 +1025,16 @@ static bool detectIndexAndBinary(QStringRef patch,
bool hasNewLine;
*remainingPatch = patch;
if (remainingPatch->isEmpty() && (fileData->fileOperation == FileData::CopyFile
|| fileData->fileOperation == FileData::RenameFile)) {
// in case of 100% similarity we don't have more lines in the patch
return true;
if (remainingPatch->isEmpty()) {
switch (fileData->fileOperation) {
case FileData::CopyFile:
case FileData::RenameFile:
case FileData::ChangeMode:
// in case of 100% similarity we don't have more lines in the patch
return true;
default:
break;
}
}
QStringRef afterNextLine;
......@@ -1151,8 +1157,6 @@ static bool detectFileData(QStringRef patch,
QStringRef afterSecondLine;
const QStringRef secondLine = readLine(afterDiffGit, &afterSecondLine, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
if (secondLine.startsWith(QStringLiteral("new file mode "))) {
fileData->fileOperation = FileData::NewFile;
......@@ -1165,7 +1169,7 @@ static bool detectFileData(QStringRef patch,
// new mode
readLine(afterSecondLine, &afterThirdLine, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
fileData->fileOperation = FileData::ChangeMode;
// TODO: validate new mode line
*remainingPatch = afterThirdLine;
......
......@@ -104,6 +104,7 @@ class DIFFEDITOR_EXPORT FileData {
public:
enum FileOperation {
ChangeFile,
ChangeMode,
NewFile,
DeleteFile,
CopyFile,
......
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