SvnClientImpl::SvnClientImpl() : _isActive(true) { // Initialize the app. Send all error messages to nothing if (svn_cmdline_init("minimal_client", NULL) != EXIT_SUCCESS) { throw std::runtime_error("Could not initialise SVN commandline."); } // Create our main pool _pool = svn_pool_create(NULL); /* Initialize the FS library. */ svn_error_t* err = svn_fs_initialize(_pool); if (err) { throw std::runtime_error("Could not initialise SVN filesystem library."); } /* Make sure the ~/.subversion run-time config files exist */ err = svn_config_ensure(NULL, _pool); if (err) { throw std::runtime_error("Could not initialise SVN configuration."); } // Initialize and allocate the client_ctx object. if ((err = svn_client_create_context(&_context, _pool))) { throw std::runtime_error("Could not create SVN context."); } // Load the run-time config file into a hash if ((err = svn_config_get_config (&(_context->config), NULL, _pool))) { throw std::runtime_error("Could not load SVN config."); } #ifdef WIN32 // Set the working copy administrative directory name. if (getenv("SVN_ASP_DOT_NET_HACK")) { err = svn_wc_set_adm_dir("_svn", _pool); if (err) { throw std::runtime_error("Could not set SVN admin directory."); } } #endif }
JNIEXPORT void JNICALL Java_Subversion_openSession(JNIEnv * env, jobject obj, jstring repoURL) { svn_error_t * err; const char * repoURLC = (*env)->GetStringUTFChars(env, repoURL, 0); apr_initialize(); pool = svn_pool_create(0); if (!pool) abort(); err = svn_config_ensure(0, pool); if (err) barf(err); apr_hash_t * config; err = svn_config_get_config(&config, 0, pool); if (err) barf(err); /* Set up authentication info from the config files (copied from subversion/clients/cmdline/main.c). */ apr_array_header_t * providers = apr_array_make(pool, 10, sizeof (svn_auth_provider_object_t *)); svn_auth_provider_object_t * provider; svn_client_get_simple_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_server_trust_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_client_cert_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; svn_client_get_ssl_client_cert_pw_file_provider(&provider, pool); APR_ARRAY_PUSH(providers, svn_auth_provider_object_t *) = provider; /* Get the plugin that handles the protocol for `repoURL'. */ err = svn_ra_init_ra_libs(&ra_baton, pool); if (err) barf(err); err = svn_ra_get_ra_library(&ra_lib, ra_baton, repoURLC, pool); if (err) barf(err); memset(&callbacks, 0, sizeof callbacks); svn_auth_open(&callbacks.auth_baton, providers, pool); /* Open a session to `repoURL'. */ err = ra_lib->open(&ra_session, repoURLC, &callbacks, 0, config, pool); if (err) barf(err); (*env)->ReleaseStringUTFChars(env, repoURL, repoURLC); }
/* Initialize the RA layer, and set *CTX to a new client context baton * allocated from POOL. Use CONFIG_DIR and pass USERNAME, PASSWORD, * CONFIG_DIR and NO_AUTH_CACHE to initialize the authorization baton. * CONFIG_OPTIONS (if not NULL) is a list of configuration overrides. */ static svn_error_t * init_client_context(svn_client_ctx_t **ctx_p, svn_boolean_t non_interactive, const char *username, const char *password, const char *config_dir, svn_boolean_t no_auth_cache, svn_boolean_t trust_server_cert, apr_array_header_t *config_options, apr_pool_t *pool) { svn_client_ctx_t *ctx = NULL; svn_config_t *cfg_config; SVN_ERR(svn_ra_initialize(pool)); SVN_ERR(svn_config_ensure(config_dir, pool)); SVN_ERR(svn_client_create_context(&ctx, pool)); SVN_ERR(svn_config_get_config(&(ctx->config), config_dir, pool)); if (config_options) SVN_ERR(svn_cmdline__apply_config_options(ctx->config, config_options, "svnrdump: ", "--config-option")); cfg_config = apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING); /* Set up our cancellation support. */ ctx->cancel_func = check_cancel; /* Default authentication providers for non-interactive use */ SVN_ERR(svn_cmdline_create_auth_baton(&(ctx->auth_baton), non_interactive, username, password, config_dir, no_auth_cache, trust_server_cert, cfg_config, ctx->cancel_func, ctx->cancel_baton, pool)); *ctx_p = ctx; return SVN_NO_ERROR; }
/* fonction permettant d'initialiser le contexte avant toute opération svn */ svn_client_ctx_t *initialize_context(){ svn_error_t *err; svn_config_t *cfg; err = svn_config_ensure (NULL, pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "svn_support: "); return NULL; } // -- Creation du contexte -- svn_client_create_context(&ctx,pool); svn_config_get_config (&(ctx->config), NULL, pool); // -- Récupération du fichier de config dans ~/.subversion -- const char *config_path; svn_config_get_user_config_path(&config_path, NULL, SVN_CONFIG_CATEGORY_CONFIG, pool); svn_config_read(&cfg, config_path, TRUE, pool); // -- Initialisation des parametres d'authentification -- svn_cmdline_create_auth_baton(&ctx->auth_baton, TRUE, NULL, NULL, config_path, FALSE, FALSE, cfg, cancel, ctx->cancel_baton, pool); return ctx; }
/* Opens a session */ char session_open(session_t *session) { svn_error_t *err; svn_client_ctx_t *ctx; svn_config_t *config; svn_auth_baton_t *auth_baton; const char *root; const char *config_dir = NULL; /* Make sure the URL is properly encoded */ session->encoded_url = svn_path_uri_encode(svn_path_canonicalize(session->url, session->pool), session->pool); /* Do neccessary SVN library initialization */ if ((err = svn_fs_initialize(session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } if ((err = svn_ra_initialize(session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } if ((err = svn_config_ensure(NULL, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } /* Setup the client context */ if ((err = svn_client_create_context(&ctx, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } if ((err = svn_config_get_config(&(ctx->config), NULL, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } if (session->config_dir != NULL) { const char *path; if ((err = svn_utf_cstring_to_utf8(&path, session->config_dir, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } config_dir = svn_path_canonicalize(path, session->pool); } /* Setup auth baton */ config = apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING); if ((err = svn_cmdline_setup_auth_baton(&auth_baton, (session->flags & SF_NON_INTERACTIVE), session->username, session->password, config_dir, (session->flags & SF_NO_AUTH_CACHE), config, NULL, NULL, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } ctx->auth_baton = auth_baton; /* Setup the RA session */ if ((err = svn_client_open_ra_session(&(session->ra), session->encoded_url, ctx, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } /* Determine the root (and the prefix) of the URL */ if ((err = svn_ra_get_repos_root(session->ra, &root, session->pool))) { utils_handle_error(err, stderr, FALSE, "ERROR: "); svn_error_clear(err); return 1; } session->root = root; if (!strcmp(session->encoded_url, root)) { session->prefix = apr_pstrdup(session->pool, ""); } else { session->prefix = apr_pstrdup(session->pool, session->encoded_url + strlen(root) + 1); } session->prefix = session_obfuscate(session, session->pool, session->prefix); return 0; }
nsvn_t* nsvn_base_init (const char *config_dir) { nsvn_t *nsvn; /* Initializing apr module. */ if (nsvn_base__init_apr() == EXIT_FAILURE) return NULL; /* Allocating memory for NSVN internal data structure. */ nsvn = (nsvn_t*) calloc (1, sizeof(nsvn_t)); if (nsvn == NULL) return NULL; if (apr_allocator_create (&nsvn->allocator)) return nsvn_base_uninit(nsvn); apr_allocator_max_free_set (nsvn->allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE); nsvn->pool = svn_pool_create_ex (NULL, nsvn->allocator); apr_allocator_owner_set (nsvn->allocator, nsvn->pool); /* Initializing auth provider array. */ nsvn->auth_providers = NULL; /* Check svn library version, which are used here */ #ifdef NSVN_DEBUG //nsvn->err = nsvn_base__check_svnlib_ver(); //if (nsvn->err) // return nsvn_base_uninit (nsvn); #endif /* Initializing the SVN FS library. */ nsvn->err = svn_fs_initialize (nsvn->pool); if (nsvn->err) return nsvn_base_uninit (nsvn); /* TODO: Need to ignore SIGPIPE and hook SIGINT, SIGHUP, SIGTERM, and SIGUSR1 signals to a handler which will set a global volatile varaible to TRUE. So by looking at the variable we can decide to cancel a on going process. Also we need to write a exportable function which is same as the handler. */ /* TODO: Need to decide, whether to check config_dir is a valid subversion config directory or not, if check needed add it here. */ if (config_dir) { nsvn->config_dir = strdup (config_dir); svn_config_ensure(nsvn->config_dir, nsvn->pool); } else nsvn->config_dir = NULL; /* Creating Subversion client context object. */ nsvn->err = svn_client_create_context (&(nsvn->ctx), nsvn->pool); if (nsvn->err) return nsvn_base_uninit (nsvn); nsvn->err = svn_config_get_config (&(nsvn->ctx->config), nsvn->config_dir, nsvn->pool); if (nsvn->err) return nsvn_base_uninit (nsvn); nsvn->cfg = apr_hash_get(nsvn->ctx->config, SVN_CONFIG_CATEGORY_CONFIG, APR_HASH_KEY_STRING); return nsvn; }
void QSvn::init() { svn_error_t *err = nullptr; pool = svn_pool_create(nullptr); err = svn_fs_initialize(pool); if (err) { emit error(tr("Error calling svn_fs_initialize.")); return; } err = svn_config_ensure(nullptr, pool); if (err) { emit error(tr("Error calling svn_config_ensure.")); return; } err = svn_client_create_context(&ctx, pool); if (err) { emit error(tr("Error calling svn_client_create_context.")); return; } err = svn_config_get_config(&(ctx->config), nullptr, pool); if (err) { emit error(tr("Error calling svn_config_get_config.")); return; } ctx->log_msg_func3 = log_msg_func3; ctx->log_msg_baton3 = nullptr; ctx->notify_func2 = notify_func2; ctx->notify_baton2 = this; ctx->notify_func = nullptr; ctx->notify_baton = this; ctx->conflict_func = nullptr; ctx->conflict_baton = this; ctx->conflict_func2 = conflict_func2; ctx->conflict_baton2 = this; ctx->cancel_func = cancel_func; ctx->cancel_baton = this; ctx->progress_func = progress_func; ctx->progress_baton = this; ctx->client_name = "qsvn"; svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 3, sizeof (svn_auth_provider_object_t *)); svn_auth_get_platform_specific_client_providers (&providers, nullptr, pool); svn_auth_get_simple_prompt_provider (&provider, &svn_login_callback, this, /* baton */ 3, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&ctx->auth_baton, providers, pool); }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; apr_hash_t *dirents; const char *upload_file, *URL; const char *parent_URL, *basename; svn_ra_plugin_t *ra_lib; void *session, *ra_baton; svn_revnum_t rev; const svn_delta_editor_t *editor; void *edit_baton; svn_dirent_t *dirent; svn_ra_callbacks_t *cbtable; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 2) { printf ("Usage: %s PATH URL\n", argv[0]); printf (" Uploads file at PATH to Subversion repository URL.\n"); return EXIT_FAILURE; } upload_file = argv[1]; URL = argv[2]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("minimal_client", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ /* Open an RA session to the parent URL, fetch current HEAD rev and "lock" onto that revnum for the remainder of the session. */ svn_path_split (URL, &parent_URL, &basename, pool); err = svn_ra_init_ra_libs (&ra_baton, pool); if (err) goto hit_error; err = svn_ra_get_ra_library (&ra_lib, ra_baton, parent_URL, pool); if (err) goto hit_error; err = ra_lib->open (&session, parent_URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = ra_lib->get_latest_revnum (session, &rev, pool); if (err) goto hit_error; /* Examine contents of parent dir in the rev. */ err = ra_lib->get_dir (session, "", rev, &dirents, NULL, NULL, pool); if (err) goto hit_error; /* Sanity checks. Don't let the user shoot himself *too* much. */ dirent = apr_hash_get (dirents, basename, APR_HASH_KEY_STRING); if (dirent && dirent->kind == svn_node_dir) { printf ("Sorry, a directory already exists at that URL.\n"); return EXIT_FAILURE; } if (dirent && dirent->kind == svn_node_file) { char answer[5]; printf ("\n*** WARNING ***\n\n"); printf ("You're about to overwrite r%ld of this file.\n", rev); printf ("It was last changed by user '%s',\n", dirent->last_author ? dirent->last_author : "?"); printf ("on %s.\n", svn_time_to_human_cstring (dirent->time, pool)); printf ("\nSomebody *might* have just changed the file seconds ago,\n" "and your upload would be overwriting their changes!\n\n"); err = prompt_and_read_line("Are you SURE you want to upload? [y/n]", answer, sizeof(answer)); if (err) goto hit_error; if (apr_strnatcasecmp (answer, "y")) { printf ("Operation aborted.\n"); return EXIT_SUCCESS; } } /* Fetch a commit editor (it's anchored on the parent URL, because the session is too.) */ /* ### someday add an option for a user-written commit message? */ err = ra_lib->get_commit_editor (session, &editor, &edit_baton, "File upload from 'svnput' program.", my_commit_callback, NULL, pool); if (err) goto hit_error; /* Drive the editor */ { void *root_baton, *file_baton, *handler_baton; svn_txdelta_window_handler_t handler; svn_stream_t *contents; apr_file_t *f = NULL; err = editor->open_root (edit_baton, rev, pool, &root_baton); if (err) goto hit_error; if (! dirent) { err = editor->add_file (basename, root_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton); } else { err = editor->open_file (basename, root_baton, rev, pool, &file_baton); } if (err) goto hit_error; err = editor->apply_textdelta (file_baton, NULL, pool, &handler, &handler_baton); if (err) goto hit_error; err = svn_io_file_open (&f, upload_file, APR_READ, APR_OS_DEFAULT, pool); if (err) goto hit_error; contents = svn_stream_from_aprfile (f, pool); err = svn_txdelta_send_stream (contents, handler, handler_baton, NULL, pool); if (err) goto hit_error; err = svn_io_file_close (f, pool); if (err) goto hit_error; err = editor->close_file (file_baton, NULL, pool); if (err) goto hit_error; err = editor->close_edit (edit_baton, pool); if (err) goto hit_error; } return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "svnput: "); return EXIT_FAILURE; }
int main( int argc, char **argv ) { if( argc < 4 ) { std::cout << "Usage: " << argv[0] << " <path-to-wc-file> <num-calls> <recurse>" << std::endl; std::cout << " " << argv[0] << " readme.txt 50 0" << std::endl; std::cout << " " << argv[0] << " ../Sources 1 1" << std::endl; return 1; } apr_initialize(); apr_pool_initialize(); apr_pool_t *m_pool; apr_pool_create( &m_pool, NULL ); svn_config_ensure( "", m_pool ); svn_client_ctx_t m_context; memset( &m_context, 0, sizeof( m_context ) ); // get the config based on the config dir passed in svn_config_get_config( &m_context.config, "", m_pool ); apr_pool_t *pool = svn_pool_create( NULL ); svn_opt_revision_t revision; revision.kind = svn_opt_revision_working; char *path = argv[1]; svn_boolean_t recurse = atoi( argv[3] ); int t0 = elapse_time(); int max_calls = atoi( argv[2] ); int i; for( i=0; i<max_calls; i++ ) { apr_array_header_t *props = NULL; svn_error_t *error = svn_client_proplist ( &props, path, &revision, recurse, &m_context, pool ); } int t1 = elapse_time(); int total = t1 - t0; std::cout << "Time for " << max_calls << " calls " << total << "ms recurse=" << recurse << std::endl; std::cout << "Time for " << 1 << " call " << total/max_calls << "ms recurse=" << recurse << std::endl; return 0; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; svn_opt_revision_t revision; apr_hash_t *dirents; apr_hash_index_t *hi; svn_client_ctx_t *ctx; const char *URL; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); return EXIT_FAILURE; } else URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("minimal_client", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) { /* For functions deeper in the stack, we usually use the SVN_ERR() exception-throwing macro (see svn_error.h). At the top level, we catch & print the error with svn_handle_error2(). */ svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Make sure the ~/.subversion run-time config files exist */ err = svn_config_ensure (NULL, pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* All clients need to fill out a client_ctx object. */ { /* Initialize and allocate the client_ctx object. */ if ((err = svn_client_create_context (&ctx, pool))) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Load the run-time config file into a hash */ if ((err = svn_config_get_config (&(ctx->config), NULL, pool))) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } #ifdef WIN32 /* Set the working copy administrative directory name. */ if (getenv ("SVN_ASP_DOT_NET_HACK")) { err = svn_wc_set_adm_dir ("_svn", pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } } #endif /* Depending on what your client does, you'll want to read about (and implement) the various callback function types below. */ /* A func (& context) which receives event signals during checkouts, updates, commits, etc. */ /* ctx->notify_func = my_notification_func; ctx->notify_baton = NULL; */ /* A func (& context) which can receive log messages */ /* ctx->log_msg_func = my_log_msg_receiver_func; ctx->log_msg_baton = NULL; */ /* A func (& context) which checks whether the user cancelled */ /* ctx->cancel_func = my_cancel_checking_func; ctx->cancel_baton = NULL; */ /* Make the client_ctx capable of authenticating users */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. If you want to get the auth behavior of the 'svn' program, you can use svn_cmdline_setup_auth_baton, which will give you the exact set of auth providers it uses. This program doesn't use it because it's only appropriate for a command line program, and this is supposed to be a general purpose example. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_auth_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_auth_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&ctx->auth_baton, providers, pool); } } /* end of client_ctx setup */ /* Now do the real work. */ /* Set revision to always be the HEAD revision. It could, however, be set to a specific revision number, date, or other values. */ revision.kind = svn_opt_revision_head; /* Main call into libsvn_client does all the work. */ err = svn_client_ls (&dirents, URL, &revision, FALSE, /* no recursion */ ctx, pool); if (err) { svn_handle_error2 (err, stderr, FALSE, "minimal_client: "); return EXIT_FAILURE; } /* Print the dir entries in the hash. */ for (hi = apr_hash_first (pool, dirents); hi; hi = apr_hash_next (hi)) { const char *entryname; svn_dirent_t *val; apr_hash_this (hi, (void *) &entryname, NULL, (void *) &val); printf (" %s\n", entryname); /* 'val' is actually an svn_dirent_t structure; a more complex program would mine it for extra printable information. */ } return EXIT_SUCCESS; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; apr_hash_t *locks; apr_hash_index_t *hi; const char *URL; svn_ra_session_t *session; svn_ra_callbacks_t *cbtable; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); printf (" Print all locks at or below URL.\n"); return EXIT_FAILURE; } URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("ra_test", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ err = svn_ra_open (&session, URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = svn_ra_get_locks (session, &locks, "", pool); if (err) goto hit_error; err = svn_cmdline_printf (pool, "\n"); if (err) goto hit_error; for (hi = apr_hash_first (pool, locks); hi; hi = apr_hash_next (hi)) { const void *key; void *val; const char *path, *cr_date, *exp_date; svn_lock_t *lock; apr_hash_this (hi, &key, NULL, &val); path = key; lock = val; cr_date = svn_time_to_human_cstring (lock->creation_date, pool); if (lock->expiration_date) exp_date = svn_time_to_human_cstring (lock->expiration_date, pool); else exp_date = "never"; err = svn_cmdline_printf (pool, "%s\n", path); if (err) goto hit_error; err = svn_cmdline_printf (pool, " UUID Token: %s\n", lock->token); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Owner: %s\n", lock->owner); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Comment: %s\n", lock->comment ? lock->comment : "none"); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Created: %s\n", cr_date); if (err) goto hit_error; err = svn_cmdline_printf (pool, " Expires: %s\n\n", exp_date); if (err) goto hit_error; } return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "getlocks_test: "); return EXIT_FAILURE; }
int main (int argc, const char **argv) { apr_pool_t *pool; svn_error_t *err; const char *URL; svn_ra_session_t *session; svn_ra_callbacks2_t *cbtable; svn_revnum_t rev; apr_hash_t *cfg_hash; svn_auth_baton_t *auth_baton; if (argc <= 1) { printf ("Usage: %s URL\n", argv[0]); printf (" Print HEAD revision of URL's repository.\n"); return EXIT_FAILURE; } else URL = argv[1]; /* Initialize the app. Send all error messages to 'stderr'. */ if (svn_cmdline_init ("headrev", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create top-level memory pool. Be sure to read the HACKING file to understand how to properly use/free subpools. */ pool = svn_pool_create (NULL); /* Initialize the FS library. */ err = svn_fs_initialize (pool); if (err) goto hit_error; /* Make sure the ~/.subversion run-time config files exist, and load. */ err = svn_config_ensure (NULL, pool); if (err) goto hit_error; err = svn_config_get_config (&cfg_hash, NULL, pool); if (err) goto hit_error; /* Build an authentication baton. */ { /* There are many different kinds of authentication back-end "providers". See svn_auth.h for a full overview. */ svn_auth_provider_object_t *provider; apr_array_header_t *providers = apr_array_make (pool, 4, sizeof (svn_auth_provider_object_t *)); svn_client_get_simple_prompt_provider (&provider, my_simple_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; svn_client_get_username_prompt_provider (&provider, my_username_prompt_callback, NULL, /* baton */ 2, /* retry limit */ pool); APR_ARRAY_PUSH (providers, svn_auth_provider_object_t *) = provider; /* Register the auth-providers into the context's auth_baton. */ svn_auth_open (&auth_baton, providers, pool); } /* Create a table of callbacks for the RA session, mostly nonexistent. */ cbtable = apr_pcalloc (pool, sizeof(*cbtable)); cbtable->auth_baton = auth_baton; cbtable->open_tmp_file = open_tmp_file; /* Now do the real work. */ err = svn_ra_open2(&session, URL, cbtable, NULL, cfg_hash, pool); if (err) goto hit_error; err = svn_ra_get_latest_revnum(session, &rev, pool); if (err) goto hit_error; printf ("The latest revision is %ld.\n", rev); return EXIT_SUCCESS; hit_error: svn_handle_error2 (err, stderr, FALSE, "headrev: "); return EXIT_FAILURE; }