DAUserFilelog.cpp #1

  • //
  • guest/
  • sam_stafford/
  • deepannotate/
  • DAUserFilelog.cpp
  • View
  • Commits
  • Open Download .zip Download (4 KB)
#include <clientapi.h>
#include "DAUserFilelog.h"

#include "DAFile.h"
#include "DARev.h"
#include "DAInteg.h"

DAUserFilelog::DAUserFilelog( DAFile* f, bool* tag )
:file( f ), tagFlag( tag )
{
	done = false;
	rev = 0x0;
}

DAUserFilelog::~DAUserFilelog(void)
{
}

void DAUserFilelog::OutputStat( StrDict* varList )
{
	*tagFlag = true;
	if ( done ) return;
	
	file->setPath( varList->GetVar( "depotFile" ) );
	
	StrPtr *num, *change, *action;
	bool edited;
	StrPtr *how, *source, *srev, *erev;
	DAInteg::How ihow;
	int isrev, ierev;
	int i, j;

	i = 0;
	while( num = varList->GetVar( StrRef("rev"), i ) )
	{
		change = varList->GetVar( StrRef("change"), i );
		if ( !change ) return;

		action = varList->GetVar( StrRef("action"), i );
		if ( !action ) return;

		edited = ( *action == "add" || *action == "edit" );

		rev = file->addRev( num->Atoi(), change->Atoi() );
		if ( !rev ) return;

		rev->setEdited( edited );

		j = 0;
		while ( how = varList->GetVar( StrRef("how"), i, j ) )
		{
			if		( *how == "add from"	) ihow = DAInteg::Add;
			else if	( *how == "branch from" ) ihow = DAInteg::Branch;
			else if ( *how == "copy from"	) ihow = DAInteg::Copy;
			else if ( *how == "edit from"	) ihow = DAInteg::Edit;
			else if ( *how == "ignored"		) ihow = DAInteg::Ignore;
			else if ( *how == "merge from"	) ihow = DAInteg::Merge;
			else	
			{	
				j++;
				continue; 
			}
			source	= varList->GetVar( StrRef("file"), i, j );
			srev	= varList->GetVar( StrRef("srev"), i, j );
			erev	= varList->GetVar( StrRef("erev"), i, j );
			if ( !source || !srev || !erev || 
					srev->Length() < 2 || erev->Length() < 2 )
			{
				j++;
				continue;
			}

			isrev = atoi( srev->Text() + 1 ) + 1;
			ierev = atoi( erev->Text() + 1 );

			rev->addInteg( ihow, source, isrev, ierev );
			
			j++;
		}

		i++;
	}

	done = true;
}

void DAUserFilelog::OutputInfo( char level, const char* data )
{
	if ( done ) return;

	if ( level == '0' )
	{
		if ( file->getPath().Length() )
		{
			done = true;
			return;
		}
		StrRef path( data );
		file->setPath( &path );
		return;
	}

	if ( level == '1' )
	{
		StrBuf revNum, changeNum, action;
		StrBuf changeTag;
		if ( *data && *data == '#' ) data++;
		while ( *data && *data != ' ' )
		{
			revNum.Append( data++, 1 );
		}
		if ( !*data ) return;

		changeTag.Append( data, 8 );
		if ( changeTag != " change " )
			return;
		data += 8;
		while ( *data && *data != ' ' )
		{
			changeNum.Append( data++, 1 );
		}
		if ( !*data ) return;
		data++;

		rev = file->addRev( revNum.Atoi(), changeNum.Atoi() );
		if ( !rev ) return;

		if ( *data == 'a' || *data == 'e' )
			rev->setEdited( true );

		return;
	}

	if ( level == '2' )
	{
		if ( !rev ) return;

		DAInteg::How how;
		StrRef line( data );
		     if ( line.Contains( StrRef( "add from //" ) ) )
		{
			how = DAInteg::Add;
			data += 9;
		}
		else if ( line.Contains( StrRef( "branch from //" ) ) )
		{
			how = DAInteg::Branch;
			data += 12;
		}
		else if ( line.Contains( StrRef( "copy from //" ) ) )
		{
			how = DAInteg::Copy;
			data += 10;
		}
		else if ( line.Contains( StrRef( "edit from //" ) ) )
		{
			how = DAInteg::Edit;
			data += 10;
		}
		else if ( line.Contains( StrRef( "merge from //" ) ) )
		{
			how = DAInteg::Merge;
			data += 11;
		}
		else if ( line.Contains( StrRef( "ignored //" ) ) )
		{
			how = DAInteg::Ignore;
			data += 8;
		}
		else
			return;

		StrBuf path;
		while ( *data && *data != '#' )
		{
			path.Append( data++, 1 );
		}
		if ( *data ) data++;	// '#'

		StrBuf srev;
		while ( *data && *data != ',' )
		{
			srev.Append( data++, 1 );
		}
		if ( *data ) data++;	// ','
		if ( *data ) data++;	// '#'

		StrBuf erev;
		if ( !*data ) erev = srev;
		else
		{
			while ( *data ) erev.Append( data++, 1 );
		}

		rev->addInteg( how, &path, srev.Atoi(), erev.Atoi() );
	}
}

void DAUserFilelog::HandleError( Error* )
{
	// Any error that a filelog can generate should either be
	// getting handled elsewhere or a permissions error that
	// we don't want to bother the user with.  So we will
	// quietly drop them rather than passing them back to
	// the invoking ClientUser.
}
# Change User Description Committed
#1 6297 Sam Stafford Work so far on "deep annotate".
 Been getting a lot of questions on
this lately from other people working on the same thing; might as well
pool efforts.