Py::Object pysvn_client::cmd_status( const Py::Tuple &a_args, const Py::Dict &a_kws ) { static argument_description args_desc[] = { { true, name_path }, { false, name_recurse }, { false, name_get_all }, { false, name_update }, { false, name_ignore }, #if defined( PYSVN_HAS_CLIENT_STATUS2 ) { false, name_ignore_externals }, #endif #if defined( PYSVN_HAS_CLIENT_STATUS3 ) { false, name_depth }, { false, name_changelists }, #endif { false, NULL } }; FunctionArguments args( "status", args_desc, a_args, a_kws ); args.check(); Py::String path( args.getUtf8String( name_path ) ); SvnPool pool( m_context ); #if defined( PYSVN_HAS_CLIENT_STATUS3 ) apr_array_header_t *changelists = NULL; if( args.hasArg( name_changelists ) ) { changelists = arrayOfStringsFromListOfStrings( args.getArg( name_changelists ), pool ); } svn_depth_t depth = args.getDepth( name_depth, name_recurse, svn_depth_infinity, svn_depth_infinity, svn_depth_immediates ); #else bool recurse = args.getBoolean( name_recurse, true ); #endif bool get_all = args.getBoolean( name_get_all, true ); bool update = args.getBoolean( name_update, false ); bool ignore = args.getBoolean( name_ignore, false ); #if defined( PYSVN_HAS_CLIENT_STATUS2 ) bool ignore_externals = args.getBoolean( name_ignore_externals, false ); #endif apr_hash_t *status_hash = NULL; Py::List entries_list; try { std::string norm_path( svnNormalisedIfPath( path, pool ) ); checkThreadPermission(); PythonAllowThreads permission( m_context ); svn_revnum_t revnum; svn_opt_revision_t rev = { svn_opt_revision_head, {0} }; StatusEntriesBaton baton; status_hash = apr_hash_make( pool ); baton.hash = status_hash; baton.pool = pool; #if defined( PYSVN_HAS_CLIENT_STATUS4 ) svn_error_t *error = svn_client_status4 ( &revnum, // revnum norm_path.c_str(), // path &rev, StatusEntriesFunc, // status func &baton, // status baton depth, get_all, update, !ignore, ignore_externals, changelists, m_context, pool ); #elif defined( PYSVN_HAS_CLIENT_STATUS3 ) svn_error_t *error = svn_client_status3 ( &revnum, // revnum norm_path.c_str(), // path &rev, StatusEntriesFunc, // status func &baton, // status baton depth, get_all, update, !ignore, ignore_externals, changelists, m_context, pool ); #elif defined( PYSVN_HAS_CLIENT_STATUS2 ) svn_error_t *error = svn_client_status2 ( &revnum, // revnum norm_path.c_str(), // path &rev, StatusEntriesFunc, // status func &baton, // status baton recurse, get_all, update, !ignore, ignore_externals, m_context, pool ); #else svn_error_t *error = svn_client_status ( &revnum, // revnum norm_path.c_str(), // path &rev, StatusEntriesFunc, // status func &baton, // status baton recurse, get_all, update, !ignore, m_context, pool ); #endif permission.allowThisThread(); if( error != NULL ) 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 *statusarray = svn_sort__hash( status_hash, svn_sort_compare_items_as_paths, pool ); // Loop over array, printing each name/status-structure for (int i = statusarray->nelts-1; i >= 0; i--) { const svn_sort__item_t *item = &APR_ARRAY_IDX( statusarray, i, const svn_sort__item_t ); pysvn_wc_status_t *status = (pysvn_wc_status_t *)item->value; entries_list.append( toObject( Py::String( osNormalisedPath( (const char *)item->key, pool ), "UTF-8" ), *status, pool, m_wrapper_status, m_wrapper_entry, m_wrapper_lock ) ); } return entries_list; }
/* This implements the `svn_opt_subcommand_t' interface. */ svn_error_t * svn_cl__status(apr_getopt_t *os, void *baton, apr_pool_t *pool) { svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; apr_array_header_t *targets; apr_pool_t *subpool; apr_hash_t *master_cl_hash = apr_hash_make(pool); int i; svn_opt_revision_t rev; struct status_baton sb; SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, opt_state->targets, pool)); /* Add "." if user passed 0 arguments */ svn_opt_push_implicit_dot_target(targets, pool); /* We want our -u statuses to be against HEAD. */ rev.kind = svn_opt_revision_head; /* The notification callback, leave the notifier as NULL in XML mode */ if (! opt_state->xml) svn_cl__get_notifier(&ctx->notify_func2, &ctx->notify_baton2, FALSE, FALSE, FALSE, pool); subpool = svn_pool_create(pool); sb.had_print_error = FALSE; if (opt_state->xml) { /* If output is not incremental, output the XML header and wrap everything in a top-level element. This makes the output in its entirety a well-formed XML document. */ if (! opt_state->incremental) SVN_ERR(svn_cl__xml_print_header("status", pool)); } else { if (opt_state->incremental) return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("'incremental' option only valid in XML " "mode")); } sb.detailed = (opt_state->verbose || opt_state->update); sb.show_last_committed = opt_state->verbose; sb.skip_unrecognized = opt_state->quiet; sb.repos_locks = opt_state->update; sb.xml_mode = opt_state->xml; sb.pool = subpool; sb.cached_changelists = master_cl_hash; sb.cl_pool = pool; for (i = 0; i < targets->nelts; i++) { const char *target = APR_ARRAY_IDX(targets, i, const char *); svn_revnum_t repos_rev = SVN_INVALID_REVNUM; svn_pool_clear(subpool); SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton)); if (opt_state->xml) SVN_ERR(print_start_target_xml(svn_path_local_style(target, subpool), subpool)); /* Retrieve a hash of status structures with the information requested by the user. */ SVN_ERR(svn_cl__try(svn_client_status3(&repos_rev, target, &rev, print_status, &sb, opt_state->depth, opt_state->verbose, opt_state->update, opt_state->no_ignore, opt_state->ignore_externals, opt_state->changelists, ctx, subpool), NULL, opt_state->quiet, /* not versioned: */ SVN_ERR_WC_NOT_DIRECTORY, SVN_NO_ERROR)); if (opt_state->xml) SVN_ERR(print_finish_target_xml(repos_rev, subpool)); } /* If any paths were cached because they were associatied with changelists, we can now display them as grouped changelists. */ if (apr_hash_count(master_cl_hash) > 0) { apr_hash_index_t *hi; svn_stringbuf_t *buf; if (opt_state->xml) buf = svn_stringbuf_create("", pool); for (hi = apr_hash_first(pool, master_cl_hash); hi; hi = apr_hash_next(hi)) { const char *changelist_name; apr_array_header_t *path_array; const void *key; void *val; int j; apr_hash_this(hi, &key, NULL, &val); changelist_name = key; path_array = val; /* ### TODO: For non-XML output, we shouldn't print the ### leading \n on the first changelist if there were no ### non-changelist entries. */ if (opt_state->xml) { svn_stringbuf_set(buf, ""); svn_xml_make_open_tag(&buf, pool, svn_xml_normal, "changelist", "name", changelist_name, NULL); SVN_ERR(svn_cl__error_checked_fputs(buf->data, stdout)); } else SVN_ERR(svn_cmdline_printf(pool, _("\n--- Changelist '%s':\n"), changelist_name)); for (j = 0; j < path_array->nelts; j++) { struct status_cache *scache = APR_ARRAY_IDX(path_array, j, struct status_cache *); print_status_normal_or_xml(&sb, scache->path, scache->status); } if (opt_state->xml) { svn_stringbuf_set(buf, ""); svn_xml_make_close_tag(&buf, pool, "changelist"); SVN_ERR(svn_cl__error_checked_fputs(buf->data, stdout)); } } }