From 63861c44c1e4f9d4cf6a7a48fe9534b4f73d0ad7 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Sun, 26 Nov 2017 10:24:32 +0200 Subject: DiffEditor: Fix parsing of mode-only change in patch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: André Hartmann Reviewed-by: Jarek Kobus --- src/plugins/diffeditor/diffutils.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/plugins/diffeditor/diffutils.cpp') diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp index a9d9b11ae2..69ddbb9ba9 100644 --- a/src/plugins/diffeditor/diffutils.cpp +++ b/src/plugins/diffeditor/diffutils.cpp @@ -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; -- cgit v1.2.1