void pysvn_context::contextNotify2 ( const svn_wc_notify_t *notify, apr_pool_t *pool ) { PythonDisallowThreads callback_permission( m_permission ); // make sure we can call the users object if( !m_pyfn_Notify.isCallable() ) return; Py::Callable callback( m_pyfn_Notify ); Py::Tuple args( 1 ); Py::Dict info; args[0] = info; info["path"] = Py::String( notify->path ); info["action"] = toEnumValue( notify->action ); info["kind"] = toEnumValue( notify->kind ); if( notify->mime_type == NULL ) info["mime_type"] = Py::Nothing(); else info["mime_type"] = Py::String( notify->mime_type ); info["content_state"] = toEnumValue( notify->content_state ); info["prop_state"] = toEnumValue( notify->prop_state ); info["revision"] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, notify->revision ) ); if( notify->err != NULL ) { SvnException error( notify->err ); info["error"] = error.pythonExceptionArg( 1 ); } else { info["error"] = Py::None(); } Py::Object results; try { results = callback.apply( args ); } catch( Py::Exception &e ) { PyErr_Print(); e.clear(); m_error_message = "unhandled exception in callback_notify"; } }
void pysvn_context::contextNotify ( const char *path, svn_wc_notify_action_t action, svn_node_kind_t kind, const char *mime_type, svn_wc_notify_state_t content_state, svn_wc_notify_state_t prop_state, svn_revnum_t revnum ) { PythonDisallowThreads callback_permission( m_permission ); // make sure we can call the users object if( !m_pyfn_Notify.isCallable() ) return; Py::Callable callback( m_pyfn_Notify ); Py::Tuple args( 1 ); Py::Dict info; args[0] = info; info["path"] = Py::String( path ); info["action"] = toEnumValue( action ); info["kind"] = toEnumValue( kind ); if( mime_type == NULL ) info["mime_type"] = Py::Nothing(); else info["mime_type"] = Py::String( mime_type ); info["content_state"] = toEnumValue( content_state ); info["prop_state"] = toEnumValue( prop_state ); info["revision"] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, revnum ) ); Py::Object results; try { results = callback.apply( args ); } catch( Py::Exception &e ) { PyErr_Print(); e.clear(); m_error_message = "unhandled exception in callback_notify"; } }
Py::Object toObject ( Py::String path, pysvn_wc_status_t &svn_status, SvnPool &pool, const DictWrapper &wrapper_status, const DictWrapper &wrapper_entry, const DictWrapper &wrapper_lock ) { Py::Dict status; status[ str_path ] = path; if( svn_status.entry == NULL ) { status[ str_entry ] = Py::None(); } else { status[ str_entry ] = toObject( *svn_status.entry, pool, wrapper_entry ); } if( svn_status.repos_lock == NULL ) { status[ str_repos_lock ] = Py::None(); } #if defined( PYSVN_HAS_CLIENT_STATUS2 ) else { status[ str_repos_lock ] = toObject( *svn_status.repos_lock, wrapper_lock ); } #endif long is_versioned = (long)(svn_status.text_status > svn_wc_status_unversioned); status[ str_is_versioned ] = Py::Int( is_versioned ); status[ str_is_locked ] = Py::Int( svn_status.locked ); status[ str_is_copied ] = Py::Int( svn_status.copied ); status[ str_is_switched ] = Py::Int( svn_status.switched ); status[ str_prop_status ] = toEnumValue( svn_status.prop_status ); status[ str_text_status ] = toEnumValue( svn_status.text_status ); status[ str_repos_prop_status ] = toEnumValue( svn_status.repos_prop_status ); status[ str_repos_text_status ] = toEnumValue( svn_status.repos_text_status ); return wrapper_status.wrapDict( status ); }
Py::Object toObject ( const svn_wc_entry_t &svn_entry, SvnPool &pool, const DictWrapper &wrapper_entry ) { Py::Dict entry; entry[ str_checksum ] = utf8_string_or_none( svn_entry.checksum ); entry[ str_commit_author ] = utf8_string_or_none( svn_entry.cmt_author ); entry[ str_commit_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.cmt_rev ) ); entry[ str_commit_time ] = toObject( svn_entry.cmt_date ); entry[ str_conflict_new ] = path_string_or_none( svn_entry.conflict_new, pool ); entry[ str_conflict_old ] = path_string_or_none( svn_entry.conflict_old, pool ); entry[ str_conflict_work ] = path_string_or_none( svn_entry.conflict_wrk, pool ); entry[ str_copy_from_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.copyfrom_rev ) ); entry[ str_copy_from_url ] = utf8_string_or_none( svn_entry.copyfrom_url ); entry[ str_is_absent ] = Py::Int( svn_entry.absent ); entry[ str_is_copied ] = Py::Int( svn_entry.copied ); entry[ str_is_deleted ] = Py::Int( svn_entry.deleted ); entry[ str_kind ] = toEnumValue( svn_entry.kind ); entry[ str_name ] = path_string_or_none( svn_entry.name, pool ); entry[ str_properties_time ] = toObject( svn_entry.prop_time ); entry[ str_property_reject_file ] = path_string_or_none( svn_entry.prejfile, pool ); entry[ str_repos ] = utf8_string_or_none( svn_entry.repos ); entry[ str_revision ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, svn_entry.revision ) ); entry[ str_schedule ] = toEnumValue( svn_entry.schedule ); entry[ str_text_time ] = toObject( svn_entry.text_time ); entry[ str_url ] = utf8_string_or_none( svn_entry.url ); entry[ str_uuid ] = utf8_string_or_none( svn_entry.uuid ); #if defined( PYSVN_HAS_CLIENT_STATUS2 ) entry[ str_lock_token ] = utf8_string_or_none( svn_entry.lock_token ); entry[ str_lock_owner ] = utf8_string_or_none( svn_entry.lock_owner ); entry[ str_lock_comment ] = utf8_string_or_none( svn_entry.lock_comment ); entry[ str_lock_creation_date ] = toObject( svn_entry.lock_creation_date ); #endif return wrapper_entry.wrapDict( entry ); }
svn_error_t *diff_summarize_c ( const svn_client_diff_summarize_t *diff, void *baton_, apr_pool_t *pool ) { DiffSummarizeBaton *baton = reinterpret_cast<DiffSummarizeBaton *>( baton_ ); PythonDisallowThreads callback_permission( baton->m_permission ); Py::Dict diff_dict; diff_dict[ *py_name_path ] = Py::String( diff->path, name_utf8 ); diff_dict[ *py_name_summarize_kind ] = toEnumValue( diff->summarize_kind ); diff_dict[ *py_name_prop_changed ] = Py::Int( diff->prop_changed != 0 ); diff_dict[ *py_name_node_kind ] = toEnumValue( diff->node_kind ); baton->m_diff_list.append( baton->m_wrapper_diff_summary->wrapDict( diff_dict ) ); return SVN_NO_ERROR; }
Py::Object direntsToObject( apr_hash_t *dirents, SvnPool &pool ) { Py::Dict py_dirents_dict; for( apr_hash_index_t *hi = apr_hash_first( pool, dirents ); hi; hi = apr_hash_next( hi ) ) { const void *key = NULL; void *val = NULL; apr_hash_this (hi, &key, NULL, &val); const svn_fs_dirent_t *dirent = (const svn_fs_dirent_t *)val; py_dirents_dict[ Py::String( (const char *)key ) ] = toEnumValue( dirent->kind ); } return py_dirents_dict; }
Py::Object pysvn_client::cmd_ls( const Py::Tuple &a_args, const Py::Dict &a_kws ) { static argument_description args_desc[] = { { true, name_url_or_path }, { false, name_revision }, { false, name_recurse }, #if defined( PYSVN_HAS_CLIENT_LS2 ) { false, name_peg_revision }, #endif { false, NULL } }; FunctionArguments args( "ls", args_desc, a_args, a_kws ); args.check(); std::string path( args.getUtf8String( name_url_or_path ) ); bool recurse = args.getBoolean( name_recurse, false ); svn_opt_revision_t revision = args.getRevision( name_revision, svn_opt_revision_head ); SvnPool pool( m_context ); apr_hash_t *hash = NULL; std::string norm_path( svnNormalisedIfPath( path, pool ) ); #if defined( PYSVN_HAS_CLIENT_LS2 ) svn_opt_revision_t peg_revision = args.getRevision( name_peg_revision, revision ); #endif bool is_url = is_svn_url( path ); #if defined( PYSVN_HAS_CLIENT_LS2 ) revisionKindCompatibleCheck( is_url, peg_revision, name_peg_revision, name_url_or_path ); #endif revisionKindCompatibleCheck( is_url, revision, name_revision, name_url_or_path ); try { checkThreadPermission(); PythonAllowThreads permission( m_context ); #if defined( PYSVN_HAS_CLIENT_LS2 ) svn_error_t *error = svn_client_ls2 ( &hash, norm_path.c_str(), &peg_revision, &revision, recurse, m_context, pool ); #else svn_error_t *error = svn_client_ls ( &hash, norm_path.c_str(), &revision, recurse, m_context, pool ); #endif permission.allowThisThread(); if( error != 0 ) throw SvnException( error ); } catch( SvnException &e ) { // use callback error over ClientException m_context.checkForError( m_module.client_error ); throw_client_error( e ); } apr_array_header_t *array = svn_sort__hash( hash, compare_items_as_paths, pool ); std::string base_path; if( !norm_path.empty() ) { base_path = norm_path; base_path += '/'; } // convert the entries into python objects Py::List entries_list; for( int i = 0; i < array->nelts; ++i ) { svn_sort__item_t *item = &APR_ARRAY_IDX( array, i, svn_sort__item_t ); const char *utf8_entryname = static_cast<const char *>( item->key ); svn_dirent_t *dirent = static_cast<svn_dirent_t *>( apr_hash_get( hash, utf8_entryname, item->klen ) ); std::string full_name( base_path ); full_name += utf8_entryname; Py::Dict entry_dict; entry_dict[ *py_name_name ] = Py::String( full_name, name_utf8 ); entry_dict[ *py_name_kind ] = toEnumValue( dirent->kind ); entry_dict[ *py_name_has_props ] = Py::Int( dirent->has_props ); entry_dict[ *py_name_size ] = Py::Long( Py::Float( double( static_cast<signed_int64>( dirent->size ) ) ) ); entry_dict[ *py_name_created_rev ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, dirent->created_rev ) ); entry_dict[ *py_name_time ] = toObject( dirent->time ); entry_dict[ *py_name_last_author ] = utf8_string_or_none( dirent->last_author ); entries_list.append( m_wrapper_dirent.wrapDict( entry_dict ) ); } return entries_list; }
svn_error_t *list_receiver_c ( void *baton_, const char *path, const svn_dirent_t *dirent, const svn_lock_t *lock, const char *abs_path, apr_pool_t *pool ) { ListReceiveBaton *baton = reinterpret_cast<ListReceiveBaton *>( baton_ ); PythonDisallowThreads callback_permission( baton->m_permission ); std::string full_path( baton->m_url_or_path ); std::string full_repos_path( abs_path ); if( strlen( path ) != 0 ) { full_path += "/"; full_path += path; full_repos_path += "/"; full_repos_path += path; } Py::Tuple py_tuple( 2 ); Py::Dict entry_dict; entry_dict[ *py_name_path ] = Py::String( full_path, name_utf8 ); entry_dict[ *py_name_repos_path ] = Py::String( full_repos_path, name_utf8 ); if( dirent != NULL ) { if( baton->m_dirent_fields&SVN_DIRENT_KIND ) { entry_dict[ *py_name_kind ] = toEnumValue( dirent->kind ); } if( baton->m_dirent_fields&SVN_DIRENT_SIZE ) { entry_dict[ *py_name_size ] = Py::Long( Py::Float( double( static_cast<signed_int64>( dirent->size ) ) ) ); } if( baton->m_dirent_fields&SVN_DIRENT_CREATED_REV ) { entry_dict[ *py_name_created_rev ] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, dirent->created_rev ) ); } if( baton->m_dirent_fields&SVN_DIRENT_TIME ) { entry_dict[ *py_name_time ] = toObject( dirent->time ); } if( baton->m_dirent_fields&SVN_DIRENT_HAS_PROPS ) { entry_dict[ *py_name_has_props ] = Py::Int( dirent->has_props ); } if( baton->m_dirent_fields&SVN_DIRENT_LAST_AUTHOR ) { entry_dict[ *py_name_last_author ] = utf8_string_or_none( dirent->last_author ); } } py_tuple[0] = baton->m_wrapper_list->wrapDict( entry_dict ); if( lock == NULL ) { py_tuple[1] = Py::None(); } else { py_tuple[1] = toObject( *lock, *baton->m_wrapper_lock ); } baton->m_list_list.append( py_tuple ); return SVN_NO_ERROR; }
Py::Object toObject ( const svn_info_t &info, const DictWrapper &wrapper_info, const DictWrapper &wrapper_lock, const DictWrapper &wrapper_wc_info ) { Py::Dict py_info; // Where the item lives in the repository. py_info[str_URL] = utf8_string_or_none( info.URL ); // The revision of the object. If path_or_url is a working-copy // path, then this is its current working revnum. If path_or_url // is a URL, then this is the repos revision that path_or_url lives in. py_info[str_rev] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, info.rev ) ); // The node's kind. py_info[str_kind] = toEnumValue( info.kind ); // The root URL of the repository. py_info[str_repos_root_URL] = utf8_string_or_none( info.repos_root_URL ); // The repository's UUID. py_info[str_repos_UUID] = utf8_string_or_none( info.repos_UUID ); // The last revision in which this object changed. py_info[str_last_changed_rev] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, info.last_changed_rev ) ); // The date of the last_changed_rev. py_info[str_last_changed_date] = toObject( info.last_changed_date ); // The author of the last_changed_rev. py_info[str_last_changed_author] = utf8_string_or_none( info.last_changed_author ); #if defined( PYSVN_HAS_CLIENT_LOCK ) // An exclusive lock, if present. Could be either local or remote. if( info.lock == NULL ) { py_info[str_lock] = Py::None(); } else { py_info[str_lock] = toObject( *info.lock, wrapper_lock ); } #endif // Whether or not to ignore the next 10 wc-specific fields. if( info.has_wc_info == 0 ) { py_info[str_wc_info] = Py::None(); } else { Py::Dict py_wc_info; py_wc_info[str_schedule] = toEnumValue( info.schedule ); py_wc_info[str_copyfrom_url] = utf8_string_or_none( info.copyfrom_url ); py_wc_info[str_copyfrom_rev] = Py::asObject( new pysvn_revision( svn_opt_revision_number, 0, info.copyfrom_rev ) ); py_wc_info[str_text_time] = toObject( info.text_time ); py_wc_info[str_prop_time] = toObject( info.prop_time ); py_wc_info[str_checksum] = utf8_string_or_none( info.checksum ); py_wc_info[str_conflict_old] = utf8_string_or_none( info.conflict_old ); py_wc_info[str_conflict_new] = utf8_string_or_none( info.conflict_new ); py_wc_info[str_conflict_work] = utf8_string_or_none( info.conflict_wrk ); py_wc_info[str_prejfile] = utf8_string_or_none( info.prejfile ); #ifdef PYSVN_HAS_SVN_INFO_T__CHANGELIST py_wc_info[str_changelist] = utf8_string_or_none( info.changelist ); py_wc_info[str_depth] = toEnumValue( info.depth ); #endif #ifdef PYSVN_HAS_SVN_INFO_T__SIZES #ifdef HAVE_LONG_LONG if( info.working_size == SVN_INFO_SIZE_UNKNOWN ) py_wc_info[str_working_size] = Py::None(); else py_wc_info[str_working_size] = Py::LongLong( static_cast<PY_LONG_LONG>( info.working_size ) ); if( info.size == SVN_INFO_SIZE_UNKNOWN ) py_wc_info[str_size] = Py::None(); else py_wc_info[str_size] = Py::LongLong( static_cast<PY_LONG_LONG>( info.size ) ); #else if( info.working_size == SVN_INFO_SIZE_UNKNOWN ) py_wc_info[str_working_size] = Py::None(); else py_wc_info[str_working_size] = Py::Int( static_cast<int>( info.working_size ) ); if( info.size == SVN_INFO_SIZE_UNKNOWN ) py_wc_info[str_size] = Py::None(); else py_wc_info[str_size] = Py::Int( static_cast<int>( info.size ) ); #endif #endif py_info[str_wc_info] = wrapper_wc_info.wrapDict( py_wc_info ); } return wrapper_info.wrapDict( py_info ); }