2014-02-28 10:40:20 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-02-28 10:40:20 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-02-28 10:40:20 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-02-28 10:40:20 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef DIFFUTILS_H
|
|
|
|
|
#define DIFFUTILS_H
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
#include "diffeditor_global.h"
|
|
|
|
|
|
2014-02-28 10:40:20 +01:00
|
|
|
#include <QString>
|
|
|
|
|
#include <QMap>
|
2014-03-10 12:57:48 +01:00
|
|
|
|
|
|
|
|
namespace TextEditor { class FontSettings; }
|
2014-02-28 10:40:20 +01:00
|
|
|
|
|
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
|
|
|
|
class Diff;
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class DIFFEDITOR_EXPORT DiffFileInfo {
|
|
|
|
|
public:
|
2014-07-07 14:26:41 +02:00
|
|
|
DiffFileInfo() {}
|
|
|
|
|
DiffFileInfo(const QString &file) : fileName(file) {}
|
2014-02-13 16:43:28 +01:00
|
|
|
DiffFileInfo(const QString &file, const QString &type)
|
2014-07-07 14:26:41 +02:00
|
|
|
: fileName(file), typeInfo(type) {}
|
2014-02-13 16:43:28 +01:00
|
|
|
QString fileName;
|
|
|
|
|
QString typeInfo;
|
|
|
|
|
};
|
2014-02-28 10:40:20 +01:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class DIFFEDITOR_EXPORT TextLineData {
|
2014-02-28 10:40:20 +01:00
|
|
|
public:
|
|
|
|
|
enum TextLineType {
|
|
|
|
|
TextLine,
|
|
|
|
|
Separator,
|
|
|
|
|
Invalid
|
|
|
|
|
};
|
|
|
|
|
TextLineData() : textLineType(Invalid) {}
|
|
|
|
|
TextLineData(const QString &txt) : textLineType(TextLine), text(txt) {}
|
|
|
|
|
TextLineData(TextLineType t) : textLineType(t) {}
|
|
|
|
|
TextLineType textLineType;
|
|
|
|
|
QString text;
|
2014-03-11 15:31:19 +01:00
|
|
|
/*
|
|
|
|
|
* <start position, end position>
|
|
|
|
|
* <-1, n> means this is a continuation from the previous line
|
|
|
|
|
* <n, -1> means this will be continued in the next line
|
|
|
|
|
* <-1, -1> the whole line is a continuation (from the previous line to the next line)
|
|
|
|
|
*/
|
|
|
|
|
QMap<int, int> changedPositions; // counting from the beginning of the line
|
2014-02-28 10:40:20 +01:00
|
|
|
};
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class DIFFEDITOR_EXPORT RowData {
|
2014-02-28 10:40:20 +01:00
|
|
|
public:
|
|
|
|
|
RowData() : equal(false) {}
|
|
|
|
|
RowData(const TextLineData &l)
|
|
|
|
|
: leftLine(l), rightLine(l), equal(true) {}
|
|
|
|
|
RowData(const TextLineData &l, const TextLineData &r)
|
|
|
|
|
: leftLine(l), rightLine(r), equal(false) {}
|
|
|
|
|
TextLineData leftLine;
|
|
|
|
|
TextLineData rightLine;
|
|
|
|
|
bool equal;
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class DIFFEDITOR_EXPORT ChunkData {
|
2014-02-28 10:40:20 +01:00
|
|
|
public:
|
2014-02-13 16:43:28 +01:00
|
|
|
ChunkData() : contextChunk(false),
|
|
|
|
|
leftStartingLineNumber(0), rightStartingLineNumber(0) {}
|
2014-02-28 10:40:20 +01:00
|
|
|
QList<RowData> rows;
|
|
|
|
|
bool contextChunk;
|
2014-02-13 16:43:28 +01:00
|
|
|
int leftStartingLineNumber;
|
|
|
|
|
int rightStartingLineNumber;
|
2014-08-14 17:20:42 +02:00
|
|
|
QString contextInfo;
|
2014-02-28 10:40:20 +01:00
|
|
|
};
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
class DIFFEDITOR_EXPORT FileData {
|
2014-02-28 10:40:20 +01:00
|
|
|
public:
|
2014-07-07 14:26:41 +02:00
|
|
|
enum FileOperation {
|
|
|
|
|
ChangeFile,
|
|
|
|
|
NewFile,
|
|
|
|
|
DeleteFile,
|
|
|
|
|
CopyFile,
|
|
|
|
|
RenameFile
|
|
|
|
|
};
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
FileData()
|
2014-07-07 14:26:41 +02:00
|
|
|
: fileOperation(ChangeFile),
|
|
|
|
|
binaryFiles(false),
|
2014-02-13 16:43:28 +01:00
|
|
|
lastChunkAtTheEndOfFile(false),
|
|
|
|
|
contextChunksIncluded(false) {}
|
|
|
|
|
FileData(const ChunkData &chunkData)
|
2014-07-07 14:26:41 +02:00
|
|
|
: fileOperation(ChangeFile),
|
|
|
|
|
binaryFiles(false),
|
2014-02-13 16:43:28 +01:00
|
|
|
lastChunkAtTheEndOfFile(false),
|
|
|
|
|
contextChunksIncluded(false) { chunks.append(chunkData); }
|
2014-02-28 10:40:20 +01:00
|
|
|
QList<ChunkData> chunks;
|
2014-02-13 16:43:28 +01:00
|
|
|
DiffFileInfo leftFileInfo;
|
|
|
|
|
DiffFileInfo rightFileInfo;
|
2014-07-07 14:26:41 +02:00
|
|
|
FileOperation fileOperation;
|
2014-02-13 16:43:28 +01:00
|
|
|
bool binaryFiles;
|
|
|
|
|
bool lastChunkAtTheEndOfFile;
|
|
|
|
|
bool contextChunksIncluded;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DIFFEDITOR_EXPORT DiffUtils {
|
|
|
|
|
public:
|
2014-11-11 16:27:23 +01:00
|
|
|
enum PatchFormattingFlags {
|
|
|
|
|
AddLevel = 0x1, // Add 'a/' , '/b' for git am
|
|
|
|
|
GitFormat = AddLevel | 0x2, // Add line 'diff ..' as git does
|
|
|
|
|
};
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
static ChunkData calculateOriginalData(const QList<Diff> &leftDiffList,
|
|
|
|
|
const QList<Diff> &rightDiffList);
|
|
|
|
|
static FileData calculateContextData(const ChunkData &originalData,
|
2015-01-30 16:59:25 +01:00
|
|
|
int contextLineCount,
|
2014-02-13 16:43:28 +01:00
|
|
|
int joinChunkThreshold = 1);
|
|
|
|
|
static QString makePatchLine(const QChar &startLineCharacter,
|
|
|
|
|
const QString &textLine,
|
|
|
|
|
bool lastChunk,
|
|
|
|
|
bool lastLine);
|
2014-06-30 15:04:36 +02:00
|
|
|
static QString makePatch(const ChunkData &chunkData,
|
|
|
|
|
bool lastChunk = false);
|
2014-02-13 16:43:28 +01:00
|
|
|
static QString makePatch(const ChunkData &chunkData,
|
|
|
|
|
const QString &leftFileName,
|
|
|
|
|
const QString &rightFileName,
|
|
|
|
|
bool lastChunk = false);
|
2014-11-11 16:27:23 +01:00
|
|
|
static QString makePatch(const QList<FileData> &fileDataList,
|
|
|
|
|
unsigned formatFlags = 0);
|
2014-02-13 16:43:28 +01:00
|
|
|
static QList<FileData> readPatch(const QString &patch,
|
|
|
|
|
bool *ok = 0);
|
2014-02-28 10:40:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace DiffEditor
|
|
|
|
|
|
|
|
|
|
#endif // DIFFUTILS_H
|