#include "BranchSpec.h"
#include "P4Process.h"
#include <qstringlist.h>
static const char* lockNames[] = {
"Locked",
"Unlocked"
};
Perforce::BranchSpec::BranchSpecCache Perforce::BranchSpec::_branchSpecCache;
Perforce::BranchSpec::BranchSpec()
{
}
Perforce::BranchSpec::~BranchSpec()
{
}
//
//========================================================================
//
Perforce::BranchSpec*
Perforce::BranchSpec::createBranchSpec( const QString& p4out )
{
Perforce::BranchSpec* bs = new Perforce::BranchSpec();
QString temp;
int start, end;
start = end = 7;
end = p4out.find( ' ', start );
temp = p4out.mid( start, (end-start) );
// qDebug( "'%s'", temp.latin1() );
bs->_branchName = temp;
start = end + 1;
end = p4out.find( ' ', start );
temp = p4out.mid( start, (end-start) );
// qDebug( "Date: '%s'", temp.latin1() );
QStringList date = QStringList::split( "/", temp );
int year = date[0].toInt();
int month = date[1].toInt();
int day = date[2].toInt();
// qDebug( "Year: %d", year );
// qDebug( "Month: %d", month );
// qDebug( "Day: %d", day );
bs->_date = QDate( year, month, day );
start = p4out.find( '\'', start ) + 1;
end = p4out.find( '\'', start );
temp = p4out.mid( start, (end-start) );
// qDebug( "description: %s", temp.latin1() );
bs->_description = temp;
// not sure where p4win gets these???
bs->_lock = Unlocked;
bs->_owner = "John Doe";
return bs;
}
QString Perforce::BranchSpec::lockToString( Lock l )
{
ASSERT( l >= 0 && l <= 1 );
return lockNames[ l ];
}
Perforce::BranchSpec::BranchSpecCache::BranchSpecCache()
{
}
void Perforce::BranchSpec::BranchSpecCache::updateCache()
{
P4Process p4;
_cache = p4.getBranchSpecs();
}
const Perforce::BranchSpecList& Perforce::BranchSpec::getBranches()
{
_branchSpecCache.updateCacheIfNecessary();
return _branchSpecCache.getCache();
}