Utils: Collapse most of porting,h

Taking the Qt 6 branches, leaving some dummies until downstream
adapted.

Change-Id: Ib9b86568d73c341c8f740ba497c3cbfab830d8a1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
hjk
2022-07-13 09:27:18 +02:00
parent 480da99508
commit 802de0eb5e
82 changed files with 206 additions and 256 deletions

View File

@@ -560,7 +560,7 @@ QString DiffUtils::makePatch(const QList<FileData> &fileDataList, unsigned forma
return diffText;
}
static QList<RowData> readLines(StringView patch, bool lastChunk, bool *lastChunkAtTheEndOfFile, bool *ok)
static QList<RowData> readLines(QStringView patch, bool lastChunk, bool *lastChunkAtTheEndOfFile, bool *ok)
{
QList<Diff> diffList;
@@ -574,10 +574,10 @@ static QList<RowData> readLines(StringView patch, bool lastChunk, bool *lastChun
int noNewLineInDelete = -1;
int noNewLineInInsert = -1;
const QVector<StringView> lines = patch.split(newLine);
const QVector<QStringView> lines = patch.split(newLine);
int i;
for (i = 0; i < lines.size(); i++) {
StringView line = lines.at(i);
QStringView line = lines.at(i);
if (line.isEmpty()) { // need to have at least one character (1 column)
if (lastChunk)
i = lines.size(); // pretend as we've read all the lines (we just ignore the rest)
@@ -730,13 +730,13 @@ static QList<RowData> readLines(StringView patch, bool lastChunk, bool *lastChun
outputRightDiffList).rows;
}
static StringView readLine(StringView text, StringView *remainingText, bool *hasNewLine)
static QStringView readLine(QStringView text, QStringView *remainingText, bool *hasNewLine)
{
const QChar newLine('\n');
const int indexOfFirstNewLine = text.indexOf(newLine);
if (indexOfFirstNewLine < 0) {
if (remainingText)
*remainingText = StringView();
*remainingText = QStringView();
if (hasNewLine)
*hasNewLine = false;
return text;
@@ -751,10 +751,10 @@ static StringView readLine(StringView text, StringView *remainingText, bool *has
return text.left(indexOfFirstNewLine);
}
static bool detectChunkData(StringView chunkDiff, ChunkData *chunkData, StringView *remainingPatch)
static bool detectChunkData(QStringView chunkDiff, ChunkData *chunkData, QStringView *remainingPatch)
{
bool hasNewLine;
const StringView chunkLine = readLine(chunkDiff, remainingPatch, &hasNewLine);
const QStringView chunkLine = readLine(chunkDiff, remainingPatch, &hasNewLine);
const QLatin1String leftPosMarker("@@ -");
const QLatin1String rightPosMarker(" +");
@@ -774,15 +774,15 @@ static bool detectChunkData(StringView chunkDiff, ChunkData *chunkData, StringVi
const int leftPosStart = leftPosIndex + leftPosMarker.size();
const int leftPosLength = rightPosIndex - leftPosStart;
StringView leftPos = chunkLine.mid(leftPosStart, leftPosLength);
QStringView leftPos = chunkLine.mid(leftPosStart, leftPosLength);
const int rightPosStart = rightPosIndex + rightPosMarker.size();
const int rightPosLength = optionalHintIndex - rightPosStart;
StringView rightPos = chunkLine.mid(rightPosStart, rightPosLength);
QStringView rightPos = chunkLine.mid(rightPosStart, rightPosLength);
const int optionalHintStart = optionalHintIndex + optionalHintMarker.size();
const int optionalHintLength = chunkLine.size() - optionalHintStart;
const StringView optionalHint = chunkLine.mid(optionalHintStart, optionalHintLength);
const QStringView optionalHint = chunkLine.mid(optionalHintStart, optionalHintLength);
const QChar comma(',');
bool ok;
@@ -808,7 +808,7 @@ static bool detectChunkData(StringView chunkDiff, ChunkData *chunkData, StringVi
return true;
}
static QList<ChunkData> readChunks(StringView patch, bool *lastChunkAtTheEndOfFile, bool *ok)
static QList<ChunkData> readChunks(QStringView patch, bool *lastChunkAtTheEndOfFile, bool *ok)
{
QList<ChunkData> chunkDataList;
int position = -1;
@@ -834,10 +834,10 @@ static QList<ChunkData> readChunks(StringView patch, bool *lastChunkAtTheEndOfFi
: patch.size());
// extract just one chunk
const StringView chunkDiff = patch.mid(chunkStart, chunkEnd - chunkStart);
const QStringView chunkDiff = patch.mid(chunkStart, chunkEnd - chunkStart);
ChunkData chunkData;
StringView lines;
QStringView lines;
readOk = detectChunkData(chunkDiff, &chunkData, &lines);
if (!readOk)
@@ -857,9 +857,9 @@ static QList<ChunkData> readChunks(StringView patch, bool *lastChunkAtTheEndOfFi
return chunkDataList;
}
static FileData readDiffHeaderAndChunks(StringView headerAndChunks, bool *ok)
static FileData readDiffHeaderAndChunks(QStringView headerAndChunks, bool *ok)
{
StringView patch = headerAndChunks;
QStringView patch = headerAndChunks;
FileData fileData;
bool readOk = false;
@@ -911,7 +911,7 @@ static FileData readDiffHeaderAndChunks(StringView headerAndChunks, bool *ok)
}
static QList<FileData> readDiffPatch(StringView patch, bool *ok, QFutureInterfaceBase *jobController)
static QList<FileData> readDiffPatch(QStringView patch, bool *ok, QFutureInterfaceBase *jobController)
{
const QRegularExpression diffRegExp("(?:\\n|^)" // new line of the beginning of a patch
"(" // either
@@ -943,7 +943,7 @@ static QList<FileData> readDiffPatch(StringView patch, bool *ok, QFutureInterfac
int pos = diffMatch.capturedStart();
if (lastPos >= 0) {
StringView headerAndChunks = patch.mid(lastPos, pos - lastPos);
QStringView headerAndChunks = patch.mid(lastPos, pos - lastPos);
const FileData fileData = readDiffHeaderAndChunks(headerAndChunks,
&readOk);
@@ -959,7 +959,7 @@ static QList<FileData> readDiffPatch(StringView patch, bool *ok, QFutureInterfac
} while (diffMatch.hasMatch());
if (readOk) {
StringView headerAndChunks = patch.mid(lastPos, patch.size() - lastPos - 1);
QStringView headerAndChunks = patch.mid(lastPos, patch.size() - lastPos - 1);
const FileData fileData = readDiffHeaderAndChunks(headerAndChunks,
&readOk);
@@ -1009,7 +1009,7 @@ static QList<FileData> readDiffPatch(StringView patch, bool *ok, QFutureInterfac
// +++ [rightFileNameOrDevNull]\n
// <Chunks>
static bool detectIndexAndBinary(StringView patch, FileData *fileData, StringView *remainingPatch)
static bool detectIndexAndBinary(QStringView patch, FileData *fileData, QStringView *remainingPatch)
{
bool hasNewLine;
*remainingPatch = patch;
@@ -1026,14 +1026,14 @@ static bool detectIndexAndBinary(StringView patch, FileData *fileData, StringVie
}
}
StringView afterNextLine;
QStringView afterNextLine;
// index [leftIndexSha]..[rightIndexSha] <optionally: octalNumber>
const StringView nextLine = readLine(patch, &afterNextLine, &hasNewLine);
const QStringView nextLine = readLine(patch, &afterNextLine, &hasNewLine);
const QLatin1String indexHeader("index ");
if (nextLine.startsWith(indexHeader)) {
const StringView indices = nextLine.mid(indexHeader.size());
const QStringView indices = nextLine.mid(indexHeader.size());
const int dotsPosition = indices.indexOf(QStringLiteral(".."));
if (dotsPosition < 0)
return false;
@@ -1069,14 +1069,14 @@ static bool detectIndexAndBinary(StringView patch, FileData *fileData, StringVie
if (*remainingPatch == binaryLine) {
fileData->binaryFiles = true;
*remainingPatch = StringView();
*remainingPatch = QStringView();
return true;
}
const QString leftStart = "--- " + leftFileName;
StringView afterMinuses;
QStringView afterMinuses;
// --- leftFileName
const StringView minuses = readLine(*remainingPatch, &afterMinuses, &hasNewLine);
const QStringView minuses = readLine(*remainingPatch, &afterMinuses, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
@@ -1084,9 +1084,9 @@ static bool detectIndexAndBinary(StringView patch, FileData *fileData, StringVie
return false;
const QString rightStart = "+++ " + rightFileName;
StringView afterPluses;
QStringView afterPluses;
// +++ rightFileName
const StringView pluses = readLine(afterMinuses, &afterPluses, &hasNewLine);
const QStringView pluses = readLine(afterMinuses, &afterPluses, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
@@ -1097,7 +1097,7 @@ static bool detectIndexAndBinary(StringView patch, FileData *fileData, StringVie
return true;
}
static bool extractCommonFileName(StringView fileNames, StringView *fileName)
static bool extractCommonFileName(QStringView fileNames, QStringView *fileName)
{
// we should have 1 space between filenames
if (fileNames.size() % 2 == 0)
@@ -1112,10 +1112,10 @@ static bool extractCommonFileName(StringView fileNames, StringView *fileName)
return false;
// drop "a/"
const StringView leftFileName = fileNames.mid(2, fileNameSize - 2);
const QStringView leftFileName = fileNames.mid(2, fileNameSize - 2);
// drop the first filename + " b/"
const StringView rightFileName = fileNames.mid(fileNameSize + 3, fileNameSize - 2);
const QStringView rightFileName = fileNames.mid(fileNameSize + 3, fileNameSize - 2);
if (leftFileName != rightFileName)
return false;
@@ -1124,27 +1124,27 @@ static bool extractCommonFileName(StringView fileNames, StringView *fileName)
return true;
}
static bool detectFileData(StringView patch, FileData *fileData, StringView *remainingPatch)
static bool detectFileData(QStringView patch, FileData *fileData, QStringView *remainingPatch)
{
bool hasNewLine;
StringView afterDiffGit;
QStringView afterDiffGit;
// diff --git a/leftFileName b/rightFileName
const StringView diffGit = readLine(patch, &afterDiffGit, &hasNewLine);
const QStringView diffGit = readLine(patch, &afterDiffGit, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
const QLatin1String gitHeader("diff --git ");
const StringView fileNames = diffGit.mid(gitHeader.size());
StringView commonFileName;
const QStringView fileNames = diffGit.mid(gitHeader.size());
QStringView commonFileName;
if (extractCommonFileName(fileNames, &commonFileName)) {
// change / new / delete
fileData->fileOperation = FileData::ChangeFile;
fileData->leftFileInfo.fileName = fileData->rightFileInfo.fileName = commonFileName.toString();
StringView afterSecondLine;
const StringView secondLine = readLine(afterDiffGit, &afterSecondLine, &hasNewLine);
QStringView afterSecondLine;
const QStringView secondLine = readLine(afterDiffGit, &afterSecondLine, &hasNewLine);
if (secondLine.startsWith(QStringLiteral("new file mode "))) {
fileData->fileOperation = FileData::NewFile;
@@ -1153,7 +1153,7 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem
fileData->fileOperation = FileData::DeleteFile;
*remainingPatch = afterSecondLine;
} else if (secondLine.startsWith(QStringLiteral("old mode "))) {
StringView afterThirdLine;
QStringView afterThirdLine;
// new mode
readLine(afterSecondLine, &afterThirdLine, &hasNewLine);
if (!hasNewLine)
@@ -1167,9 +1167,9 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem
} else {
// copy / rename
StringView afterModeOrSimilarity;
StringView afterSimilarity;
const StringView secondLine = readLine(afterDiffGit, &afterModeOrSimilarity, &hasNewLine);
QStringView afterModeOrSimilarity;
QStringView afterSimilarity;
const QStringView secondLine = readLine(afterDiffGit, &afterModeOrSimilarity, &hasNewLine);
if (secondLine.startsWith(QLatin1String("old mode "))) {
if (!hasNewLine)
return false;
@@ -1187,9 +1187,9 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem
// TODO: validate similarity line
StringView afterCopyRenameFrom;
QStringView afterCopyRenameFrom;
// [copy / rename] from leftFileName
const StringView copyRenameFrom = readLine(afterSimilarity, &afterCopyRenameFrom, &hasNewLine);
const QStringView copyRenameFrom = readLine(afterSimilarity, &afterCopyRenameFrom, &hasNewLine);
if (!hasNewLine)
return false; // we need to have at least one more line
@@ -1205,9 +1205,9 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem
return false;
}
StringView afterCopyRenameTo;
QStringView afterCopyRenameTo;
// [copy / rename] to rightFileName
const StringView copyRenameTo = readLine(afterCopyRenameFrom, &afterCopyRenameTo, &hasNewLine);
const QStringView copyRenameTo = readLine(afterCopyRenameFrom, &afterCopyRenameTo, &hasNewLine);
// if (dis)similarity index is 100% we don't have more lines
@@ -1226,7 +1226,7 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem
return detectIndexAndBinary(*remainingPatch, fileData, remainingPatch);
}
static QList<FileData> readGitPatch(StringView patch, bool *ok, QFutureInterfaceBase *jobController)
static QList<FileData> readGitPatch(QStringView patch, bool *ok, QFutureInterfaceBase *jobController)
{
int position = -1;
@@ -1239,7 +1239,7 @@ static QList<FileData> readGitPatch(StringView patch, bool *ok, QFutureInterface
class PatchInfo {
public:
StringView patch;
QStringView patch;
FileData fileData;
};
@@ -1261,10 +1261,10 @@ static QList<FileData> readGitPatch(StringView patch, bool *ok, QFutureInterface
: patch.size());
// extract the patch for just one file
const StringView fileDiff = patch.mid(diffStart, diffEnd - diffStart);
const QStringView fileDiff = patch.mid(diffStart, diffEnd - diffStart);
FileData fileData;
StringView remainingFileDiff;
QStringView remainingFileDiff;
readOk = detectFileData(fileDiff, &fileData, &remainingFileDiff);
if (!readOk)
@@ -1324,7 +1324,7 @@ QList<FileData> DiffUtils::readPatch(const QString &patch, bool *ok,
jobController->setProgressRange(0, 1);
jobController->setProgressValue(0);
}
StringView croppedPatch = make_stringview(patch);
QStringView croppedPatch = QStringView(patch);
// Crop e.g. "-- \n2.10.2.windows.1\n\n" at end of file
const QRegularExpression formatPatchEndingRegExp("(\\n-- \\n\\S*\\n\\n$)");
const QRegularExpressionMatch match = formatPatchEndingRegExp.match(croppedPatch);