Reformat style spacing: use spaces for indentation, no spaces in brackets

parent de5a0651
......@@ -22,14 +22,14 @@
using namespace Diff2;
CVSDiffParser::CVSDiffParser( const KompareModelList* list, const QStringList& diff ) : ParserBase( list, diff )
CVSDiffParser::CVSDiffParser(const KompareModelList* list, const QStringList& diff) : ParserBase(list, diff)
{
// The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp
// third capture in header1 is non optional for cvs diff, it is the revision
m_contextDiffHeader1.setPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n"));
m_contextDiffHeader2.setPattern(QStringLiteral("--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n"));
// The regexps needed for context cvs diff parsing, the rest is the same as in parserbase.cpp
// third capture in header1 is non optional for cvs diff, it is the revision
m_contextDiffHeader1.setPattern(QStringLiteral("\\*\\*\\* ([^\\t]+)\\t([^\\t]+)\\t(.*)\\n"));
m_contextDiffHeader2.setPattern(QStringLiteral("--- ([^\\t]+)\\t([^\\t]+)(|\\t(.*))\\n"));
m_normalDiffHeader.setPattern(QStringLiteral("Index: (.*)\\n"));
m_normalDiffHeader.setPattern(QStringLiteral("Index: (.*)\\n"));
}
CVSDiffParser::~CVSDiffParser()
......@@ -38,118 +38,117 @@ CVSDiffParser::~CVSDiffParser()
enum Kompare::Format CVSDiffParser::determineFormat()
{
// qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the CVSDiff";
QRegExp normalRE (QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*"));
QRegExp unifiedRE(QStringLiteral("^--- [^\\t]+\\t"));
QRegExp contextRE(QStringLiteral("^\\*\\*\\* [^\\t]+\\t"));
QRegExp rcsRE (QStringLiteral("^[acd][0-9]+ [0-9]+"));
QRegExp edRE (QStringLiteral("^[0-9]+[0-9,]*[acd]"));
QStringList::ConstIterator it = m_diffLines.begin();
while( it != m_diffLines.end() )
{
if( (*it).indexOf( normalRE, 0 ) == 0 )
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Normal diff...";
return Kompare::Normal;
}
else if( (*it).indexOf( unifiedRE, 0 ) == 0 )
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Unified diff...";
return Kompare::Unified;
}
else if( (*it).indexOf( contextRE, 0 ) == 0 )
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Context diff...";
return Kompare::Context;
}
else if( (*it).indexOf( rcsRE, 0 ) == 0 )
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a RCS diff...";
return Kompare::RCS;
}
else if( (*it).indexOf( edRE, 0 ) == 0 )
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an ED diff...";
return Kompare::Ed;
}
++it;
}
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an unknown diff...";
return Kompare::UnknownFormat;
// qCDebug(LIBKOMPAREDIFF2) << "Determining the format of the CVSDiff";
QRegExp normalRE(QStringLiteral("[0-9]+[0-9,]*[acd][0-9]+[0-9,]*"));
QRegExp unifiedRE(QStringLiteral("^--- [^\\t]+\\t"));
QRegExp contextRE(QStringLiteral("^\\*\\*\\* [^\\t]+\\t"));
QRegExp rcsRE(QStringLiteral("^[acd][0-9]+ [0-9]+"));
QRegExp edRE(QStringLiteral("^[0-9]+[0-9,]*[acd]"));
QStringList::ConstIterator it = m_diffLines.begin();
while (it != m_diffLines.end())
{
if ((*it).indexOf(normalRE, 0) == 0)
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Normal diff...";
return Kompare::Normal;
}
else if ((*it).indexOf(unifiedRE, 0) == 0)
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Unified diff...";
return Kompare::Unified;
}
else if ((*it).indexOf(contextRE, 0) == 0)
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a Context diff...";
return Kompare::Context;
}
else if ((*it).indexOf(rcsRE, 0) == 0)
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from a RCS diff...";
return Kompare::RCS;
}
else if ((*it).indexOf(edRE, 0) == 0)
{
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an ED diff...";
return Kompare::Ed;
}
++it;
}
// qCDebug(LIBKOMPAREDIFF2) << "Difflines are from an unknown diff...";
return Kompare::UnknownFormat;
}
bool CVSDiffParser::parseNormalDiffHeader()
{
qCDebug(LIBKOMPAREDIFF2) << "CVSDiffParser::parseNormalDiffHeader()";
bool result = false;
QStringList::ConstIterator diffEnd = m_diffLines.end();
while ( m_diffIterator != diffEnd )
{
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{
qCDebug(LIBKOMPAREDIFF2) << "Matched length Header = " << m_normalDiffHeader.matchedLength();
qCDebug(LIBKOMPAREDIFF2) << "Matched string Header = " << m_normalDiffHeader.cap( 0 );
m_currentModel = new DiffModel();
m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) );
m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 1 ) );
result = true;
++m_diffIterator;
break;
}
else
{
qCDebug(LIBKOMPAREDIFF2) << "No match for: " << ( *m_diffIterator );
}
++m_diffIterator;
}
if ( result == false )
{
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
m_singleFileDiff = true;
}
return result;
qCDebug(LIBKOMPAREDIFF2) << "CVSDiffParser::parseNormalDiffHeader()";
bool result = false;
QStringList::ConstIterator diffEnd = m_diffLines.end();
while (m_diffIterator != diffEnd)
{
if (m_normalDiffHeader.exactMatch(*m_diffIterator))
{
qCDebug(LIBKOMPAREDIFF2) << "Matched length Header = " << m_normalDiffHeader.matchedLength();
qCDebug(LIBKOMPAREDIFF2) << "Matched string Header = " << m_normalDiffHeader.cap(0);
m_currentModel = new DiffModel();
m_currentModel->setSourceFile(m_normalDiffHeader.cap(1));
m_currentModel->setDestinationFile(m_normalDiffHeader.cap(1));
result = true;
++m_diffIterator;
break;
}
else
{
qCDebug(LIBKOMPAREDIFF2) << "No match for: " << (*m_diffIterator);
}
++m_diffIterator;
}
if (result == false)
{
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
m_singleFileDiff = true;
}
return result;
}
bool CVSDiffParser::parseEdDiffHeader()
{
return false;
return false;
}
bool CVSDiffParser::parseRCSDiffHeader()
{
return false;
return false;
}
bool CVSDiffParser::parseEdHunkHeader()
{
return false;
return false;
}
bool CVSDiffParser::parseRCSHunkHeader()
{
return false;
return false;
}
bool CVSDiffParser::parseEdHunkBody()
{
return false;
return false;
}
bool CVSDiffParser::parseRCSHunkBody()
{
return false;
return false;
}
......@@ -28,30 +28,30 @@ class KompareModelList;
class CVSDiffParser : public ParserBase
{
public:
CVSDiffParser( const KompareModelList* list, const QStringList& diff );
~CVSDiffParser() override;
CVSDiffParser(const KompareModelList* list, const QStringList& diff);
~CVSDiffParser() override;
protected:
enum Kompare::Format determineFormat() override;
enum Kompare::Format determineFormat() override;
protected:
// virtual bool parseContextDiffHeader();
bool parseEdDiffHeader() override;
bool parseNormalDiffHeader() override;
bool parseRCSDiffHeader() override;
// virtual bool parseUnifiedDiffHeader();
// virtual bool parseContextHunkHeader();
bool parseEdHunkHeader() override;
// virtual bool parseNormalHunkHeader();
bool parseRCSHunkHeader() override;
// virtual bool parseUnifiedHunkHeader();
// virtual bool parseContextHunkBody();
bool parseEdHunkBody() override;
// virtual bool parseNormalHunkBody();
bool parseRCSHunkBody() override;
// virtual bool parseUnifiedHunkBody();
// virtual bool parseContextDiffHeader();
bool parseEdDiffHeader() override;
bool parseNormalDiffHeader() override;
bool parseRCSDiffHeader() override;
// virtual bool parseUnifiedDiffHeader();
// virtual bool parseContextHunkHeader();
bool parseEdHunkHeader() override;
// virtual bool parseNormalHunkHeader();
bool parseRCSHunkHeader() override;
// virtual bool parseUnifiedHunkHeader();
// virtual bool parseContextHunkBody();
bool parseEdHunkBody() override;
// virtual bool parseNormalHunkBody();
bool parseRCSHunkBody() override;
// virtual bool parseUnifiedHunkBody();
};
} // End of namespace Diff2
......
......@@ -21,153 +21,153 @@
using namespace Diff2;
Difference::Difference( int sourceLineNo, int destinationLineNo, int type ) :
QObject(),
m_type( type ),
m_sourceLineNo( sourceLineNo ),
m_destinationLineNo( destinationLineNo ),
m_trackingDestinationLineNo( sourceLineNo ), // The whole patch starts as unapplied
m_applied( false ),
m_conflicts( false ),
m_unsaved( false )
Difference::Difference(int sourceLineNo, int destinationLineNo, int type) :
QObject(),
m_type(type),
m_sourceLineNo(sourceLineNo),
m_destinationLineNo(destinationLineNo),
m_trackingDestinationLineNo(sourceLineNo), // The whole patch starts as unapplied
m_applied(false),
m_conflicts(false),
m_unsaved(false)
{
}
Difference::~Difference()
{
qDeleteAll( m_sourceLines );
qDeleteAll( m_destinationLines );
qDeleteAll(m_sourceLines);
qDeleteAll(m_destinationLines);
}
void Difference::addSourceLine( QString line )
void Difference::addSourceLine(QString line)
{
m_sourceLines.append( new DifferenceString( line ) );
m_sourceLines.append(new DifferenceString(line));
}
void Difference::addDestinationLine( QString line )
void Difference::addDestinationLine(QString line)
{
m_destinationLines.append( new DifferenceString( line ) );
m_destinationLines.append(new DifferenceString(line));
}
int Difference::sourceLineCount() const
{
return m_sourceLines.count();
return m_sourceLines.count();
}
int Difference::destinationLineCount() const
{
return m_destinationLines.count();
return m_destinationLines.count();
}
int Difference::sourceLineEnd() const
{
return m_sourceLineNo + m_sourceLines.count();
return m_sourceLineNo + m_sourceLines.count();
}
int Difference::destinationLineEnd() const
{
return m_destinationLineNo + m_destinationLines.count();
return m_destinationLineNo + m_destinationLines.count();
}
int Difference::trackingDestinationLineEnd() const
{
return m_trackingDestinationLineNo + m_destinationLines.count();
return m_trackingDestinationLineNo + m_destinationLines.count();
}
void Difference::apply( bool apply )
void Difference::apply(bool apply)
{
if ( apply != m_applied )
{
m_applied = apply;
m_unsaved = !m_unsaved;
emit differenceApplied(this);
}
if (apply != m_applied)
{
m_applied = apply;
m_unsaved = !m_unsaved;
emit differenceApplied(this);
}
}
void Difference::applyQuietly(bool apply)
{
if ( m_applied != apply )
{
m_unsaved = !m_unsaved;
m_applied = apply;
}
if (m_applied != apply)
{
m_unsaved = !m_unsaved;
m_applied = apply;
}
}
void Difference::determineInlineDifferences()
{
if ( m_type != Difference::Change )
return;
if (m_type != Difference::Change)
return;
// Do nothing for now when the slc != dlc
// One could try to find the closest matching destination string for any
// of the source strings but this is compute intensive
int slc = sourceLineCount();
// Do nothing for now when the slc != dlc
// One could try to find the closest matching destination string for any
// of the source strings but this is compute intensive
int slc = sourceLineCount();
if ( slc != destinationLineCount() )
return;
if (slc != destinationLineCount())
return;
LevenshteinTable<DifferenceStringPair> table;
LevenshteinTable<DifferenceStringPair> table;
for ( int i = 0; i < slc; ++i )
{
DifferenceString* sl = sourceLineAt( i );
DifferenceString* dl = destinationLineAt( i );
DifferenceStringPair* pair = new DifferenceStringPair(sl, dl);
for (int i = 0; i < slc; ++i)
{
DifferenceString* sl = sourceLineAt(i);
DifferenceString* dl = destinationLineAt(i);
DifferenceStringPair* pair = new DifferenceStringPair(sl, dl);
// return value 0 means something went wrong creating the table so dont bother finding markers
if ( table.createTable( pair ) != 0 )
table.createListsOfMarkers();
}
// return value 0 means something went wrong creating the table so dont bother finding markers
if (table.createTable(pair) != 0)
table.createListsOfMarkers();
}
}
QString Difference::recreateDifference() const
{
QString difference;
// source
DifferenceStringListConstIterator stringIt = m_sourceLines.begin();
DifferenceStringListConstIterator sEnd = m_sourceLines.end();
for ( ; stringIt != sEnd; ++stringIt )
{
switch ( m_type )
{
case Change:
case Delete:
difference += QLatin1Char('-');
break;
default:
// Insert but this is not possible in source
// Unchanged will be handled in destination
// since they are the same
// qCDebug(LIBKOMPAREDIFF2) << "Go away, nothing to do for you in source...";
continue;
}
difference += (*stringIt)->string();
}
//destination
stringIt = m_destinationLines.begin();
sEnd = m_destinationLines.end();
for ( ; stringIt != sEnd; ++stringIt )
{
switch ( m_type )
{
case Change:
case Insert:
difference += QLatin1Char('+');
break;
case Unchanged:
difference += QLatin1Char(' ');
break;
default: // Delete but this is not possible in destination
// qCDebug(LIBKOMPAREDIFF2) << "Go away, nothing to do for you in destination...";
continue;
}
difference += (*stringIt)->string();
}
return difference;
QString difference;
// source
DifferenceStringListConstIterator stringIt = m_sourceLines.begin();
DifferenceStringListConstIterator sEnd = m_sourceLines.end();
for (; stringIt != sEnd; ++stringIt)
{
switch (m_type)
{
case Change:
case Delete:
difference += QLatin1Char('-');
break;
default:
// Insert but this is not possible in source
// Unchanged will be handled in destination
// since they are the same
// qCDebug(LIBKOMPAREDIFF2) << "Go away, nothing to do for you in source...";
continue;
}
difference += (*stringIt)->string();
}
//destination
stringIt = m_destinationLines.begin();
sEnd = m_destinationLines.end();
for (; stringIt != sEnd; ++stringIt)
{
switch (m_type)
{
case Change:
case Insert:
difference += QLatin1Char('+');
break;
case Unchanged:
difference += QLatin1Char(' ');
break;
default: // Delete but this is not possible in destination
// qCDebug(LIBKOMPAREDIFF2) << "Go away, nothing to do for you in destination...";
continue;
}
difference += (*stringIt)->string();
}
return difference;
}
......@@ -34,86 +34,86 @@ namespace Diff2
class DIFF2_EXPORT DifferenceString
{
public:
DifferenceString()
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString()";
}
explicit DifferenceString( const QString& string, const MarkerList& markerList = MarkerList() ) :
m_string( string ),
m_markerList( markerList )
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )";
calculateHash();
}
DifferenceString( const DifferenceString& ds ) :
m_string( ds.m_string ),
m_conflict( ds.m_conflict ),
m_hash( ds.m_hash ),
m_markerList( ds.m_markerList )
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString( const DifferenceString& " << ds << " )";
}
~DifferenceString()
{
qDeleteAll( m_markerList );
}
DifferenceString()
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString()";
}
explicit DifferenceString(const QString& string, const MarkerList& markerList = MarkerList()) :
m_string(string),
m_markerList(markerList)
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )";
calculateHash();
}
DifferenceString(const DifferenceString& ds) :
m_string(ds.m_string),
m_conflict(ds.m_conflict),
m_hash(ds.m_hash),
m_markerList(ds.m_markerList)
{
// qCDebug(LIBKOMPAREDIFF2) << "DifferenceString::DifferenceString( const DifferenceString& " << ds << " )";
}
~DifferenceString()
{
qDeleteAll(m_markerList);
}
public:
const QString& string() const
{
return m_string;
}
const QString& conflictString() const
{
return m_conflict;
}
const MarkerList& markerList()
{
return m_markerList;
}
void setString( const QString& string )
{
m_string = string;
calculateHash();
}
void setConflictString( const QString& conflict )
{
m_conflict = conflict;
}
void setMarkerList( const MarkerList& markerList )
{
m_markerList = markerList;
}
void prepend( Marker* marker )
{
m_markerList.prepend( marker );
}
bool operator==( const DifferenceString& ks )
{
if ( m_hash != ks.m_hash )
return false;
return m_string == ks.m_string;
}
const QString& string() const
{
return m_string;
}
const QString& conflictString() const
{
return m_conflict;
}
const MarkerList& markerList()
{
return m_markerList;
}
void setString(const QString& string)
{
m_string = string;
calculateHash();
}
void setConflictString(const QString& conflict)
{
m_conflict = conflict;
}
void setMarkerList(const MarkerList& markerList)
{
m_markerList = markerList;
}
void prepend(Marker* marker)
{
m_markerList.prepend(marker);
}
bool operator==(const DifferenceString& ks)
{
if (m_hash != ks.m_hash)
return false;
return m_string == ks.m_string;
}
protected:
void calculateHash()
{
unsigned short const* str = reinterpret_cast<unsigned short const*>( m_string.unicode() );
const unsigned int len = m_string.length();
void calculateHash()