joincheck.cpp #1

  • //
  • guest/
  • sam_stafford/
  • joincheck/
  • joincheck.cpp
  • View
  • Commits
  • Open Download .zip Download (3 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;
	joinPB = 0;
	joinPBC = 0;
}

JoinCheck::~JoinCheck()
{
	delete joinPB;
	delete joinPBC;
}

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::DoJoins()
{
	delete joinPB;
	delete joinPBC;

	joinPB = MapApi::Join( &protect, &branch );
	joinPBC = MapApi::Join( joinPB, &client );
}

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++;
	    }

	    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( "full join:\n" );
	DumpView( joinPBC );
}

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.