forked from qt-creator/qt-creator
DiffEditor: Fix DiffEditor tests
Amends 5ff073df19
Change-Id: I4597453b057dfce41b73b4973205cba33d8e4a58
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -936,7 +936,7 @@ QString Diff::toString() const
|
|||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
|
||||||
Differ::Differ(const QFuture<void> &future)
|
Differ::Differ(const std::optional<QFuture<void>> &future)
|
||||||
: m_future(future)
|
: m_future(future)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1073,7 +1073,7 @@ QList<Diff> Differ::diffMyers(const QString &text1, const QString &text2)
|
|||||||
int kMinReverse = -D;
|
int kMinReverse = -D;
|
||||||
int kMaxReverse = D;
|
int kMaxReverse = D;
|
||||||
for (int d = 0; d <= D; d++) {
|
for (int d = 0; d <= D; d++) {
|
||||||
if (m_future.isCanceled()) {
|
if (m_future && m_future->isCanceled()) {
|
||||||
delete [] forwardV;
|
delete [] forwardV;
|
||||||
delete [] reverseV;
|
delete [] reverseV;
|
||||||
return QList<Diff>();
|
return QList<Diff>();
|
||||||
@@ -1192,7 +1192,7 @@ QList<Diff> Differ::diffNonCharMode(const QString &text1, const QString &text2)
|
|||||||
QString lastInsert;
|
QString lastInsert;
|
||||||
QList<Diff> newDiffList;
|
QList<Diff> newDiffList;
|
||||||
for (int i = 0; i <= diffList.count(); i++) {
|
for (int i = 0; i <= diffList.count(); i++) {
|
||||||
if (m_future.isCanceled()) {
|
if (m_future && m_future->isCanceled()) {
|
||||||
m_currentDiffMode = diffMode;
|
m_currentDiffMode = diffMode;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
template <class K, class T>
|
template <class K, class T>
|
||||||
class QMap;
|
class QMap;
|
||||||
@@ -42,7 +44,7 @@ public:
|
|||||||
WordMode,
|
WordMode,
|
||||||
LineMode
|
LineMode
|
||||||
};
|
};
|
||||||
Differ(const QFuture<void> &future = {});
|
Differ(const std::optional<QFuture<void>> &future = {});
|
||||||
QList<Diff> diff(const QString &text1, const QString &text2);
|
QList<Diff> diff(const QString &text1, const QString &text2);
|
||||||
QList<Diff> unifiedDiff(const QString &text1, const QString &text2);
|
QList<Diff> unifiedDiff(const QString &text1, const QString &text2);
|
||||||
void setDiffMode(DiffMode mode);
|
void setDiffMode(DiffMode mode);
|
||||||
@@ -90,7 +92,7 @@ private:
|
|||||||
int subTextStart);
|
int subTextStart);
|
||||||
DiffMode m_diffMode = Differ::LineMode;
|
DiffMode m_diffMode = Differ::LineMode;
|
||||||
DiffMode m_currentDiffMode = Differ::LineMode;
|
DiffMode m_currentDiffMode = Differ::LineMode;
|
||||||
QFuture<void> m_future;
|
std::optional<QFuture<void>> m_future;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Utils
|
} // namespace Utils
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ static QList<RowData> readLines(QStringView patch, bool lastChunk, bool *lastChu
|
|||||||
int noNewLineInDelete = -1;
|
int noNewLineInDelete = -1;
|
||||||
int noNewLineInInsert = -1;
|
int noNewLineInInsert = -1;
|
||||||
|
|
||||||
const QVector<QStringView> lines = patch.split(newLine);
|
const QList<QStringView> lines = patch.split(newLine);
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < lines.size(); i++) {
|
for (i = 0; i < lines.size(); i++) {
|
||||||
QStringView line = lines.at(i);
|
QStringView line = lines.at(i);
|
||||||
@@ -795,7 +795,7 @@ static QList<ChunkData> readChunks(QStringView patch, bool *lastChunkAtTheEndOfF
|
|||||||
QList<ChunkData> chunkDataList;
|
QList<ChunkData> chunkDataList;
|
||||||
int position = -1;
|
int position = -1;
|
||||||
|
|
||||||
QVector<int> startingPositions; // store starting positions of @@
|
QList<int> startingPositions; // store starting positions of @@
|
||||||
if (patch.startsWith(QStringLiteral("@@ -")))
|
if (patch.startsWith(QStringLiteral("@@ -")))
|
||||||
startingPositions.append(position + 1);
|
startingPositions.append(position + 1);
|
||||||
|
|
||||||
@@ -1199,7 +1199,7 @@ static void readGitPatch(QPromise<QList<FileData>> &promise, QStringView patch)
|
|||||||
{
|
{
|
||||||
int position = -1;
|
int position = -1;
|
||||||
|
|
||||||
QVector<int> startingPositions; // store starting positions of git headers
|
QList<int> startingPositions; // store starting positions of git headers
|
||||||
if (patch.startsWith(QStringLiteral("diff --git ")))
|
if (patch.startsWith(QStringLiteral("diff --git ")))
|
||||||
startingPositions.append(position + 1);
|
startingPositions.append(position + 1);
|
||||||
|
|
||||||
@@ -1214,7 +1214,7 @@ static void readGitPatch(QPromise<QList<FileData>> &promise, QStringView patch)
|
|||||||
|
|
||||||
const QChar newLine('\n');
|
const QChar newLine('\n');
|
||||||
|
|
||||||
QVector<PatchInfo> patches;
|
QList<PatchInfo> patches;
|
||||||
const int count = startingPositions.size();
|
const int count = startingPositions.size();
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (promise.isCanceled())
|
if (promise.isCanceled())
|
||||||
@@ -1239,10 +1239,12 @@ static void readGitPatch(QPromise<QList<FileData>> &promise, QStringView patch)
|
|||||||
patches.append(PatchInfo { remainingFileDiff, fileData });
|
patches.append(PatchInfo { remainingFileDiff, fileData });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (patches.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
promise.setProgressRange(0, patches.size());
|
promise.setProgressRange(0, patches.size());
|
||||||
|
|
||||||
QList<FileData> fileDataList;
|
QList<FileData> fileDataList;
|
||||||
bool readOk = false;
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (const auto &patchInfo : std::as_const(patches)) {
|
for (const auto &patchInfo : std::as_const(patches)) {
|
||||||
if (promise.isCanceled())
|
if (promise.isCanceled())
|
||||||
@@ -1250,6 +1252,7 @@ static void readGitPatch(QPromise<QList<FileData>> &promise, QStringView patch)
|
|||||||
promise.setProgressValue(i++);
|
promise.setProgressValue(i++);
|
||||||
|
|
||||||
FileData fileData = patchInfo.fileData;
|
FileData fileData = patchInfo.fileData;
|
||||||
|
bool readOk = false;
|
||||||
if (!patchInfo.patch.isEmpty() || fileData.fileOperation == FileData::ChangeFile)
|
if (!patchInfo.patch.isEmpty() || fileData.fileOperation == FileData::ChangeFile)
|
||||||
fileData.chunks = readChunks(patchInfo.patch, &fileData.lastChunkAtTheEndOfFile, &readOk);
|
fileData.chunks = readChunks(patchInfo.patch, &fileData.lastChunkAtTheEndOfFile, &readOk);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user