// stl
#include <iostream>
#include <algorithm>
// Lua
#include "luaxx/luaxx.h"
// SubCpp
//#include "../../revision.hpp"
#include "FunctionOptions.h"
#include "BindRevision.h"
svn_depth_t BindFunctionOptions::StringToDepth( std::string strDepth )
{
svn_depth_t retVal = svn_depth_unknown;
// Make the string lower case so the comparision can be
std::transform( strDepth.begin(), strDepth.end(), strDepth.begin(), ::tolower );
if ( "empty" == strDepth )
{
retVal = svn_depth_empty;
}
else if ( "infinity" == strDepth )
{
retVal = svn_depth_infinity;
}
else if ( "files" == strDepth )
{
retVal = svn_depth_files;
}
else if ( "immediates" == strDepth )
{
retVal = svn_depth_immediates;
}
return retVal;
}
void BindFunctionOptions::To( lua_State* luaState, FunctionOptions& options, int index /*= -1*/ )
{
lua::state lState( luaState );
if ( lState.istable( index ) )
{
lState.getfield( "revision", index );
if ( !lState.isnoneornil() )
{
// Check what the revision
BindRevision::To( lState, options.m_revision );
// Default peg to revision so that it acts as the client does.
options.m_peg = options.m_revision;
}
lState.pop(); // revision cleanup
lState.getfield( "peg", index );
if ( !lState.isnoneornil() )
{
// Check what the revision
BindRevision::To( lState, options.m_peg );
}
lState.pop(); // peg cleanup
lState.getfield( "depth", index );
if ( !lState.isnoneornil() )
{
// Check for a supplied depth
if ( "number" == lState.type_name() )
{
// Help VC with casting from an enum to a number
options.m_depth = static_cast< svn_depth_t >( lState.as< int >( options.m_depth ) );
}
else
{
std::string optDepth;
lState.to( optDepth );
options.m_depth = StringToDepth( optDepth );
}
}
lState.pop(); // depth cleanup
lState.getfield( "ignore_externals", index );
if ( !lState.isnoneornil() )
{
// Check if we should ignore externals
options.m_shouldIgnoreExternals = lState.as( options.m_shouldIgnoreExternals );
}
lState.pop(); // ignore_externals cleanup
lState.getfield( "ignore_keywords", index );
if ( !lState.isnoneornil() )
{
// Check if we should ignore externals
options.m_shouldIgnoreKeywords = lState.as( options.m_shouldIgnoreKeywords );
}
lState.pop(); // ignore_keywords cleanup
lState.getfield( "no_ignore", index );
if ( !lState.isnoneornil() )
{
// Check if we should ignore externals
options.m_shouldIgnoreIgnore = lState.as( options.m_shouldIgnoreIgnore );
}
lState.pop(); // no_ignore cleanup
lState.getfield( "force", index );
if ( !lState.isnoneornil() )
{
// Check if we should ignore externals
options.m_shouldForce = lState.as( options.m_shouldForce );
}
lState.pop(); // force cleanup
lState.getfield( "native_eol", index );
if ( !lState.isnoneornil() )
{
// Check if we should change the files EOL marker.
options.m_nativeEolMarker = lState.as( options.m_nativeEolMarker );
}
lState.pop(); // native_eol cleanup
lState.getfield( "set_depth", index );
if ( !lState.isnoneornil() )
{
// Check if we should set the depth to the WC.
options.m_shouldSetDepth = lState.as( options.m_shouldSetDepth );
}
lState.pop(); // set_depth cleanup
lState.getfield( "parents", index );
if ( !lState.isnoneornil() )
{
// Check if we should set adding parents till a versioned dir is found.
options.m_shouldMakeParents = lState.as( options.m_shouldMakeParents );
}
lState.pop(); // parents cleanup
lState.getfield( "add_parents", index );
if ( !lState.isnoneornil() )
{
// Check if we should set adding parents till a versioned dir is found.
options.m_shouldAddParents = lState.as( options.m_shouldAddParents );
}
lState.pop(); // add_parents cleanup
lState.getfield( "keep_locks", index );
if ( !lState.isnoneornil() )
{
// Check if we should keep the locked files locked after a commit.
options.m_shouldKeepLocks = lState.as( options.m_shouldKeepLocks );
}
lState.pop(); // keep_locks cleanup
lState.getfield( "keep_changelists", index );
if ( !lState.isnoneornil() )
{
// Check if we should keep the changelist after the commit.
options.m_shouldKeepChangelists = lState.as( options.m_shouldKeepChangelists );
}
lState.pop(); // keep_changelists cleanup
lState.getfield( "auto_props", index );
if ( !lState.isnoneornil() )
{
// Check if we should use the auto-props set in the context.
options.m_shouldEnableAutoProps = lState.as( options.m_shouldEnableAutoProps );
}
lState.pop(); // auto_props cleanup
lState.getfield( "ignore_unknown_node_types", index );
if ( !lState.isnoneornil() )
{
// Check if we should we ignore the unknown node types.
options.m_shouldIgnoreUnknownNodeTypes = lState.as( options.m_shouldIgnoreUnknownNodeTypes );
}
lState.pop(); // ignore_unknown_node_types cleanup
lState.getfield( "keep_local", index );
if ( !lState.isnoneornil() )
{
// Check if we should keep local files after deleting.
options.m_shouldKeepLocal = lState.as( options.m_shouldKeepLocal );
}
lState.pop(); // keep_local cleanup
}
/*else
{
std::string errorMsg = "Options table expected. Found a ";
errorMsg += lState.type_name( index );
throw BindFunctionOptionsEx( errorMsg.c_str() );
}*/
}