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

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()
QVariant CvsDiffJob::fetchResults()
{
KDevelop::VcsDiff diff;
diff.setBaseDiff(KUrl("/"));
diff.setDiff( output() );
......
......@@ -3,11 +3,14 @@
########### next target ###############
add_definitions( ${KDE4_ENABLE_EXCEPTIONS})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/settings)
set(patchreview_PART_SRCS
patchreview.cpp
documenthighlighter.cpp
localpatchsource.cpp
settings/diffsettings.cpp
settings/settingsbase.cpp
libdiff2/kompareprocess.cpp
libdiff2/komparemodellist.cpp
......@@ -21,8 +24,6 @@ set(patchreview_PART_SRCS
libdiff2/cvsdiffparser.cpp
libdiff2/diffparser.cpp
libdiff2/perforceparser.cpp
libdiff2/diffsettings.cpp
libdiff2/settingsbase.cpp
)
set (patchreview_UI
......
......@@ -2,8 +2,7 @@
** cvsdiffparser.cpp
** -----------------
** 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 @@
** ( at your option ) any later version.
**
***************************************************************************/
#include "cvsdiffparser.h"
#include <qregexp.h>
#include <kdebug.h>
#include <QtCore/QRegExp>
#include <kdebug.h>
#include "komparemodellist.h"
using namespace Diff2;
CVSDiffParser::CVSDiffParser( const KompareModelList* list, const QStringList& diff ) : ParserBase( list, diff )
......@@ -52,27 +51,27 @@ enum Kompare::Format CVSDiffParser::determineFormat()
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...";
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...";
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...";
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...";
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...";
return Kompare::Ed;
......@@ -94,11 +93,10 @@ bool CVSDiffParser::parseNormalDiffHeader()
{
if ( m_normalDiffHeader.exactMatch( *m_diffIterator ) )
{
kDebug(8101) << "Matched length Header =" << m_normalDiffHeader.matchedLength();
kDebug(8101) << "Matched string Header =" << m_normalDiffHeader.cap( 0 );
kDebug(8101) << "Matched length Header = " << m_normalDiffHeader.matchedLength();
kDebug(8101) << "Matched string Header = " << m_normalDiffHeader.cap( 0 );
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->setDestinationFile ( m_normalDiffHeader.cap( 1 ) );
......@@ -109,7 +107,7 @@ bool CVSDiffParser::parseNormalDiffHeader()
}
else
{
kDebug(8101) << "No match for:" << ( *m_diffIterator );
kDebug(8101) << "No match for: " << ( *m_diffIterator );
}
++m_diffIterator;
}
......@@ -119,7 +117,6 @@ bool CVSDiffParser::parseNormalDiffHeader()
// Set this to the first line again and hope it is a single file diff
m_diffIterator = m_diffLines.begin();
m_currentModel = new DiffModel();
QObject::connect( m_currentModel, SIGNAL( setModified( bool ) ), m_list, SLOT( slotSetModified( bool ) ) );
m_singleFileDiff = true;
}
......
/**************************************************************************
** cvsdiffparser.h
** -----------------
** ----------------
** 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 @@
**
***************************************************************************/
#ifndef _CVSDIFF_PARSER_H
#define _CVSDIFF_PARSER_H
#ifndef CVSDIFF_PARSER_H
#define CVSDIFF_PARSER_H
#include <qregexp.h>
#include <QtCore/QRegExp>
#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
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org>
Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
......@@ -25,21 +25,23 @@ Difference::Difference( int sourceLineNo, int destinationLineNo, int type ) :
m_sourceLineNo( sourceLineNo ),
m_destinationLineNo( destinationLineNo ),
m_applied( false ),
m_table( new LevenshteinTable() )
m_conflicts( false ),
m_unsaved( false )
{
}
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 ) );
}
void Difference::addDestinationLine( const QString& line )
void Difference::addDestinationLine( QString line )
{
m_destinationLines.append( new DifferenceString( line ) );
}
......@@ -57,6 +59,7 @@ int Difference::destinationLineCount() const
void Difference::apply( bool apply )
{
m_applied = apply;
m_unsaved = !m_unsaved;
}
void Difference::determineInlineDifferences()
......@@ -67,26 +70,22 @@ void Difference::determineInlineDifferences()
// 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
if ( sourceLineCount() != destinationLineCount() )
int slc = sourceLineCount();
if ( slc != destinationLineCount() )
return;
int slc = sourceLineCount();
kDebug() << "determining differences";
LevenshteinTable table;
for ( int i = 0; i < slc; ++i )
{
DifferenceString* sl = sourceLineAt( i );
DifferenceString* dl = destinationLineAt( i );
// FIXME: If the table cant be created do not do the rest
m_table->createTable( sl, dl );
m_table->createListsOfMarkers();
// return value 0 means something went wrong creating the table so dont bother finding markers
if ( table.createTable( sl, dl ) != 0 )
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
......@@ -139,3 +138,4 @@ QString Difference::recreateDifference() const
return difference;
}
/***************************************************************************
difference.h - description
-------------------
difference.h
------------
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org>
Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
......@@ -18,21 +18,18 @@
#ifndef DIFFERENCE_H
#define DIFFERENCE_H
#include <q3valuelist.h>
#include <q3valuevector.h>
#include <qvector.h>
#include <kdebug.h>
#include "diffexport.h"
#include "diff2export.h"
class QString;
namespace Diff2
{
class LevenshteinTable;
class Marker
class DIFF2_EXPORT Marker
{
public:
enum Type { Start = 0, End = 1 };
......@@ -62,22 +59,22 @@ private:
unsigned int m_offset;
};
typedef Q3ValueList<Marker*> MarkerList;
typedef Q3ValueList<Marker*>::iterator MarkerListIterator;
typedef Q3ValueList<Marker*>::const_iterator MarkerListConstIterator;
typedef QList<Marker*> MarkerList;
typedef QList<Marker*>::iterator MarkerListIterator;
typedef QList<Marker*>::const_iterator MarkerListConstIterator;
class DifferenceString
class DIFF2_EXPORT DifferenceString
{
public:
DifferenceString()
{
// kDebug(8101) << "DifferenceString::DifferenceString()";
// kDebug(8101) << "DifferenceString::DifferenceString()" << endl;
}
explicit DifferenceString( const QString& string, const MarkerList& markerList = MarkerList() ) :
m_string( string ),
m_markerList( markerList )
{
// kDebug(8101) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )";
// kDebug(8101) << "DifferenceString::DifferenceString( " << string << ", " << markerList << " )" << endl;
calculateHash();
}
DifferenceString( const DifferenceString& ds ) :
......@@ -86,9 +83,12 @@ public:
m_hash( ds.m_hash ),
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:
const QString& string() const
......@@ -148,11 +148,11 @@ private:
MarkerList m_markerList;
};
typedef Q3ValueVector<DifferenceString*> DifferenceStringList;
typedef Q3ValueVector<DifferenceString*>::iterator DifferenceStringListIterator;
typedef Q3ValueVector<DifferenceString*>::const_iterator DifferenceStringListConstIterator;
typedef QVector<DifferenceString*> DifferenceStringList;
typedef QVector<DifferenceString*>::iterator DifferenceStringListIterator;
typedef QVector<DifferenceString*>::const_iterator DifferenceStringListConstIterator;
class Difference
class DIFF2_EXPORT Difference
{
public:
enum Type { Change, Insert, Delete, Unchanged };
......@@ -185,28 +185,28 @@ public:
m_conflicts = conflicts;
}
bool isUnsaved() const
{
return m_unsaved;
}
void setUnsaved( bool unsaved )
{
m_unsaved = unsaved;
}
void apply( bool apply );
bool applied() const { return m_applied; }
void setType( int type ) { m_type = type; }
void addSourceLine( const QString& line );
void addDestinationLine( const QString& line );
void addSourceLine( QString line );
void addDestinationLine( QString line );
/** This method will calculate the differences between the individual strings and store them as Markers */
void determineInlineDifferences();
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:
int m_type;
......@@ -218,13 +218,12 @@ private:
bool m_applied;
bool m_conflicts;
LevenshteinTable* m_table;
bool m_unsaved;
};
typedef Q3ValueList<Difference*> DifferenceList;
typedef Q3ValueList<Difference*>::iterator DifferenceListIterator;
typedef Q3ValueList<Difference*>::const_iterator DifferenceListConstIterator;
typedef QList<Difference*> DifferenceList;
typedef QList<Difference*>::iterator DifferenceListIterator;
typedef QList<Difference*>::const_iterator DifferenceListConstIterator;
} // End of namespace Diff2
......
/***************************************************************************
diffhunk.cpp - description
-------------------
diffhunk.cpp
------------
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org>
Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
......@@ -15,13 +15,13 @@
**
***************************************************************************/
#include "diffhunk.h"
#include "difference.h"
using namespace Diff2;
DiffHunk::DiffHunk( int sourceLine, int destinationLine, const QString& function, Type type ) :
DiffHunk::DiffHunk( int sourceLine, int destinationLine, QString function, Type type ) :
m_sourceLine( sourceLine ),
m_destinationLine( destinationLine ),
m_function( function ),
......@@ -31,6 +31,7 @@ DiffHunk::DiffHunk( int sourceLine, int destinationLine, const QString& function
DiffHunk::~DiffHunk()
{
qDeleteAll( m_differences );
}
void DiffHunk::add( Difference* diff )
......@@ -108,6 +109,6 @@ QString DiffHunk::recreateHunk() const
hunk += differences;
kDebug( 8101 ) << hunk;
kDebug( 8101 ) << hunk << endl;
return hunk;
}
/***************************************************************************
diffhunk.h - description
-------------------
diffhunk.h
----------
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org>
Copyright 2001-2004,2009 Otto Bruggeman <bruggie@gmail.com>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
......@@ -19,8 +19,7 @@
#define DIFFHUNK_H
#include "difference.h"
//Added by qt3to4:
#include <Q3ValueList>
namespace Diff2
{
......@@ -33,7 +32,7 @@ public:
enum Type { Normal, AddedByBlend };
public:
DiffHunk( int sourceLine, int destinationLine, const QString& function = QString(), Type type = Normal );
DiffHunk( int sourceLine, int destinationLine, QString function = QString(), Type type = Normal );
~DiffHunk();
const DifferenceList& differences() const { return m_differences; };
......@@ -45,21 +44,13 @@ public:
int sourceLineCount() const;
int destinationLineCount() const;
const Type type() const { return m_type; }
Type type() const { return m_type; }
void setType( Type type ) { m_type = type; }
void add( Difference* diff );
QString recreateHunk() const;
void reverse() {
int t = m_destinationLine;
m_destinationLine = m_sourceLine;
m_sourceLine = t;
for(int a = 0; a < m_differences.size(); ++a)
m_differences[a]->reverse();
}
private:
int m_sourceLine;
int m_destinationLine;
......@@ -68,9 +59,9 @@ private:
Type m_type;
};
typedef Q3ValueList<DiffHunk*> DiffHunkList;
typedef Q3ValueList<DiffHunk*>::iterator DiffHunkListIterator;
typedef Q3ValueList<DiffHunk*>::const_iterator DiffHunkListConstIterator;
typedef QList<DiffHunk*> DiffHunkList;
typedef QList<DiffHunk*>::iterator DiffHunkListIterator;
typedef QList<DiffHunk*>::const_iterator DiffHunkListConstIterator;
} // End of namespace Diff2
......
/***************************************************************************
diffmodel.cpp - description
-------------------
diffmodel.cpp
-------------
begin : Sun Mar 4 2001
copyright : (C) 2001-2003 Otto Bruggeman <otto.bruggeman@home.nl>
copyright : (C) 2001-2003 John Firebaugh <jfirebaugh@kde.org>
Copyright 2001-2009 Otto Bruggeman <bruggie@gmail.com>
Copyright 2001-2003 John Firebaugh <jfirebaugh@kde.org>
****************************************************************************/
/***************************************************************************
......@@ -16,8 +16,8 @@
***************************************************************************/
#include "diffmodel.h"
#include <qregexp.h>
#include <q3valuelist.h>
#include <QtCore/QRegExp>
#include <kdebug.h>
#include <klocale.h>
......@@ -40,7 +40,6 @@ DiffModel::DiffModel( const QString& source, const QString& destination ) :
m_sourceRevision( "" ),
m_destinationRevision( "" ),
m_appliedCount( 0 ),
m_modified( false ),
m_diffIndex( 0 ),
m_selectedDifference( 0 ),
m_blended( false )
......@@ -61,7 +60,6 @@ DiffModel::DiffModel() :
m_sourceRevision( "" ),
m_destinationRevision( "" ),
m_appliedCount( 0 ),
m_modified( false ),
m_diffIndex( 0 ),
m_selectedDifference( 0 ),
m_blended( false )
......@@ -71,6 +69,9 @@ DiffModel::DiffModel() :
/** */
DiffModel::~DiffModel()
{
m_selectedDifference = 0;
qDeleteAll( m_hunks );
}
void DiffModel::splitSourceInPathAndFileName()
......@@ -85,7 +86,7 @@ void DiffModel::splitSourceInPathAndFileName()
else
m_sourceFile = m_source;
kDebug(8101) << m_source << "was split into" << m_sourcePath << "and" << m_sourceFile;
kDebug(8101) << m_source << " was split into " << m_sourcePath << " and " << m_sourceFile << endl;
}
void DiffModel::splitDestinationInPathAndFileName()
......@@ -98,9 +99,9 @@ void DiffModel::splitDestinationInPathAndFileName()
if( ( pos = m_destination.lastIndexOf( "/" ) ) >= 0 )
m_destinationFile = m_destination.mid( pos+1, m_destination.length() - pos );
else
m_destinationFile = m_source;
m_destinationFile = m_destination;
kDebug(8101) << m_destination << "was split into" << m_destinationPath << "and" << m_destinationFile;
kDebug(8101) << m_destination << " was split into " << m_destinationPath << " and " << m_destinationFile << endl;
}
DiffModel& DiffModel::operator=( const DiffModel& model )
......@@ -118,7 +119,6 @@ DiffModel& DiffModel::operator=( const DiffModel& model )
m_destinationTimestamp = model.m_destinationTimestamp;
m_destinationRevision = model.m_destinationRevision;
m_appliedCount = model.m_appliedCount;
m_modified = model.m_modified;