// STL
#include <iostream>
// SubCpp
#include "../../client.hpp"
#include "../../context.hpp"
#include "../../context_listener.hpp"
#include "../../status.hpp"
#include "../../targets.hpp"
#include "SubLua.h"
#include "BindEntry.h"
#include "BindRevision.h"
#include "BindTargets.h"
#include "FunctionOptions.h"
#include "Version.h"
#include "SvnInfoReceiver.h"
#include "SvnDiffSummarizeReceiver.h"
// Set the class name to register in Lua.
const char SubLua::className[] = "SubLua";
// gtxDeviceComm function bindings.
const Lunax< SubLua >::RegType SubLua::Register[] =
{
{ "GetUsername", &SubLua::GetUsername },
{ "GetPassword", &SubLua::GetPassword },
{ "GetListener", &SubLua::GetContextListener },
{ "Cat", &SubLua::Cat },
{ "Upgrade", &SubLua::Upgrade },
{ "GetWorkingCopyFormatVersion", &SubLua::GetWorkingCopyFormatVersion },
{ "Checkout", &SubLua::Checkout },
{ "Commit", &SubLua::Commit },
{ "Update", &SubLua::Update },
{ "Export", &SubLua::Export },
{ "Get", &SubLua::Get },
{ "Add", &SubLua::Add },
{ "Import", &SubLua::Import },
{ "MkDir", &SubLua::MkDir },
{ "Delete", &SubLua::Delete },
//{ "Diff", &SubLua::Diff },
{ "DiffRevisions", &SubLua::DiffRevisions },
{ "DiffPaths", &SubLua::DiffPaths },
{ "Copy", &SubLua::Copy },
{ "Revert", &SubLua::Revert },
{ "Lock", &SubLua::Lock },
{ "Unlock", &SubLua::Unlock },
{ "Info", &SubLua::Info },
{ "PropGet", &SubLua::PropGet },
{ "PropSet", &SubLua::PropSet },
//{ "PropList", &SubLua::PropList },
{ "Cleanup", &SubLua::Cleanup },
{ "ReleaseWorkingCopyLock", &SubLua::ReleaseWorkingCopyLock },
{ "ParseExternalsDescription", &SubLua::ParseExternalsDescription },
{ 0, 0 }
};
SubLua::SubLua( lua_State* luaState )
:
m_luaState( luaState )
{
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 2 ) )
{
m_luaState.error( "SubLua( { username = 'user', password = 'mypassword', listener = listener[, no_auth_cahce = true] } ) - Too many parameters specified. Only an optional table should be specified." );
}
try
{
if( !m_luaState.istable() )
{
// None was supplied so use an empty one.
m_luaState.newtable();
m_luaState.newtable();
m_luaState.setfield( "listener" );
}
svn::Context* context = new svn::Context;
m_luaState.getfield( "username" );
std::string username = m_luaState.as( std::string() );
m_luaState.pop();
m_luaState.getfield( "password" );
std::string password = m_luaState.as( std::string() );
m_luaState.pop();
if ( !username.empty() )
{
context->SetLogin( username, password );
}
m_luaState.getfield( "no_auth_cache" );
bool shouldNotCacheAuthentication = m_luaState.as( false );
m_luaState.pop();
context->SetAuthCache( !shouldNotCacheAuthentication );
// Set the context options to the registry using the reference system.
m_contextOptionReference = m_luaState.ref();
context->SetListener( new SvnListener( m_luaState, m_contextOptionReference ) );
m_client.SetContext( context );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in SubLua constructor." );
}
}
SubLua::~SubLua()
{
m_luaState.unref( m_contextOptionReference );
}
int SubLua::Cat( lua_State* /*luaState*/ )
{
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 4 ) )
{
m_luaState.error( "SubLua:Cat( path, {options} ) - Too many parameters specified. Only the path and optional options table should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 3 );
m_luaState.push( m_client.Cat( path, options.m_peg, options.m_revision ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Cat()" );
}
return 1;
}
int SubLua::Upgrade( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Upgrade( path ) - Missing required parameters. Path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 3 ) )
{
m_luaState.error( "SubLua:Upgrade( path - Too many parameters specified. Only the path should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
m_client.UpgradeWorkingCopy( path );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Upgrade()" );
}
return 1;
}
int SubLua::GetWorkingCopyFormatVersion( lua_State* luaState )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:GetWorkingCopyFormatVersion( path ) - Missing required parameters. Path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 3 ) )
{
m_luaState.error( "SubLua:GetWorkingCopyFormatVersion( path - Too many parameters specified. Only the path should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
m_luaState.push( m_client.GetWorkingCopyFormatVersion( path ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in GetWorkingCopyFormatVersion()" );
}
return 1;
}
int SubLua::Checkout( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 2(required parameters) = 3 required.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:Checkout( url, path[, {options}] ) - Missing required parameters. url and path are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Checkout( url, path, {options} ) - Too many parameters specified. Only the url, path, and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string url;
m_luaState.to( url, 2 );
std::string path;
m_luaState.to( path, 3 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 4 );
m_luaState.push( m_client.Checkout( url, path, options.m_peg, options.m_revision, options.m_depth, options.m_shouldIgnoreExternals, options.m_shouldForce ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Checkout()" );
}
return 1;
}
int SubLua::Update( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Update( path[, {options}] ) - Missing required parameters. path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 4 ) )
{
m_luaState.error( "SubLua:Update( path, {options} ) - Too many parameters specified. Only the path and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 3 );
m_luaState.push( m_client.Update( paths, options.m_revision, options.m_depth, options.m_shouldSetDepth, options.m_shouldIgnoreExternals, options.m_shouldForce ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Update()" );
}
return 1;
}
int SubLua::Export( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 2(required parameters) = 3 required.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:Export( srcPath, destPath[, {options}] ) - Missing required parameters. srcPath and destPath are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Export( srcPath, destPath, {options} ) - Too many parameters specified. Only the srcPath, destPath, and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string srcPath;
m_luaState.to( srcPath, 2 );
std::string destPath;
m_luaState.to( destPath, 3 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 4 );
// Set this so it works like the svn executable.
if( options.m_depth == svn_depth_unknown )
{
options.m_depth = svn_depth_infinity;
}
m_luaState.push( m_client.Export( srcPath, destPath, options.m_peg, options.m_revision, options.m_shouldForce, options.m_shouldIgnoreExternals, /*options.m_shouldIgnoreKeywords,*/ options.m_depth, options.m_nativeEolMarker ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Export()" );
}
return 1;
}
int SubLua::Get( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 2(required parameters) = 3 required.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:Get( path, destPath[, {options}] ) - Missing required parameters. path and destPath are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Get( path, destPath[, {options}] ) - Too many parameters specified. Only the path, destPath, and optional options table should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
std::string destPath;
m_luaState.to( destPath, 3 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 4 );
m_luaState.push( m_client.Get( path, destPath, options.m_peg, options.m_revision ).c_str() );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Get()" );
}
return 1;
}
int SubLua::Add( lua_State* /*luaState*/ )
{
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 4 ) )
{
m_luaState.error( "SubLua:Add( path, {options} ) - Too many parameters specified. Only the path and optional options table should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 3 );
m_client.Add( path, options.m_depth, options.m_shouldForce, options.m_shouldIgnoreIgnore, options.m_shouldAddParents );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Add()" );
}
return 0;
}
int SubLua::Import( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:Import( path, url[, message, {options}] ) - Missing required parameters. Only path and url are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 6 ) )
{
m_luaState.error( "SubLua:Import( path, url[, message, {options}] ) - Too many parameters specified. Only the path, message, and optional options table should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
std::string url;
m_luaState.to( url, 3 );
std::string msg;
FunctionOptions options;
if( m_luaState.istable( 4 ) )
{
BindFunctionOptions::To( m_luaState, options, 4 );
}
else if( m_luaState.type_name( 4 ) == "string" )
{
msg = m_luaState.as( msg, 4 );
BindFunctionOptions::To( m_luaState, options, 5 );
}
m_client.Import( path, url, msg, options.m_depth, options.m_shouldIgnoreIgnore, options.m_shouldIgnoreUnknownNodeTypes );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Add()" );
}
return 0;
}
int SubLua::MkDir( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:MkDir( path[, message, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:MkDir( path[, message, {options}] ) - Too many parameters specified. Only the path, message, and optional options table should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
std::string msg;
FunctionOptions options;
if( m_luaState.istable( 3 ) )
{
BindFunctionOptions::To( m_luaState, options, 3 );
}
else if( m_luaState.type_name( 3 ) == "string" )
{
msg = m_luaState.as( msg, 3 );
BindFunctionOptions::To( m_luaState, options, 4 );
}
m_client.MkDir( paths, msg, options.m_shouldMakeParents );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in MkDir()" );
}
return 0;
}
int SubLua::Delete( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Delete( path[, message, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Delete( path, message, {options} ) - Too many parameters specified. Only the path, message and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
std::string msg = std::string();
FunctionOptions options;
if ( m_luaState.isstring( 3 ) )
{
msg = m_luaState.as( std::string(), 3 );
BindFunctionOptions::To( m_luaState, options, 4 );
}
else
{
BindFunctionOptions::To( m_luaState, options, 3 );
}
m_client.Delete( paths, msg, options.m_shouldForce, options.m_shouldKeepLocal );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Remove()" );
}
return 0;
}
int SubLua::Commit( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Commit( path[, message, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Commit( path, message, {options} ) - Too many parameters specified. Only the path and message should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
std::string msg = std::string();
FunctionOptions options;
options.m_depth = svn_depth_infinity; // default it to svn_depth_infinity because that is how the client acts.
if ( m_luaState.isstring( 3 ) )
{
msg = m_luaState.as( std::string(), 3 );
BindFunctionOptions::To( m_luaState, options, 4 );
}
else
{
BindFunctionOptions::To( m_luaState, options, 3 );
}
m_client.Commit( paths, msg, options.m_depth, options.m_shouldKeepLocks, options.m_shouldKeepChangelists );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Commit()" );
}
return 0;
}
int SubLua::Revert( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Revert( path[, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 4 ) )
{
m_luaState.error( "SubLua:Revert( path[, {options}] ) - Too many parameters specified. Only the path and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 3 );
if ( svn_depth_unknown == options.m_depth )
{
options.m_depth = svn_depth_empty;
}
m_client.Revert( paths, options.m_depth ); // Currently not supporting changlelists
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Revert()" );
}
return 0;
}
int SubLua::Lock( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Lock( path[, message, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Lock( path[, message, {options}] ) - Too many parameters specified. Only the path, message, and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
std::string msg = m_luaState.as( std::string(), 3 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 4 );
m_client.Lock( paths, msg, options.m_shouldForce );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Lock()" );
}
return 0;
}
int SubLua::Unlock( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Unlock( path[, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 4 ) )
{
m_luaState.error( "SubLua:Unlock( path[, {options}] ) - Too many parameters specified. Only the path and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
svn::Targets paths;
BindTargets::To( m_luaState, paths, 2 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 3 );
m_client.Unlock( paths, options.m_shouldForce );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Unlock()" );
}
return 0;
}
int SubLua::Info( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 2 )
{
m_luaState.error( "SubLua:Info( path[, infoCallbackFunction, {options}] ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Info( path[, infoCallbackFunction, {options}] ) - Too many parameters specified. Only the path and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
FunctionOptions options;
if( !m_luaState.isnoneornil( 3 ) )
{
if( m_luaState.istable( 3 ) )
{
BindFunctionOptions::To( m_luaState, options, 3 );
}
else if( m_luaState.isfunction( 3 ) )
{
BindFunctionOptions::To( m_luaState, options, 4 );
m_luaState.pushvalue( 3 );
SvnInfoReceiver infoReceiver( m_luaState );
m_client.Info( path, infoReceiver, options.m_peg, options.m_revision, options.m_depth );
return 0;
}
else
{
m_luaState.typerror( 3, "table/function" );
}
}
BindInfo::Push( m_luaState, m_client.Info( path, options.m_peg, options.m_revision ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Info()" );
}
return 1;
}
int SubLua::DiffPaths( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:DiffPaths( path1, path2[, summarizeCallback, {options}] ) - Missing required parameters. path1 and path2 are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 6 ) )
{
m_luaState.error( "SubLua:DiffPaths( path1, path2[, summarizeCallback, {options}] ) - Too many parameters specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path1;
m_luaState.to( path1, 2 );
std::string path2;
m_luaState.to( path2, 3 );
FunctionOptions options;
if( !m_luaState.isnoneornil( 4 ) )
{
if( m_luaState.istable( 4 ) )
{
BindFunctionOptions::To( m_luaState, options, 4 );
}
else if( m_luaState.isfunction( 4 ) )
{
// Get the options table
BindFunctionOptions::To( m_luaState, options, 5 );
if ( options.m_shouldSummarize )
{
// Duplicate the callback
m_luaState.pushvalue( 4 );
// Setup calling the specified Lua function
SvnDiffSummarizeReceiver diffSummarizeReceiver( m_luaState );
// Call the diff that summarizes
m_client.DiffSummarizeCallback( path1, path2, diffSummarizeReceiver, options.m_revision, options.m_revision2, options.m_depth, options.m_shouldNoticeAncestry );
return 0;
}
}
else
{
m_luaState.typerror( 4, "table/function" );
}
}
// Figure out what version of the diff to call
if ( options.m_shouldSummarize )
{
BindDiffSummarize::Push( m_luaState, m_client.DiffSummarize( path1, path2, options.m_revision, options.m_revision2, options.m_depth, options.m_shouldNoticeAncestry ) );
return 1;
}
else
{
m_luaState.push( m_client.Diff( path1, path2, options.m_revision, options.m_revision2, options.m_depth, options.m_shouldNoticeAncestry, options.m_noDiffDeleted, options.m_shouldIgnoreContentType ) );
return 1;
}
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in DiffPaths()" );
}
return 1;
}
int SubLua::DiffRevisions( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
if( m_luaState.size() < 4 )
{
m_luaState.error( "SubLua:DiffRevisions( path, startRevision, endRevision[, summarizeCallback, {options}] ) - Missing required parameters. path, startRevision, and endRevision are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 7 ) )
{
m_luaState.error( "SubLua:DiffRevisions( path, startRevision, endRevision[, summarizeCallback, {options}] ) - Too many parameters specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string path;
m_luaState.to( path, 2 );
svn::Revision startRevision;
if( !m_luaState.isnoneornil( 3 ) )
{
BindRevision::To( m_luaState, startRevision, 3 );
}
svn::Revision endRevision;
if( !m_luaState.isnoneornil( 4 ) )
{
BindRevision::To( m_luaState, endRevision, 4 );
}
FunctionOptions options;
if( !m_luaState.isnoneornil( 5 ) )
{
if( m_luaState.istable( 5 ) )
{
BindFunctionOptions::To( m_luaState, options, 5 );
}
else if( m_luaState.isfunction( 5 ) )
{
// Get the options table
BindFunctionOptions::To( m_luaState, options, 6 );
if ( options.m_shouldSummarize )
{
// Duplicate the callback
m_luaState.pushvalue( 5 );
// Setup calling the specified Lua function
SvnDiffSummarizeReceiver diffSummarizeReceiver( m_luaState );
// Call the diff that summarizes
m_client.DiffSummarizeCallback( path, startRevision, endRevision, diffSummarizeReceiver, options.m_peg, options.m_depth, options.m_shouldNoticeAncestry );
return 0;
}
}
else
{
m_luaState.typerror( 5, "table/function" );
}
}
// Figure out what version of the diff to call
if ( options.m_shouldSummarize )
{
BindDiffSummarize::Push( m_luaState, m_client.DiffSummarize( path, startRevision, endRevision, options.m_peg, options.m_depth, options.m_shouldNoticeAncestry ) );
return 1;
}
else
{
m_luaState.push( m_client.Diff( path, startRevision, endRevision, options.m_peg, options.m_depth, options.m_shouldNoticeAncestry, options.m_noDiffDeleted, options.m_shouldIgnoreContentType ) );
return 1;
}
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in DiffRevisions()" );
}
return 1;
}
int SubLua::Copy( lua_State* /*luaState*/ )
{
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:Copy( srcPath, srcRevision, destPath ) - Too many parameters specified. Only the source path, source revision, and destination path should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string srcPath;
m_luaState.to( srcPath, 2 );
svn::Revision srcRevision;
BindRevision::To( m_luaState, srcRevision, 3 );
std::string destPath;
m_luaState.to( destPath, 4 );
m_client.Copy( srcPath, srcRevision, destPath );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Diff()" );
}
return 0;
}
int SubLua::PropGet( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 1(required parameters) = 2 required.
if( m_luaState.size() < 3 )
{
m_luaState.error( "SubLua:PropGet( propertyName, path[, {options}] ) - Missing required parameters. propertyName and path are required." );
}
// Check for correct parameter ammount.
if( !m_luaState.isnoneornil( 5 ) )
{
m_luaState.error( "SubLua:PropGet( propertyName, path, {options} ) - Too many parameters specified. Only the propertyName, path, and options should be specified." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string propertyName;
m_luaState.to( propertyName, 2 );
std::string path;
m_luaState.to( path, 3 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 4 );
m_luaState.push( m_client.PropGet( propertyName, path, options.m_revision, options.m_depth ) );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in PropGet()" );
}
return 1;
}
int SubLua::PropSet( lua_State* /*luaState*/ )
{
// Check for the correct number of required parameters.
// 1(lunax pointer) + 5(required parameters) = 6 required.
if( m_luaState.size() < 6 )
{
m_luaState.error( "SubLua:PropSet( propertyName, propertyValue, path, message, {options} ) - Missing required parameters. propertyName, propertyValue, path, message, and options are required." );
}
try
{
// Get the function parameters. The first parameter is the Lunax pointer.
std::string propertyName;
m_luaState.to( propertyName, 2 );
std::string propVal;
m_luaState.to( propVal, 3 );
std::string path;
m_luaState.to( path, 4 );
std::string message;
m_luaState.to( message, 5 );
FunctionOptions options;
BindFunctionOptions::To( m_luaState, options, 5 );
// Set this so it works like the svn executable.
if( svn_depth_unknown == options.m_depth )
{
options.m_depth = svn_depth_empty;
}
m_client.PropSet( propertyName, propVal, path, options.m_revision, message, options.m_depth );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in PropSet()" );
}
return 1;
}
int SubLua::Cleanup( lua_State* luaState )
{
lua::state lState( luaState );
// Check for the correct number of required parameters.
if( lState.size() < 2 )
{
lState.error( "SubLua:Cleanup( path ) - Missing required parameters. Only path is required." );
}
// Check for correct parameter ammount.
if( !lState.isnoneornil( 3 ) )
{
lState.error( "SubLua:Cleanup() - Too many parameters specified. Only path should be specified." );
}
try
{
std::string path;
m_luaState.to( path, 2 );
m_client.Cleanup( path );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in Cleanup()" );
}
return 0;
}
int SubLua::ReleaseWorkingCopyLock( lua_State* luaState )
{
lua::state lState( luaState );
// Check for correct parameter ammount.
if( !lState.isnoneornil( 2 ) )
{
lState.error( "SubLua:ReleaseWorkingCopyLock() - Too many parameters specified. None should be specified." );
}
try
{
m_client.ReleaseWorkingCopyLock();
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in ReleaseWorkingCopyLock()" );
}
return 0;
}
int SubLua::ParseExternalsDescription( lua_State* )
{
if( !m_luaState.isnoneornil( 3 ) )
{
m_luaState.error( "SubLua:ParseExternalsDescription() - Too many parameters specified. One should be specified." );
}
try
{
std::string description;
m_luaState.to( description, 2 );
m_luaState.pop();
std::vector< svn::External > externals = m_client.ParseExternalsDescription( description );
m_luaState.newtable();
int tableIndex = 1;
for ( std::vector< svn::External >::iterator external = externals.begin(), end = externals.end(); external != end; ++external )
{
m_luaState.push( tableIndex++ );
m_luaState.newtable();
m_luaState.push( external->m_targetDir );
m_luaState.setfield( "targetDir" );
m_luaState.push( external->m_url );
m_luaState.setfield( "url" );
if ( external->m_revision.Kind() != svn_opt_revision_head )
{
BindRevision::Push( m_luaState, external->m_revision );
m_luaState.setfield( "revision" );
}
if ( external->m_pegRevision.Kind() != svn_opt_revision_head )
{
BindRevision::Push( m_luaState, external->m_pegRevision );
m_luaState.setfield( "peg" );
}
m_luaState.settable();
}
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in ParseExternalsDescription()" );
}
return 1;
}
int SubLua::GetUsername( lua_State* luaState )
{
lua::state lState( luaState );
// Check for correct parameter ammount.
if( !lState.isnoneornil( 2 ) )
{
lState.error( "SubLua:GetUsername() - Too many parameters specified. None should be specified." );
}
try
{
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the username on the stack.
lState.getfield( "username" );
}
catch( std::exception& ex )
{
lState.error( ex.what() );
}
catch( ... )
{
lState.error( "Critical error occured in GetUsername()" );
}
return 1;
}
int SubLua::GetPassword( lua_State* luaState )
{
lua::state lState( luaState );
// Check for correct parameter ammount.
if( !lState.isnoneornil( 2 ) )
{
lState.error( "SubLua:GetPassword() - Too many parameters specified. None should be specified." );
}
try
{
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the username on the stack.
lState.getfield( "password" );
}
catch( std::exception& ex )
{
lState.error( ex.what() );
}
catch( ... )
{
lState.error( "Critical error occured in GetPassword()" );
}
return 1;
}
int SubLua::GetContextListener( lua_State* luaState )
{
lua::state lState( luaState );
// Check for correct parameter ammount.
if( !lState.isnoneornil( 2 ) )
{
lState.error( "SubLua:GetContextListener() - Too many parameters specified. None should be specified." );
}
try
{
// Get the context options.
lState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the username on the stack.
lState.getfield( "listener" );
}
catch( std::exception& ex )
{
lState.error( ex.what() );
}
catch( ... )
{
lState.error( "Critical error occured in GetListener()" );
}
return 1;
}
std::string SubLua::GetContextUsername()
{
std::string user;
try
{
// Get the context options.
m_luaState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the username on the stack.
m_luaState.getfield( "username" );
user = m_luaState.as( std::string() );
// Clean up the stack.
m_luaState.pop( 2 );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in GetContextUsername()." );
}
return user;
}
std::string SubLua::GetContextPassword()
{
std::string user;
try
{
// Get the context options.
m_luaState.rawgeti( m_contextOptionReference, LUA_REGISTRYINDEX );
// Place the username on the stack.
m_luaState.getfield( "password" );
user = m_luaState.as( std::string() );
// Clean up the stack.
m_luaState.pop( 2 );
}
catch( std::exception& ex )
{
m_luaState.error( ex.what() );
}
catch( ... )
{
m_luaState.error( "Critical error occured in GetContextPassword()." );
}
return user;
}
extern "C" int luaopen_SubLua( lua_State* luaState )
{
lua::state lState( luaState );
// Register the class.
Lunax< SubLua >::Register( luaState );
// Clean the stack from Lunax registration, so its empty
lState.pop( lState.size() );
// Create the table to hold the class and static functions.
lState.newtable();
// Get the global constructor Lunax set.
lState.getglobal( SubLua::className );
// Add the 'new()' method that allows our class to be instanciated.
lState.setfield( "new" ); // key
// BuildNumber
lState.push( svn::Version::SubLuaBuildNumber() ); // value
lState.setfield( "buildNumber" ); // key
// Static helper introspective command.
lState.push( svn::Version::SubLua() ); // value
lState.setfield( "version" ); // key
// Add the enumerations to the SubLua static portion.
SubLua::BindSvnEnums( lState );
// Leave the table on the stack so that the users can save it away. Not polluting the global namespace
return 1;
}