static svn_error_t * commit_tree(svn_ra_session_t *session, apr_pool_t *pool) { apr_hash_t *revprop_table = apr_hash_make(pool); const svn_delta_editor_t *editor; void *edit_baton; const char *repos_root_url; void *root_baton, *A_baton, *B_baton, *file_baton; SVN_ERR(svn_ra_get_commit_editor3(session, &editor, &edit_baton, revprop_table, NULL, NULL, NULL, TRUE, pool)); SVN_ERR(svn_ra_get_repos_root(session, &repos_root_url, pool)); SVN_ERR(editor->open_root(edit_baton, SVN_INVALID_REVNUM, pool, &root_baton)); SVN_ERR(editor->add_directory("A", root_baton, NULL, SVN_INVALID_REVNUM, pool, &A_baton)); SVN_ERR(editor->add_directory("A/B", A_baton, NULL, SVN_INVALID_REVNUM, pool, &B_baton)); SVN_ERR(editor->add_file("A/B/f", B_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton)); SVN_ERR(editor->close_file(file_baton, NULL, pool)); SVN_ERR(editor->add_file("A/B/g", B_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton)); SVN_ERR(editor->close_file(file_baton, NULL, pool)); SVN_ERR(editor->close_directory(B_baton, pool)); SVN_ERR(editor->add_directory("A/BB", A_baton, NULL, SVN_INVALID_REVNUM, pool, &B_baton)); SVN_ERR(editor->add_file("A/BB/f", B_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton)); SVN_ERR(editor->close_file(file_baton, NULL, pool)); SVN_ERR(editor->add_file("A/BB/g", B_baton, NULL, SVN_INVALID_REVNUM, pool, &file_baton)); SVN_ERR(editor->close_file(file_baton, NULL, pool)); SVN_ERR(editor->close_directory(B_baton, pool)); SVN_ERR(editor->close_directory(A_baton, pool)); SVN_ERR(editor->close_edit(edit_baton, pool)); return SVN_NO_ERROR; }
/* Commit some simple changes */ static svn_error_t * commit_changes(svn_ra_session_t *session, apr_pool_t *pool) { apr_hash_t *revprop_table = apr_hash_make(pool); const svn_delta_editor_t *editor; void *edit_baton; const char *repos_root_url; void *root_baton, *dir_baton; SVN_ERR(svn_ra_get_commit_editor3(session, &editor, &edit_baton, revprop_table, NULL, NULL, NULL, TRUE, pool)); SVN_ERR(svn_ra_get_repos_root(session, &repos_root_url, pool)); SVN_ERR(editor->open_root(edit_baton, SVN_INVALID_REVNUM, pool, &root_baton)); /* copy root-dir@0 to A@1 */ SVN_ERR(editor->add_directory("A", root_baton, repos_root_url, 0, pool, &dir_baton)); SVN_ERR(editor->close_edit(edit_baton, pool)); return SVN_NO_ERROR; }
/* 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; }