From d6e0df1c74045936c5db030e15b094a61de068d2 Mon Sep 17 00:00:00 2001 From: jkobus Date: Fri, 11 Jul 2014 10:34:22 +0200 Subject: [PATCH] Fix reading of git format-patch output Task-number: QTCREATORBUG-12627 Change-Id: I7df1fe27f6502895ab9c82178084d2b631468c5d Reviewed-by: Friedemann Kleint Reviewed-by: Orgad Shaneh --- src/plugins/diffeditor/diffutils.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp index af787f72ff8..c483eb3b89e 100644 --- a/src/plugins/diffeditor/diffutils.cpp +++ b/src/plugins/diffeditor/diffutils.cpp @@ -821,7 +821,7 @@ static QList readDiffPatch(const QString &patch, QList fileDataList; int pos = diffRegExp.indexIn(patch, 0); - if (pos == 0) { // git style patch + if (pos >= 0) { // git style patch readOk = true; int lastPos = -1; do { @@ -1045,7 +1045,7 @@ static QList readGitPatch(const QString &patch, bool ignoreWhitespace, simpleGitMatched = (pos == simpleGitPos); } - if (pos == 0) { // git style patch + if (pos >= 0) { // git style patch readOk = true; int endOfLastHeader = 0; QString lastLeftFileName; @@ -1159,9 +1159,16 @@ QList DiffUtils::readPatch(const QString &patch, bool ignoreWhitespace QList fileDataList; - fileDataList = readGitPatch(patch, ignoreWhitespace, &readOk); + QString croppedPatch = patch; + // Crop e.g. "-- \n1.9.4.msysgit.0\n\n" at end of file + const QRegExp formatPatchEndingRegExp(QLatin1String("(\\n-- \\n\\S*\\n\\n$)")); + const int pos = formatPatchEndingRegExp.indexIn(patch, 0); + if (pos != -1) + croppedPatch = patch.left(pos + 1); // crop the ending for git format-patch + + fileDataList = readGitPatch(croppedPatch, ignoreWhitespace, &readOk); if (!readOk) - fileDataList = readDiffPatch(patch, ignoreWhitespace, &readOk); + fileDataList = readDiffPatch(croppedPatch, ignoreWhitespace, &readOk); if (ok) *ok = readOk;