9#include "kompareprocess.h"
12#include "diffsettings.h"
13#include <komparediff2_logging.h>
42 for (; upLevels > 0; --upLevels) {
43 relative += QStringLiteral(
"../");
58 , m_diffSettings(diffSettings)
59 , m_diffMode(diffMode)
65 setEnv(QStringLiteral(
"LANG"), QStringLiteral(
"C"));
68 if (m_diffMode == KompareDiff2::Default) {
69 writeDefaultCommandLine();
75 setWorkingDirectory(dir);
79 *
this << QStringLiteral(
"--");
83 *
this << QStringLiteral(
"-");
84 m_customString = source;
86 *
this << constructRelativePath(dir, source);
90 *
this << QStringLiteral(
"-");
91 m_customString = destination;
93 *
this << constructRelativePath(dir, destination);
97void KompareProcess::writeDefaultCommandLine()
99 if (!m_diffSettings || m_diffSettings->m_diffProgram.isEmpty()) {
100 *
this << QStringLiteral(
"diff") << QStringLiteral(
"-dr");
102 *
this << m_diffSettings->m_diffProgram << QStringLiteral(
"-dr");
105 *
this << QStringLiteral(
"-U") <<
QString::number(m_diffSettings->m_linesOfContext);
108void KompareProcess::writeCommandLine()
111 if (m_diffSettings->m_diffProgram.isEmpty()) {
112 qCDebug(KOMPAREDIFF2_LOG) <<
"Using the first diff in the path...";
113 *
this << QStringLiteral(
"diff");
115 qCDebug(KOMPAREDIFF2_LOG) <<
"Using a user specified diff, namely: " << m_diffSettings->m_diffProgram;
116 *
this << m_diffSettings->m_diffProgram;
119 switch (m_diffSettings->m_format) {
120 case KompareDiff2::Unified:
121 *
this << QStringLiteral(
"-U") <<
QString::number(m_diffSettings->m_linesOfContext);
123 case KompareDiff2::Context:
124 *
this << QStringLiteral(
"-C") <<
QString::number(m_diffSettings->m_linesOfContext);
126 case KompareDiff2::RCS:
127 *
this << QStringLiteral(
"-n");
129 case KompareDiff2::Ed:
130 *
this << QStringLiteral(
"-e");
132 case KompareDiff2::SideBySide:
133 *
this << QStringLiteral(
"-y");
135 case KompareDiff2::Normal:
136 case KompareDiff2::UnknownFormat:
141 if (m_diffSettings->m_largeFiles
144#
if defined(__OpenBSD__)
145 && !m_diffSettings->m_diffProgram.isEmpty()
148 *
this << QStringLiteral(
"-H");
151 if (m_diffSettings->m_ignoreWhiteSpace) {
152 *
this << QStringLiteral(
"-b");
155 if (m_diffSettings->m_ignoreAllWhiteSpace) {
156 *
this << QStringLiteral(
"-w");
159 if (m_diffSettings->m_ignoreEmptyLines) {
160 *
this << QStringLiteral(
"-B");
163 if (m_diffSettings->m_ignoreChangesDueToTabExpansion) {
164 *
this << QStringLiteral(
"-E");
167 if (m_diffSettings->m_createSmallerDiff) {
168 *
this << QStringLiteral(
"-d");
171 if (m_diffSettings->m_ignoreChangesInCase) {
172 *
this << QStringLiteral(
"-i");
175 if (m_diffSettings->m_ignoreRegExp && !m_diffSettings->m_ignoreRegExpText.isEmpty()) {
176 *
this << QStringLiteral(
"-I") << m_diffSettings->m_ignoreRegExpText;
179 if (m_diffSettings->m_showCFunctionChange) {
180 *
this << QStringLiteral(
"-p");
183 if (m_diffSettings->m_convertTabsToSpaces) {
184 *
this << QStringLiteral(
"-t");
187 if (m_diffSettings->m_recursive) {
188 *
this << QStringLiteral(
"-r");
191 if (m_diffSettings->m_newFiles) {
192 *
this << QStringLiteral(
"-N");
201 if (m_diffSettings->m_excludeFilePattern) {
202 for (
const QString &it : std::as_const(m_diffSettings->m_excludeFilePatternList)) {
203 *
this << QStringLiteral(
"-x") << it;
207 if (m_diffSettings->m_excludeFilesFile && !m_diffSettings->m_excludeFilesFileURL.isEmpty()) {
208 *
this << QStringLiteral(
"-X") << m_diffSettings->m_excludeFilesFileURL;
212KompareProcess::~KompareProcess() =
default;
214void KompareProcess::setEncoding(
const QString &encoding)
222 if (!m_textDecoder.isValid() || !m_textEncoder.isValid()) {
223 qCDebug(KOMPAREDIFF2_LOG) <<
"Using locale codec as backup...";
230void KompareProcess::start()
235 for (
const QString &arg :
program)
236 cmdLine += QLatin1Char(
'\"') + arg + QLatin1String(
"\" ");
237 qCDebug(KOMPAREDIFF2_LOG) << cmdLine;
245 write(m_textEncoder.encode(m_customString));
252 m_textDecoder.resetState();
254 m_textDecoder.resetState();
260 qCDebug(KOMPAREDIFF2_LOG) <<
"Exited with exit code : " <<
exitCode;
264#include "moc_kompareprocess.cpp"
void setNextOpenMode(QIODevice::OpenMode mode)
QStringList program() const
void setOutputChannelMode(OutputChannelMode mode)
KIOCORE_EXPORT QUrl upUrl(const QUrl &url)
KIOCORE_EXPORT QString dir(const QString &fileClass)
@ ComparingFileString
Compare a source file with a destination string.
@ ComparingStringFile
Compare a source string with a destination file.
const char * constData() const const
qint64 write(const QByteArray &data)
int exitCode() const const
QProcess::ExitStatus exitStatus() const const
void finished(int exitCode, QProcess::ExitStatus exitStatus)
QByteArray readAllStandardError()
QByteArray readAllStandardOutput()
int compare(QLatin1StringView s1, const QString &s2, Qt::CaseSensitivity cs)
bool isEmpty() const const
qsizetype length() const const
QString number(double n, char format, int precision)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QByteArray toUtf8() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool isParentOf(const QUrl &childUrl) const const
bool isValid() const const
QString path(ComponentFormattingOptions options) const const