Fix reading of git format-patch output

Task-number: QTCREATORBUG-12627
Change-Id: I7df1fe27f6502895ab9c82178084d2b631468c5d
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
jkobus
2014-07-11 10:34:22 +02:00
committed by Tobias Hunger
parent ea675821e3
commit d6e0df1c74

View File

@@ -821,7 +821,7 @@ static QList<FileData> readDiffPatch(const QString &patch,
QList<FileData> fileDataList; QList<FileData> fileDataList;
int pos = diffRegExp.indexIn(patch, 0); int pos = diffRegExp.indexIn(patch, 0);
if (pos == 0) { // git style patch if (pos >= 0) { // git style patch
readOk = true; readOk = true;
int lastPos = -1; int lastPos = -1;
do { do {
@@ -1045,7 +1045,7 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
simpleGitMatched = (pos == simpleGitPos); simpleGitMatched = (pos == simpleGitPos);
} }
if (pos == 0) { // git style patch if (pos >= 0) { // git style patch
readOk = true; readOk = true;
int endOfLastHeader = 0; int endOfLastHeader = 0;
QString lastLeftFileName; QString lastLeftFileName;
@@ -1159,9 +1159,16 @@ QList<FileData> DiffUtils::readPatch(const QString &patch, bool ignoreWhitespace
QList<FileData> fileDataList; QList<FileData> 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) if (!readOk)
fileDataList = readDiffPatch(patch, ignoreWhitespace, &readOk); fileDataList = readDiffPatch(croppedPatch, ignoreWhitespace, &readOk);
if (ok) if (ok)
*ok = readOk; *ok = readOk;