forked from qt-creator/qt-creator
DiffEditor: Use lambda for the common initialization
Change-Id: I834754f7d52f29257e822464132d5fe24dbf5ec7 Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1037,20 +1037,26 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
|
|||||||
|
|
||||||
QList<FileData> fileDataList;
|
QList<FileData> fileDataList;
|
||||||
|
|
||||||
int simpleGitPos = simpleGitRegExp.indexIn(patch);
|
bool simpleGitMatched;
|
||||||
int similarityPos = similarityRegExp.indexIn(patch);
|
int pos = 0;
|
||||||
|
auto calculateGitMatchAndPosition = [&]() {
|
||||||
bool simpleGitMatched = false;
|
const int simpleGitPos = simpleGitRegExp.indexIn(patch, pos, QRegExp::CaretAtOffset);
|
||||||
int pos = -1;
|
const int similarityPos = similarityRegExp.indexIn(patch, pos, QRegExp::CaretAtOffset);
|
||||||
if (simpleGitPos < 0) {
|
if (simpleGitPos < 0) {
|
||||||
pos = similarityPos;
|
pos = similarityPos;
|
||||||
} else if (similarityPos < 0) {
|
simpleGitMatched = false;
|
||||||
pos = simpleGitPos;
|
return;
|
||||||
simpleGitMatched = true;
|
} else if (similarityPos < 0) {
|
||||||
} else {
|
pos = simpleGitPos;
|
||||||
|
simpleGitMatched = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
pos = qMin(simpleGitPos, similarityPos);
|
pos = qMin(simpleGitPos, similarityPos);
|
||||||
simpleGitMatched = (pos == simpleGitPos);
|
simpleGitMatched = (pos == simpleGitPos);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// Set both pos and simpleGitMatched according to the first match:
|
||||||
|
calculateGitMatchAndPosition();
|
||||||
|
|
||||||
if (pos >= 0) { // git style patch
|
if (pos >= 0) { // git style patch
|
||||||
readOk = true;
|
readOk = true;
|
||||||
@@ -1104,20 +1110,8 @@ static QList<FileData> readGitPatch(const QString &patch, bool ignoreWhitespace,
|
|||||||
break; // either copy or rename, otherwise broken
|
break; // either copy or rename, otherwise broken
|
||||||
}
|
}
|
||||||
|
|
||||||
simpleGitPos = simpleGitRegExp.indexIn(patch, pos, QRegExp::CaretAtOffset);
|
// give both pos and simpleGitMatched a new value for the next match
|
||||||
similarityPos = similarityRegExp.indexIn(patch, pos, QRegExp::CaretAtOffset);
|
calculateGitMatchAndPosition();
|
||||||
|
|
||||||
simpleGitMatched = false;
|
|
||||||
pos = -1;
|
|
||||||
if (simpleGitPos < 0) {
|
|
||||||
pos = similarityPos;
|
|
||||||
} else if (similarityPos < 0) {
|
|
||||||
pos = simpleGitPos;
|
|
||||||
simpleGitMatched = true;
|
|
||||||
} else {
|
|
||||||
pos = qMin(simpleGitPos, similarityPos);
|
|
||||||
simpleGitMatched = (pos == simpleGitPos);
|
|
||||||
}
|
|
||||||
} while (pos != -1);
|
} while (pos != -1);
|
||||||
|
|
||||||
if (endOfLastHeader > 0 && readOk) {
|
if (endOfLastHeader > 0 && readOk) {
|
||||||
|
|||||||
Reference in New Issue
Block a user