Commit 18bbdd13 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Updated the libdiff2 version so that it can work with git patches.

Add a method to VcsDiff to specify the base directory of the patch.
Adapt the existing plugins to that.

If there are regressions just tell me and I'll try to sort them out.

CCMAIL: kdevelop-devel@kdevelop.org
parent cc527c8b
...@@ -25,6 +25,7 @@ CvsDiffJob::~CvsDiffJob() ...@@ -25,6 +25,7 @@ CvsDiffJob::~CvsDiffJob()
QVariant CvsDiffJob::fetchResults() QVariant CvsDiffJob::fetchResults()
{ {
KDevelop::VcsDiff diff; KDevelop::VcsDiff diff;
diff.setBaseDiff(KUrl("/"));
diff.setDiff( output() ); diff.setDiff( output() );
......
...@@ -3,11 +3,14 @@ ...@@ -3,11 +3,14 @@
########### next target ############### ########### next target ###############
add_definitions( ${KDE4_ENABLE_EXCEPTIONS}) add_definitions( ${KDE4_ENABLE_EXCEPTIONS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/settings)
set(patchreview_PART_SRCS set(patchreview_PART_SRCS
patchreview.cpp patchreview.cpp
documenthighlighter.cpp documenthighlighter.cpp
localpatchsource.cpp localpatchsource.cpp
settings/diffsettings.cpp
settings/settingsbase.cpp
libdiff2/kompareprocess.cpp libdiff2/kompareprocess.cpp
libdiff2/komparemodellist.cpp libdiff2/komparemodellist.cpp
...@@ -21,8 +24,6 @@ set(patchreview_PART_SRCS ...@@ -21,8 +24,6 @@ set(patchreview_PART_SRCS
libdiff2/cvsdiffparser.cpp libdiff2/cvsdiffparser.cpp
libdiff2/diffparser.cpp libdiff2/diffparser.cpp
libdiff2/perforceparser.cpp libdiff2/perforceparser.cpp
libdiff2/diffsettings.cpp
libdiff2/settingsbase.cpp
) )
set (patchreview_UI set (patchreview_UI
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
** cvsdiffparser.cpp ** cvsdiffparser.cpp
** ----------------- ** -----------------
** begin : Sun Aug 4 15:05:35 2002 ** begin : Sun Aug 4 15:05:35 2002
** copyright : (C) 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl> ** Copyright 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
**
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
** **
...@@ -13,15 +12,15 @@ ...@@ -13,15 +12,15 @@
** ( at your option ) any later version. ** ( at your option ) any later version.
** **
***************************************************************************/ ***************************************************************************/
#include "cvsdiffparser.h" #include "cvsdiffparser.h"
#include <qregexp.h>
#include <kdebug.h> #include <QtCore/QRegExp>
#include <kdebug.h>
#include "komparemodellist.h" #include "komparemodellist.h"
using namespace Diff2; 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 )
...@@ -52,27 +51,27 @@ enum Kompare::Format CVSDiffParser::determineFormat() ...@@ -52,27 +51,27 @@ enum Kompare::Format CVSDiffParser::determineFormat()
while( it != m_diffLines.end() ) while( it != m_diffLines.end() )
{ {
if( (*it).indexOf( normalRE, 0 ) == 0 ) if( it->indexOf( normalRE, 0 ) == 0 )
{ {
// kDebug(8101) << "Difflines are from a Normal diff..."; // kDebug(8101) << "Difflines are from a Normal diff...";
return Kompare::Normal; return Kompare::Normal;
} }
else if( (*it).indexOf( unifiedRE, 0 ) == 0 ) else if( it->indexOf( unifiedRE, 0 ) == 0 )
{ {
// kDebug(8101) << "Difflines are from a Unified diff..."; // kDebug(8101) << "Difflines are from a Unified diff...";
return Kompare::Unified; return Kompare::Unified;
} }
else if( (*it).indexOf( contextRE, 0 ) == 0 ) else if( it->indexOf( contextRE, 0 ) == 0 )
{ {
// kDebug(8101) << "Difflines are from a Context diff..."; // kDebug(8101) << "Difflines are from a Context diff...";
return Kompare::Context; return Kompare::Context;
} }
else if( (*it).indexOf( rcsRE, 0 ) == 0 ) else if( it->indexOf( rcsRE, 0 ) == 0 )
{ {
// kDebug(8101) << "Difflines are from a RCS diff..."; // kDebug(8101) << "Difflines are from a RCS diff...";
return Kompare::RCS; return Kompare::RCS;
} }
else if( (*it).indexOf( edRE, 0 ) == 0 ) else if( it->indexOf( edRE, 0 ) == 0 )
{ {
// kDebug(8101) << "Difflines are from an ED diff..."; // kDebug(8101) << "Difflines are from an ED diff...";
return Kompare::Ed; return Kompare::Ed;
...@@ -94,11 +93,10 @@ bool CVSDiffParser::parseNormalDiffHeader() ...@@ -94,11 +93,10 @@ bool CVSDiffParser::parseNormalDiffHeader()
{ {
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) ) if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{ {
kDebug(8101) << "Matched length Header =" << m_normalDiffHeader.matchedLength(); kDebug(8101) << "Matched length Header = " << m_normalDiffHeader.matchedLength();
kDebug(8101) << "Matched string Header =" << m_normalDiffHeader.cap( 0 ); kDebug(8101) << "Matched string Header = " << m_normalDiffHeader.cap( 0 );
m_currentModel = new DiffModel(); m_currentModel = new DiffModel();
QObject::connect( m_currentModel, SIGNAL( setModified( bool ) ), m_list, SLOT( slotSetModified( bool ) ) );
m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) ); m_currentModel->setSourceFile ( m_normalDiffHeader.cap( 1 ) );
m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 1 ) ); m_currentModel->setDestinationFile ( m_normalDiffHeader.cap( 1 ) );
...@@ -109,7 +107,7 @@ bool CVSDiffParser::parseNormalDiffHeader() ...@@ -109,7 +107,7 @@ bool CVSDiffParser::parseNormalDiffHeader()
} }
else else
{ {
kDebug(8101) << "No match for:" << ( *m_diffIterator ); kDebug(8101) << "No match for: " << ( *m_diffIterator );
} }
++m_diffIterator; ++m_diffIterator;
} }
...@@ -119,7 +117,6 @@ bool CVSDiffParser::parseNormalDiffHeader() ...@@ -119,7 +117,6 @@ bool CVSDiffParser::parseNormalDiffHeader()
// Set this to the first line again and hope it is a single file diff // Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin(); m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel(); m_currentModel = new DiffModel();
QObject::connect( m_currentModel, SIGNAL( setModified( bool ) ), m_list, SLOT( slotSetModified( bool ) ) );
m_singleFileDiff = true; m_singleFileDiff = true;
} }
......
/************************************************************************** /**************************************************************************
** cvsdiffparser.h ** cvsdiffparser.h
** ----------------- ** ----------------
** begin : Sun Aug 4 15:05:35 2002 ** begin : Sun Aug 4 15:05:35 2002
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl> ** Copyright 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
**
***************************************************************************/ ***************************************************************************/
/*************************************************************************** /***************************************************************************
** **
...@@ -14,10 +13,10 @@ ...@@ -14,10 +13,10 @@
** **
***************************************************************************/ ***************************************************************************/
#ifndef _CVSDIFF_PARSER_H #ifndef CVSDIFF_PARSER_H
#define _CVSDIFF_PARSER_H #define CVSDIFF_PARSER_H
#include <qregexp.h> #include <QtCore/QRegExp>
#include "parserbase.h" #include "parserbase.h"
......
/***************************************************************************
* Copyright 2007 Andreas Pakulat <apaku@gmx.de> *
* Copyright 2006 Matt Rogers <mattr@kde.org> *
* Copyright 2004 Jarosław Staniek <staniek@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef LIBDIFF2EXPORT_H
#define LIBDIFF2EXPORT_H
# define DIFF2_EXPORT
#endif
/*************************************************************************** /***************************************************************************
difference.cpp - description difference.cpp
------------------- --------------
begin : Sun Mar 4 2001 begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl> Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org> Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/ ****************************************************************************/
/*************************************************************************** /***************************************************************************
...@@ -25,21 +25,23 @@ Difference::Difference( int sourceLineNo, int destinationLineNo, int type ) : ...@@ -25,21 +25,23 @@ Difference::Difference( int sourceLineNo, int destinationLineNo, int type ) :
m_sourceLineNo( sourceLineNo ), m_sourceLineNo( sourceLineNo ),
m_destinationLineNo( destinationLineNo ), m_destinationLineNo( destinationLineNo ),
m_applied( false ), m_applied( false ),
m_table( new LevenshteinTable() ) m_conflicts( false ),
m_unsaved( false )
{ {
} }
Difference::~Difference() Difference::~Difference()
{ {
delete m_table; qDeleteAll( m_sourceLines );
qDeleteAll( m_destinationLines );
} }
void Difference::addSourceLine( const QString& line ) void Difference::addSourceLine( QString line )
{ {
m_sourceLines.append( new DifferenceString( line ) ); m_sourceLines.append( new DifferenceString( line ) );
} }
void Difference::addDestinationLine( const QString& line ) void Difference::addDestinationLine( QString line )
{ {
m_destinationLines.append( new DifferenceString( line ) ); m_destinationLines.append( new DifferenceString( line ) );
} }
...@@ -57,6 +59,7 @@ int Difference::destinationLineCount() const ...@@ -57,6 +59,7 @@ int Difference::destinationLineCount() const
void Difference::apply( bool apply ) void Difference::apply( bool apply )
{ {
m_applied = apply; m_applied = apply;
m_unsaved = !m_unsaved;
} }
void Difference::determineInlineDifferences() void Difference::determineInlineDifferences()
...@@ -67,26 +70,22 @@ void Difference::determineInlineDifferences() ...@@ -67,26 +70,22 @@ void Difference::determineInlineDifferences()
// Do nothing for now when the slc != dlc // Do nothing for now when the slc != dlc
// One could try to find the closest matching destination string for any // One could try to find the closest matching destination string for any
// of the source strings but this is compute intensive // of the source strings but this is compute intensive
if ( sourceLineCount() != destinationLineCount() ) int slc = sourceLineCount();
if ( slc != destinationLineCount() )
return; return;
int slc = sourceLineCount(); LevenshteinTable table;
kDebug() << "determining differences";
for ( int i = 0; i < slc; ++i ) for ( int i = 0; i < slc; ++i )
{ {
DifferenceString* sl = sourceLineAt( i ); DifferenceString* sl = sourceLineAt( i );
DifferenceString* dl = destinationLineAt( i ); DifferenceString* dl = destinationLineAt( i );
// FIXME: If the table cant be created do not do the rest // return value 0 means something went wrong creating the table so dont bother finding markers
m_table->createTable( sl, dl ); if ( table.createTable( sl, dl ) != 0 )
table.createListsOfMarkers();
m_table->createListsOfMarkers();
} }
// No longer needed, if we ever need to recalculate the inline differences we should
// simply recreate the table
delete m_table;
m_table = 0;
} }
QString Difference::recreateDifference() const QString Difference::recreateDifference() const
...@@ -139,3 +138,4 @@ QString Difference::recreateDifference() const ...@@ -139,3 +138,4 @@ QString Difference::recreateDifference() const
return difference; return difference;
} }
/*************************************************************************** /***************************************************************************
difference.h - description difference.h
------------------- ------------
begin : Sun Mar 4 2001 begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl> Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org> Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/ ****************************************************************************/
/*************************************************************************** /***************************************************************************
...@@ -18,21 +18,18 @@ ...@@ -18,21 +18,18 @@
#ifndef DIFFERENCE_H #ifndef DIFFERENCE_H
#define DIFFERENCE_H #define DIFFERENCE_H
#include <q3valuelist.h> #include <qvector.h>
#include <q3valuevector.h>
#include <kdebug.h> #include <kdebug.h>
#include "diff2export.h"
#include "diffexport.h"
class QString; class QString;
namespace Diff2 namespace Diff2
{ {
class LevenshteinTable;
class Marker class DIFF2_EXPORT Marker
{ {
public: public:
enum Type { Start = 0, End = 1 }; enum Type { Start = 0, End = 1 };
...@@ -62,22 +59,22 @@ private: ...@@ -62,22 +59,22 @@ private:
unsigned int m_offset; unsigned int m_offset;
}; };
typedef Q3ValueList<Marker*> MarkerList; typedef QList<Marker*> MarkerList;
typedef Q3ValueList<Marker*>::iterator MarkerListIterator; typedef QList<Marker*>::iterator MarkerListIterator;
typedef Q3ValueList<Marker*>::const_iterator MarkerListConstIterator; typedef QList<Marker*>::const_iterator MarkerListConstIterator;
class DifferenceString class DIFF2_EXPORT DifferenceString
{ {
public: public:
DifferenceString() DifferenceString()
{ {
// kDebug(8101) << "DifferenceString::DifferenceString()"; // kDebug(8101) << "DifferenceString::DifferenceString()" << endl;
} }
explicit DifferenceString( const QString& string, const MarkerList& markerList = MarkerList() ) : explicit DifferenceString( const QString& string, const MarkerList& markerList = MarkerList() ) :
m_string( string ), m_string( string ),
m_markerList( markerList ) m_markerList( markerList )
{ {
// kDebug(8101) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )"; // kDebug(8101) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )" << endl;
calculateHash(); calculateHash();
} }
DifferenceString( const DifferenceString& ds ) : DifferenceString( const DifferenceString& ds ) :
...@@ -86,9 +83,12 @@ public: ...@@ -86,9 +83,12 @@ public:
m_hash( ds.m_hash ), m_hash( ds.m_hash ),
m_markerList( ds.m_markerList ) m_markerList( ds.m_markerList )
{ {
// kDebug(8101) << "DifferenceString::DifferenceString( const DifferenceString& " << ds << " )"; // kDebug(8101) << "DifferenceString::DifferenceString( const DifferenceString& " << ds << " )" << endl;
}
~DifferenceString()
{
qDeleteAll( m_markerList );
} }
~DifferenceString() {}
public: public:
const QString& string() const const QString& string() const
...@@ -148,11 +148,11 @@ private: ...@@ -148,11 +148,11 @@ private:
MarkerList m_markerList; MarkerList m_markerList;
}; };
typedef Q3ValueVector<DifferenceString*> DifferenceStringList; typedef QVector<DifferenceString*> DifferenceStringList;
typedef Q3ValueVector<DifferenceString*>::iterator DifferenceStringListIterator; typedef QVector<DifferenceString*>::iterator DifferenceStringListIterator;
typedef Q3ValueVector<DifferenceString*>::const_iterator DifferenceStringListConstIterator; typedef QVector<DifferenceString*>::const_iterator DifferenceStringListConstIterator;
class Difference class DIFF2_EXPORT Difference
{ {
public: public:
enum Type { Change, Insert, Delete, Unchanged }; enum Type { Change, Insert, Delete, Unchanged };
...@@ -185,28 +185,28 @@ public: ...@@ -185,28 +185,28 @@ public:
m_conflicts = conflicts; m_conflicts = conflicts;
} }
bool isUnsaved() const
{
return m_unsaved;
}
void setUnsaved( bool unsaved )
{
m_unsaved = unsaved;
}
void apply( bool apply ); void apply( bool apply );
bool applied() const { return m_applied; } bool applied() const { return m_applied; }
void setType( int type ) { m_type = type; } void setType( int type ) { m_type = type; }
void addSourceLine( const QString& line ); void addSourceLine( QString line );
void addDestinationLine( const QString& line ); void addDestinationLine( QString line );
/** This method will calculate the differences between the individual strings and store them as Markers */ /** This method will calculate the differences between the individual strings and store them as Markers */
void determineInlineDifferences(); void determineInlineDifferences();
QString recreateDifference() const; QString recreateDifference() const;
void reverse() {
int l = m_sourceLineNo;
m_sourceLineNo = m_destinationLineNo;
m_destinationLineNo = l;
DifferenceStringList t = m_destinationLines;
m_destinationLines = m_sourceLines;
m_sourceLines = t;
}
private: private:
int m_type; int m_type;
...@@ -218,13 +218,12 @@ private: ...@@ -218,13 +218,12 @@ private:
bool m_applied; bool m_applied;
bool m_conflicts; bool m_conflicts;
bool m_unsaved;
LevenshteinTable* m_table;
}; };
typedef Q3ValueList<Difference*> DifferenceList; typedef QList<Difference*> DifferenceList;
typedef Q3ValueList<Difference*>::iterator DifferenceListIterator; typedef QList<Difference*>::iterator DifferenceListIterator;
typedef Q3ValueList<Difference*>::const_iterator DifferenceListConstIterator; typedef QList<Difference*>::const_iterator DifferenceListConstIterator;
} // End of namespace Diff2 } // End of namespace Diff2
......
/*************************************************************************** /***************************************************************************
diffhunk.cpp - description diffhunk.cpp
------------------- ------------
begin : Sun Mar 4 2001 begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl> Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org> Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/ ****************************************************************************/
/***************************************************************************