joincheck.cpp #2

  • //
  • guest/
  • sam_stafford/
  • joincheck/
  • joincheck.cpp
  • View
  • Commits
  • Open Download .zip Download (4 KB)
# include <clientapi.h>
# include <mapapi.h>
# include <spec.h>
# include <strops.h>

# include "joincheck.h"

JoinCheck::JoinCheck( ClientApi* api, Error* e )
{
	this->api = api;
	this->e = e;
	join = 0;
	depotPath = 0;
	clientPath = 0;
}

JoinCheck::~JoinCheck()
{
	delete join;
	delete depotPath;
	delete clientPath;
}

void JoinCheck::LoadProtect( StrPtr* user )
{
	state = 'p';

	if ( user )
	{
	    char *args[2];
	    args[0] = "-u";
	    args[1] = user->Text();
	    api->SetArgv( 2, args );
	}
	api->Run( "protects", this );

	if ( !protect.Count() ) // empty?
	{
	    protect.Insert( StrRef( "//..." ) );
	}
}

void JoinCheck::LoadBranch( StrPtr* branch )
{
	state = 'b';

	if ( branch )
	{
	    char *args[2];
	    args[0] = "-o";
	    args[1] = branch->Text();
	    api->SetArgv( 2, args );
	    api->Run( "branch", this );
	}
	else
	{
	    this->branch.Insert( StrRef( "//..." ) );
	}
}

void JoinCheck::LoadClient( StrPtr* client )
{
	state = 'c';

	char *args[2];
	args[0] = "-o";
	args[1] = client ? client->Text() : 0;
	api->SetArgv( client ? 2 : 1, args );
	api->Run( "client", this );
}

void JoinCheck::LoadPath( char* path )
{
	delete depotPath;
	delete clientPath;

	if ( !path )
	{
	    depotPath = new MapApi();
	    clientPath = new MapApi();
	    depotPath->Insert( StrRef( "//..." ) );
	    clientPath->Insert( StrRef( "//..." ) );
	    return;
	}

	MapApi pTest;
	pTest.Insert( StrRef( path ) );
	MapApi *dTest = MapApi::Join( &pTest, &client );
	MapApi *cTest = MapApi::Join( &client, &pTest );
	StrBuf trans;

	if ( dTest->Count() )
	{
	    depotPath = new MapApi();
	    depotPath->Insert( StrRef( path ) );
	    delete dTest;
	    dTest = MapApi::Join( depotPath, &client );
	    clientPath = MapApi::Join
		( &client, MapRightLeft, dTest, MapLeftRight );
	}
	else if ( cTest->Count() )
	{
	    clientPath = new MapApi();
	    clientPath->Insert( StrRef( path ) );
	    delete cTest;
	    cTest = MapApi::Join( &client, clientPath );
	    depotPath = MapApi::Join
		( cTest, MapLeftRight, &client, MapRightLeft );
	}
	else
	{
	    OutputError( "Please give a full //depot or //client path.\n" );
	}
	
	delete dTest;
	delete cTest;
}

void JoinCheck::DoJoins()
{
	delete join;

	MapApi *j1 = MapApi::Join( &protect, &branch );
	MapApi *j2 = MapApi::Join( j1, depotPath );
	MapApi *j3 = MapApi::Join( j2, &protect );
	MapApi *j4 = MapApi::Join( j3, &client );
	join = MapApi::Join( j4, clientPath );

	delete j1;
	delete j2;
	delete j3;
	delete j4;
}

int JoinCheck::MaxWild( MapApi *view )
{
	int maxWild = 0;
	int maxThis;
	StrBuf half;
	StrRef find;
	for ( int i = 0 ; i < view->Count() ; i++ )
	{
	    maxThis = 0;
	    StrOps::Replace( half, *view->GetLeft( i ), 
		StrRef("..."), StrRef("*") );
	    find = half;
	    while ( find.Contains( StrRef("*") ) )
	    {
		find = find.Contains( StrRef("*") ) + 1;
		maxThis++;
	    }
	    if ( maxThis > maxWild )
		maxWild = maxThis;
	}
	return maxWild;
}

void JoinCheck::OutputStat( StrDict *varList )
{
	MapApi *ins;
	switch ( state )
	{
	    case 'p':
		ins = &protect;
		break;
	    case 'b':
		ins = &branch;
		break;
	    case 'c':
		ins = &client;
		break;
	    default:
		return;
	}

	if ( state == 'p' )
	{
	    ins->Insert( *varList->GetVar( "depotFile" ), 
		varList->GetVar( "unmap" ) ? MapExclude : MapInclude );

	    return;
	}

	const char *left;
	MapType type;
	StrPtr *line;
	SpecWords words;
	for ( int i = 0 ; line = varList->GetVar( StrRef("View"), i ) ; i++ )
	{
	    words.Set( *line );
	    
	    if ( words.Split() != 2 ) 
		continue;
	    
	    type = MapInclude;
	    left = words.wv[0];
	    if ( *left == '-' )
	    {
		type = MapExclude;
		left++;
	    }
	    if ( *left == '+' )
	    {
		type = MapOverlay;
		left++;
	    }

	    ins->Insert( StrRef( left ), StrRef( words.wv[1] ), type );
	}
}

void JoinCheck::DumpViews()
{
	printf( "protect:\n" );
	DumpView( &protect );
	printf( "branch:\n" );
	DumpView( &branch );
	printf( "client:\n" );
	DumpView( &client );
	printf( "depot path:\n" );
	DumpView( depotPath );
	printf( "client path:\n" );
	DumpView( clientPath );
	printf( "full join:\n" );
	DumpView( join );
}

void JoinCheck::DumpView( MapApi *view )
{
	char c = ' ';
	for ( int i = 0 ; i < view->Count() ; i++ )
	{
	    switch( view->GetType( i ) )
	    {
	    case MapInclude:
		c = ' '; break;
	    case MapExclude:
		c = '-'; break;
	    case MapOverlay:
		c = '+'; break;
	    }
	    printf( "%c%s %s\n", c,
		view->GetLeft( i )->Text(),
		view->GetRight( i )->Text() );
	}
}
# Change User Description Committed
#2 7728 Sam Stafford Add an option for a file path, and another join of
the protect table after the branch map.
#1 7727 Sam Stafford MapApi-based tool for displaying joins of protects, client,
and optionally a branch view.