forked from qt-creator/qt-creator
DiffEditor: Support patch with new/deleted file
Change-Id: I669564355e27dc06464fc8d8641b2f4255c8965e Reviewed-by: Jarek Kobus <jaroslaw.kobus@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
67561efd29
commit
5e883e5b4d
@@ -453,7 +453,22 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
"+}\n"
|
"+}\n"
|
||||||
"+\n"
|
"+\n"
|
||||||
" } // namespace Internal\n"
|
" } // namespace Internal\n"
|
||||||
" } // namespace DiffEditor\n");
|
" } // namespace DiffEditor\n"
|
||||||
|
"diff --git a/new b/new\n"
|
||||||
|
"new file mode 100644\n"
|
||||||
|
"index 0000000..257cc56\n"
|
||||||
|
"--- /dev/null\n"
|
||||||
|
"+++ b/new\n"
|
||||||
|
"@@ -0,0 +1 @@\n"
|
||||||
|
"+foo\n"
|
||||||
|
"diff --git a/deleted b/deleted\n"
|
||||||
|
"deleted file mode 100644\n"
|
||||||
|
"index 257cc56..0000000\n"
|
||||||
|
"--- a/deleted\n"
|
||||||
|
"+++ /dev/null\n"
|
||||||
|
"@@ -1 +0,0 @@\n"
|
||||||
|
"-foo\n"
|
||||||
|
);
|
||||||
|
|
||||||
FileData fileData1;
|
FileData fileData1;
|
||||||
fileData1.leftFileInfo = DiffFileInfo(QLatin1String("src/plugins/diffeditor/diffeditor.cpp"),
|
fileData1.leftFileInfo = DiffFileInfo(QLatin1String("src/plugins/diffeditor/diffeditor.cpp"),
|
||||||
@@ -510,9 +525,34 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
|
|||||||
chunkData2.rows = rows2;
|
chunkData2.rows = rows2;
|
||||||
fileData2.chunks.append(chunkData2);
|
fileData2.chunks.append(chunkData2);
|
||||||
|
|
||||||
|
FileData fileData3;
|
||||||
|
fileData3.leftFileInfo = DiffFileInfo(QLatin1String("new"), QLatin1String("0000000"));
|
||||||
|
fileData3.rightFileInfo = DiffFileInfo(QLatin1String("new"), QLatin1String("257cc56"));
|
||||||
|
ChunkData chunkData3;
|
||||||
|
chunkData3.leftStartingLineNumber = -1;
|
||||||
|
chunkData3.rightStartingLineNumber = 0;
|
||||||
|
QList<RowData> rows3;
|
||||||
|
rows3.append(RowData(TextLineData::Separator, TextLineData(QLatin1String("foo"))));
|
||||||
|
TextLineData textLineData3(TextLineData::TextLine);
|
||||||
|
rows3.append(RowData(TextLineData::Separator, textLineData3));
|
||||||
|
chunkData3.rows = rows3;
|
||||||
|
fileData3.chunks.append(chunkData3);
|
||||||
|
|
||||||
|
FileData fileData4;
|
||||||
|
fileData4.leftFileInfo = DiffFileInfo(QLatin1String("deleted"), QLatin1String("257cc56"));
|
||||||
|
fileData4.rightFileInfo = DiffFileInfo(QLatin1String("deleted"), QLatin1String("0000000"));
|
||||||
|
ChunkData chunkData4;
|
||||||
|
chunkData4.leftStartingLineNumber = 0;
|
||||||
|
chunkData4.rightStartingLineNumber = -1;
|
||||||
|
QList<RowData> rows4;
|
||||||
|
rows4.append(RowData(TextLineData(QLatin1String("foo")), TextLineData::Separator));
|
||||||
|
TextLineData textLineData4(TextLineData::TextLine);
|
||||||
|
rows4.append(RowData(textLineData4, TextLineData::Separator));
|
||||||
|
chunkData4.rows = rows4;
|
||||||
|
fileData4.chunks.append(chunkData4);
|
||||||
|
|
||||||
QList<FileData> fileDataList;
|
QList<FileData> fileDataList;
|
||||||
fileDataList.append(fileData1);
|
fileDataList << fileData1 << fileData2 << fileData3 << fileData4;
|
||||||
fileDataList.append(fileData2);
|
|
||||||
|
|
||||||
QTest::newRow("Git patch") << patch
|
QTest::newRow("Git patch") << patch
|
||||||
<< fileDataList;
|
<< fileDataList;
|
||||||
|
|||||||
@@ -613,8 +613,8 @@ static QList<ChunkData> readChunks(const QString &patch,
|
|||||||
const QRegExp chunkRegExp(QLatin1String(
|
const QRegExp chunkRegExp(QLatin1String(
|
||||||
// beginning of the line
|
// beginning of the line
|
||||||
"((?:\\n|^)"
|
"((?:\\n|^)"
|
||||||
// @@ -leftPos,leftCount +rightPos,rightCount @@
|
// @@ -leftPos[,leftCount] +rightPos[,rightCount] @@
|
||||||
"@@ -(\\d+),\\d+ \\+(\\d+),\\d+ @@"
|
"@@ -(\\d+)(?:,\\d+)? \\+(\\d+)(?:,\\d+)? @@"
|
||||||
// optional hint (e.g. function name)
|
// optional hint (e.g. function name)
|
||||||
"(?:\\ +[^\\n]*)?"
|
"(?:\\ +[^\\n]*)?"
|
||||||
// end of line (need to be followed by text line)
|
// end of line (need to be followed by text line)
|
||||||
|
|||||||
Reference in New Issue
Block a user