1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
/**************************************************************************
** perforceparser.cpp
** ------------------
** begin : Sun Aug 4 15:05:35 2002
** Copyright 2002-2004 Otto Bruggeman <otto.bruggeman@home.nl>
***************************************************************************/
/***************************************************************************
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** ( at your option ) any later version.
**
***************************************************************************/
#include "perforceparser.h"
#include <QtCore/QRegExp>
#include <kdebug.h>
using namespace Diff2;
PerforceParser::PerforceParser( const KompareModelList* list, const QStringList& diff ) : ParserBase( list, diff )
{
m_contextDiffHeader1.setPattern( "==== (.*) - (.*) ====\\n" );
m_contextDiffHeader1.setMinimal( true );
m_normalDiffHeader.setPattern ( "==== (.*) - (.*) ====\\n" );
m_normalDiffHeader.setMinimal ( true );
m_rcsDiffHeader.setPattern ( "==== (.*) - (.*) ====\\n" );
m_rcsDiffHeader.setMinimal ( true );
m_unifiedDiffHeader1.setPattern( "==== (.*) - (.*) ====\\n" );
m_unifiedDiffHeader1.setMinimal( true );
}
PerforceParser::~PerforceParser()
{
}
enum Kompare::Format PerforceParser::determineFormat()
{
kDebug(8101) << "Determining the format of the Perforce Diff" << endl;
QRegExp unifiedRE( "^@@" );
QRegExp contextRE( "^\\*{15}" );
QRegExp normalRE ( "^\\d+(|,\\d+)[acd]\\d+(|,\\d+)" );
QRegExp rcsRE ( "^[acd]\\d+ \\d+" );
// Summary is not supported since it gives no useful parsable info
QStringList::ConstIterator it = m_diffLines.begin();
while( it != m_diffLines.end() )
{
if( it->indexOf( unifiedRE, 0 ) == 0 )
{
kDebug(8101) << "Difflines are from a Unified diff..." << endl;
return Kompare::Unified;
}
else if( it->indexOf( contextRE, 0 ) == 0 )
{
kDebug(8101) << "Difflines are from a Context diff..." << endl;
return Kompare::Context;
}
else if( it->indexOf( normalRE, 0 ) == 0 )
{
kDebug(8101) << "Difflines are from a Normal diff..." << endl;
return Kompare::Normal;
}
else if( it->indexOf( rcsRE, 0 ) == 0 )
{
kDebug(8101) << "Difflines are from a RCS diff..." << endl;
return Kompare::RCS;
}
++it;
}
kDebug(8101) << "Difflines are from an unknown diff..." << endl;
return Kompare::UnknownFormat;
}
bool PerforceParser::parseContextDiffHeader()
{
// kDebug(8101) << "ParserBase::parseContextDiffHeader()" << endl;
bool result = false;
QStringList::ConstIterator itEnd = m_diffLines.end();
QRegExp sourceFileRE ( "([^\\#]+)#(\\d+)" );
QRegExp destinationFileRE( "([^\\#]+)#(|\\d+)" );
while ( m_diffIterator != itEnd )
{
if ( m_contextDiffHeader1.exactMatch( *(m_diffIterator)++ ) )
{
// kDebug(8101) << "Matched length Header1 = " << m_contextDiffHeader1.matchedLength() << endl;
// kDebug(8101) << "Matched string Header1 = " << m_contextDiffHeader1.cap( 0 ) << endl;
// kDebug(8101) << "First capture Header1 = " << m_contextDiffHeader1.cap( 1 ) << endl;
// kDebug(8101) << "Second capture Header1 = " << m_contextDiffHeader1.cap( 2 ) << endl;
m_currentModel = new DiffModel();
sourceFileRE.exactMatch( m_contextDiffHeader1.cap( 1 ) );
destinationFileRE.exactMatch( m_contextDiffHeader1.cap( 2 ) );
kDebug(8101) << "Matched length = " << sourceFileRE.matchedLength() << endl;
kDebug(8101) << "Matched length = " << destinationFileRE.matchedLength() << endl;
kDebug(8101) << "Captured texts = " << sourceFileRE.capturedTexts() << endl;
kDebug(8101) << "Captured texts = " << destinationFileRE.capturedTexts() << endl;
kDebug(8101) << "Source File : " << sourceFileRE.cap( 1 ) << endl;
kDebug(8101) << "Destination File : " << destinationFileRE.cap( 1 ) << endl;
m_currentModel->setSourceFile ( sourceFileRE.cap( 1 ) );
m_currentModel->setDestinationFile( destinationFileRE.cap( 1 ) );
result = true;
break;
}
else
{
kDebug(8101) << "Matched length = " << m_contextDiffHeader1.matchedLength() << endl;
kDebug(8101) << "Captured texts = " << m_contextDiffHeader1.capturedTexts() << endl;
}
}
return result;
}
bool PerforceParser::parseNormalDiffHeader()
{
bool result = false;
QStringList::ConstIterator itEnd = m_diffLines.end();
QRegExp sourceFileRE ( "([^\\#]+)#(\\d+)" );
QRegExp destinationFileRE( "([^\\#]+)#(|\\d+)" );
while ( m_diffIterator != itEnd )
{
kDebug(8101) << "Line = " << *m_diffIterator << endl;
kDebug(8101) << "String length = " << (*m_diffIterator).length() << endl;
if ( m_normalDiffHeader.exactMatch( *(m_diffIterator)++ ) )
{
kDebug(8101) << "Matched length Header1 = " << m_normalDiffHeader.matchedLength() << endl;
kDebug(8101) << "Matched string Header1 = " << m_normalDiffHeader.cap( 0 ) << endl;
kDebug(8101) << "First capture Header1 = \"" << m_normalDiffHeader.cap( 1 ) << "\"" << endl;
kDebug(8101) << "Second capture Header1 = \"" << m_normalDiffHeader.cap( 2 ) << "\"" << endl;
m_currentModel = new DiffModel();
sourceFileRE.exactMatch( m_normalDiffHeader.cap( 1 ) );
destinationFileRE.exactMatch( m_normalDiffHeader.cap( 2 ) );
kDebug(8101) << "Matched length = " << sourceFileRE.matchedLength() << endl;
kDebug(8101) << "Matched length = " << destinationFileRE.matchedLength() << endl;
kDebug(8101) << "Captured texts = " << sourceFileRE.capturedTexts() << endl;
kDebug(8101) << "Captured texts = " << destinationFileRE.capturedTexts() << endl;
kDebug(8101) << "Source File : " << sourceFileRE.cap( 1 ) << endl;
kDebug(8101) << "Destination File : " << destinationFileRE.cap( 1 ) << endl;
m_currentModel->setSourceFile ( sourceFileRE.cap( 1 ) );
m_currentModel->setDestinationFile( destinationFileRE.cap( 1 ) );
result = true;
break;
}
else
{
kDebug(8101) << "Matched length = " << m_normalDiffHeader.matchedLength() << endl;
kDebug(8101) << "Captured texts = " << m_normalDiffHeader.capturedTexts() << endl;
}
}
return result;
}
bool PerforceParser::parseRCSDiffHeader()
{
return false;
}
bool PerforceParser::parseUnifiedDiffHeader()
{
bool result = false;
QStringList::ConstIterator itEnd = m_diffLines.end();
QRegExp sourceFileRE ( "([^\\#]+)#(\\d+)" );
QRegExp destinationFileRE( "([^\\#]+)#(|\\d+)" );
while ( m_diffIterator != itEnd )
{
// kDebug(8101) << "Line = " << *m_diffIterator << endl;
// kDebug(8101) << "String length = " << (*m_diffIterator).length() << endl;
if ( m_unifiedDiffHeader1.exactMatch( *(m_diffIterator)++ ) )
{
// kDebug(8101) << "Matched length Header1 = " << m_unifiedDiffHeader1.matchedLength() << endl;
// kDebug(8101) << "Matched string Header1 = " << m_unifiedDiffHeader1.cap( 0 ) << endl;
// kDebug(8101) << "First capture Header1 = \"" << m_unifiedDiffHeader1.cap( 1 ) << "\"" << endl;
// kDebug(8101) << "Second capture Header1 = \"" << m_unifiedDiffHeader1.cap( 2 ) << "\"" << endl;
m_currentModel = new DiffModel();
sourceFileRE.exactMatch( m_unifiedDiffHeader1.cap( 1 ) );
destinationFileRE.exactMatch( m_unifiedDiffHeader1.cap( 2 ) );
// kDebug(8101) << "Matched length = " << sourceFileRE.matchedLength() << endl;
// kDebug(8101) << "Matched length = " << destinationFileRE.matchedLength() << endl;
// kDebug(8101) << "Captured texts = " << sourceFileRE.capturedTexts() << endl;
// kDebug(8101) << "Captured texts = " << destinationFileRE.capturedTexts() << endl;
// kDebug(8101) << "Source File : " << sourceFileRE.cap( 1 ) << endl;
// kDebug(8101) << "Destination File : " << destinationFileRE.cap( 1 ) << endl;
m_currentModel->setSourceFile ( sourceFileRE.cap( 1 ) );
m_currentModel->setDestinationFile( destinationFileRE.cap( 1 ) );
result = true;
break;
}
else
{
// kDebug(8101) << "Matched length = " << m_unifiedDiffHeader1.matchedLength() << endl;
// kDebug(8101) << "Captured texts = " << m_unifiedDiffHeader1.capturedTexts() << endl;
}
}
return result;
}
|