1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
|
//
// ====================================================================
// Copyright (c) 2003-2006 Barry A Scott. All rights reserved.
//
// This software is licensed as described in the file LICENSE.txt,
// which you should have received as part of this distribution.
//
// ====================================================================
//
//
// pysvn.cpp
//
#ifdef _MSC_VER
// disable warning C4786: symbol greater than 255 character,
// nessesary to ignore as <map> causes lots of warning
#pragma warning(disable: 4786)
#endif
#include "pysvn.hpp"
#include "pysvn_docs.hpp"
#include "pysvn_version.hpp"
#include "svn_version.h"
pysvn_module::pysvn_module()
: Py::ExtensionModule<pysvn_module>( "pysvn" )
, client_error()
{
// init APR once globally - rather then on demand
// to avoid life time issues with pools
apr_initialize();
apr_pool_initialize();
client_error.init( *this, "ClientError" );
pysvn_client::init_type();
pysvn_transaction::init_type();
pysvn_revision::init_type();
pysvn_enum< svn_opt_revision_kind >::init_type();
pysvn_enum_value< svn_opt_revision_kind >::init_type();
pysvn_enum< svn_wc_notify_action_t >::init_type();
pysvn_enum_value< svn_wc_notify_action_t >::init_type();
pysvn_enum< svn_wc_status_kind >::init_type();
pysvn_enum_value< svn_wc_status_kind >::init_type();
pysvn_enum< svn_wc_schedule_t >::init_type();
pysvn_enum_value< svn_wc_schedule_t >::init_type();
pysvn_enum< svn_wc_merge_outcome_t >::init_type();
pysvn_enum_value< svn_wc_merge_outcome_t >::init_type();
pysvn_enum< svn_wc_notify_state_t >::init_type();
pysvn_enum_value< svn_wc_notify_state_t >::init_type();
pysvn_enum< svn_node_kind_t >::init_type();
pysvn_enum_value< svn_node_kind_t >::init_type();
#if defined( PYSVN_HAS_DIFF_FILE_IGNORE_SPACE )
pysvn_enum< svn_diff_file_ignore_space_t >::init_type();
pysvn_enum_value< svn_diff_file_ignore_space_t >::init_type();
#endif
#if defined( PYSVN_HAS_CLIENT_DIFF_SUMMARIZE )
pysvn_enum< svn_client_diff_summarize_kind_t >::init_type();
pysvn_enum_value< svn_client_diff_summarize_kind_t >::init_type();
#endif
add_keyword_method("_Client", &pysvn_module::new_client, pysvn_client_doc);
add_keyword_method("Revision", &pysvn_module::new_revision, pysvn_revision_doc);
add_keyword_method("_Transaction", &pysvn_module::new_transaction, pysvn_transaction_doc);
initialize( pysvn_module_doc );
Py::Dict d( moduleDictionary() );
d["ClientError"] = client_error;
d["copyright"] = Py::String( copyright_doc );
Py::Tuple version(4);
version[0] = Py::Int( version_major );
version[1] = Py::Int( version_minor );
version[2] = Py::Int( version_patch );
version[3] = Py::Int( version_build );
d["version"] = version;
Py::Tuple svn_api_version(4);
svn_api_version[0] = Py::Int( SVN_VER_MAJOR );
svn_api_version[1] = Py::Int( SVN_VER_MINOR );
svn_api_version[2] = Py::Int( SVN_VER_MICRO );
svn_api_version[3] = Py::String( SVN_VER_TAG );
#ifdef PYSVN_HAS_CLIENT_VERSION
const svn_version_t *client_version = svn_client_version();
Py::Tuple svn_version(4);
svn_version[0] = Py::Int( client_version->major );
svn_version[1] = Py::Int( client_version->minor );
svn_version[2] = Py::Int( client_version->patch );
svn_version[3] = Py::String( client_version->tag );
d["svn_version"] = svn_version;
d["svn_api_version"] = svn_api_version;
#else
d["svn_version"] = svn_api_version;
d["svn_api_version"] = svn_api_version;
#endif
d["opt_revision_kind"] = Py::asObject( new pysvn_enum< svn_opt_revision_kind >() );
d["wc_notify_action"] = Py::asObject( new pysvn_enum< svn_wc_notify_action_t >() );
d["wc_status_kind"] = Py::asObject( new pysvn_enum< svn_wc_status_kind >() );
d["wc_schedule"] = Py::asObject( new pysvn_enum< svn_wc_schedule_t >() );
d["wc_merge_outcome"] = Py::asObject( new pysvn_enum< svn_wc_merge_outcome_t >() );
d["wc_notify_state"] = Py::asObject( new pysvn_enum< svn_wc_notify_state_t >() );
d["node_kind"] = Py::asObject( new pysvn_enum< svn_node_kind_t >() );
#if defined( PYSVN_HAS_CLIENT_DIFF_SUMMARIZE )
d["diff_summarize_kind"] = Py::asObject( new pysvn_enum< svn_client_diff_summarize_kind_t >() );
#endif
}
pysvn_module::~pysvn_module()
{
}
static const char name_config_dir[] = "config_dir";
static const char name_result_wrappers[] = "result_wrappers";
Py::Object pysvn_module::new_client( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
static argument_description args_desc[] =
{
{ false, name_config_dir },
{ false, name_result_wrappers },
{ false, NULL }
};
FunctionArguments args( "Client", args_desc, a_args, a_kws );
args.check();
std::string config_dir = args.getUtf8String( name_config_dir, "" );
Py::Dict result_wrappers_dict;
if( args.hasArg( name_result_wrappers ) )
result_wrappers_dict = args.getArg( name_result_wrappers );
return Py::asObject( new pysvn_client( *this, config_dir, result_wrappers_dict ) );
}
static const char name_repos_path[] = "repos_path";
static const char name_transaction_name[] = "transaction_name";
Py::Object pysvn_module::new_transaction( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
static argument_description args_desc[] =
{
{ true, name_repos_path },
{ true, name_transaction_name },
{ false, name_result_wrappers },
{ false, NULL }
};
FunctionArguments args( "Transaction", args_desc, a_args, a_kws );
args.check();
std::string repos_path = args.getUtf8String( name_repos_path );
std::string transaction_name = args.getUtf8String( name_transaction_name );
Py::Dict result_wrappers_dict;
if( args.hasArg( name_result_wrappers ) )
result_wrappers_dict = args.getArg( name_result_wrappers );
pysvn_transaction *t = new pysvn_transaction( *this, result_wrappers_dict );
Py::Object result( Py::asObject( t ) );
t->init( repos_path, transaction_name );
return result;
}
static const char name_kind[] = "kind";
static const char name_number[] = "number";
static const char name_date[] = "date";
Py::Object pysvn_module::new_revision( const Py::Tuple &a_args, const Py::Dict &a_kws )
{
//
// support only one of the following:
// revision( kind )
// revision( kind, number )
// revision( kind, date )
//
static argument_description args_desc[] =
{
{ true, name_kind },
{ false, name_date },
{ false, name_number },
{ false, NULL }
};
FunctionArguments args( "Revision", args_desc, a_args, a_kws );
args.check();
Py::ExtensionObject< pysvn_enum_value<svn_opt_revision_kind> > py_kind( args.getArg( name_kind ) );
svn_opt_revision_kind kind = svn_opt_revision_kind( py_kind.extensionObject()->m_value );
pysvn_revision *rev = NULL;
switch( kind )
{
case svn_opt_revision_date:
{
static argument_description args_desc[] =
{
{ true, name_kind },
{ true, name_date },
{ false, NULL }
};
FunctionArguments args( "Revision", args_desc, a_args, a_kws );
args.check();
Py::Float date( args.getArg( name_date ) );
rev = new pysvn_revision( kind, double(date) );
break;
}
case svn_opt_revision_number:
{
static argument_description args_desc[] =
{
{ true, name_kind },
{ true, name_number },
{ false, NULL }
};
FunctionArguments args( "Revision", args_desc, a_args, a_kws );
args.check();
Py::Int revnum( args.getArg( name_number ) );
rev = new pysvn_revision( kind, 0, long( revnum ) );
break;
}
default:
{
static argument_description args_desc[] =
{
{ true, name_kind },
{ false, NULL }
};
FunctionArguments args( "Revision", args_desc, a_args, a_kws );
args.check();
rev = new pysvn_revision( kind );
}
}
return Py::asObject( rev );
}
//--------------------------------------------------------------------------------
//
// PythonAllowThreads provides a exception safe
// wrapper for the C idiom:
//
// Py_BEGIN_ALLOW_THREADS
// ...Do some blocking I/O operation...
// Py_END_ALLOW_THREADS
//
// IN C++ use PythonAllowThreads in main code:
//{
// PythonAllowThreads main_permission;
// ...Do some blocking I/O operation that may throw
//} // allow d'tor grabs the lock
//
// In C++ use PythonDisallowTheads in callback code:
//{
// PythonDisallowTheads permission( main_permission );
// ... Python operations that may throw
//} // allow d'tor to release the lock
//
//--------------------------------------------------------------------------------
PythonAllowThreads::PythonAllowThreads( pysvn_context &_callbacks )
: m_callbacks( _callbacks )
, m_save( NULL )
{
m_callbacks.setPermission( *this );
allowOtherThreads();
}
PythonAllowThreads::~PythonAllowThreads()
{
if( m_save != NULL )
allowThisThread();
m_callbacks.clearPermission();
}
void PythonAllowThreads::allowOtherThreads()
{
#if defined( WITH_THREAD )
assert( m_save == NULL );
m_save = PyEval_SaveThread();
assert( m_save != NULL );
#endif
}
void PythonAllowThreads::allowThisThread()
{
#if defined( WITH_THREAD )
assert( m_save != NULL );
PyEval_RestoreThread( m_save );
m_save = NULL;
#endif
}
PythonDisallowThreads::PythonDisallowThreads( PythonAllowThreads *_permission )
: m_permission( _permission )
{
m_permission->allowThisThread();
}
PythonDisallowThreads::~PythonDisallowThreads()
{
m_permission->allowOtherThreads();
}
//--------------------------------------------------------------------------------
static pysvn_module* the_pysvn_module = NULL;
extern "C" void init_pysvn()
{
the_pysvn_module = new pysvn_module;
}
// symbol required for the debug version
extern "C" void init_pysvn_d()
{
init_pysvn();
}
|