void SVNAdmin::create(const char *path, bool disableFsyncCommits, bool keepLogs, const char *configPath, const char *fstype) { Pool requestPool; SVN_JNI_NULL_PTR_EX(path, "path", ); path = svn_path_internal_style(path, requestPool.pool()); if (configPath != NULL) configPath = svn_path_internal_style(configPath, requestPool.pool()); svn_repos_t *repos; apr_hash_t *config; apr_hash_t *fs_config = apr_hash_make (requestPool.pool());; apr_hash_set (fs_config, SVN_FS_CONFIG_BDB_TXN_NOSYNC, APR_HASH_KEY_STRING, (disableFsyncCommits? "1" : "0")); apr_hash_set (fs_config, SVN_FS_CONFIG_BDB_LOG_AUTOREMOVE, APR_HASH_KEY_STRING, (keepLogs ? "0" : "1")); apr_hash_set (fs_config, SVN_FS_CONFIG_FS_TYPE, APR_HASH_KEY_STRING, fstype); SVN_JNI_ERR(svn_config_get_config(&config, configPath, requestPool.pool()),); SVN_JNI_ERR(svn_repos_create(&repos, path, NULL, NULL, config, fs_config, requestPool.pool()), ); }
/* Helper to parse local repository path. Try parsing next parameter * of OS as a local path to repository. If successfull *REPOS_PATH * will contain internal style path to the repository. */ static svn_error_t * parse_local_repos_path (apr_getopt_t *os, const char ** repos_path, apr_pool_t *pool) { *repos_path = NULL; /* Check to see if there is one more parameter. */ if (os->ind < os->argc) { const char * path = os->argv[os->ind++]; SVN_ERR (svn_utf_cstring_to_utf8 (repos_path, path, pool)); *repos_path = svn_path_internal_style (*repos_path, pool); } if (*repos_path == NULL) { return svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Repository argument required")); } else if (svn_path_is_url (*repos_path)) { return svn_error_createf (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("'%s' is an URL when it should be a path"), *repos_path); } return SVN_NO_ERROR; }
/* Helper function. Set URL to a "file://" url for the current directory, suffixed by the forward-slash-style relative path SUFFIX, performing all allocation in POOL. */ static svn_error_t * current_directory_url(const char **url, const char *suffix, apr_pool_t *pool) { /* 8KB is a lot, but it almost guarantees that any path will fit. */ char curdir[8192]; const char *utf8_ls_curdir, *utf8_is_curdir, *unencoded_url; if (! getcwd(curdir, sizeof(curdir))) return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed"); SVN_ERR(svn_utf_cstring_to_utf8(&utf8_ls_curdir, curdir, pool)); utf8_is_curdir = svn_path_internal_style(utf8_ls_curdir, pool); unencoded_url = apr_psprintf(pool, "file://%s%s%s%s", (utf8_is_curdir[0] != '/') ? "/" : "", utf8_is_curdir, (suffix[0] && suffix[0] != '/') ? "/" : "", suffix); *url = svn_path_uri_encode(unencoded_url, pool); return SVN_NO_ERROR; }
bool CAppUtils::CreateUnifiedDiff(const CString& orig, const CString& modified, const CString& output, bool bShowError) { apr_file_t * outfile = NULL; apr_pool_t * pool = svn_pool_create(NULL); svn_error_t * err = svn_io_file_open (&outfile, svn_path_internal_style(CUnicodeUtils::GetUTF8(output), pool), APR_WRITE | APR_CREATE | APR_BINARY | APR_TRUNCATE, APR_OS_DEFAULT, pool); if (err == NULL) { svn_stream_t * stream = svn_stream_from_aprfile2(outfile, false, pool); if (stream) { svn_diff_t * diff = NULL; svn_diff_file_options_t * opts = svn_diff_file_options_create(pool); opts->ignore_eol_style = false; opts->ignore_space = svn_diff_file_ignore_space_none; err = svn_diff_file_diff_2(&diff, svn_path_internal_style(CUnicodeUtils::GetUTF8(orig), pool), svn_path_internal_style(CUnicodeUtils::GetUTF8(modified), pool), opts, pool); if (err == NULL) { err = svn_diff_file_output_unified(stream, diff, svn_path_internal_style(CUnicodeUtils::GetUTF8(orig), pool), svn_path_internal_style(CUnicodeUtils::GetUTF8(modified), pool), NULL, NULL, pool); svn_stream_close(stream); } } apr_file_close(outfile); } if (err) { if (bShowError) AfxMessageBox(CAppUtils::GetErrorString(err), MB_ICONERROR); svn_error_clear(err); svn_pool_destroy(pool); return false; } svn_pool_destroy(pool); return true; }
static const char * SVNParentPath_cmd(cmd_parms *cmd, void *config, const char *arg1) { dir_conf_t *conf = config; if (conf->fs_path != NULL) return "SVNParentPath cannot be defined at same time as SVNPath."; conf->fs_parent_path = svn_path_internal_style(apr_pstrdup(cmd->pool, arg1), cmd->pool); return NULL; }
void SVNAdmin::deltify(const char *path, Revision &revStart, Revision &revEnd) { Pool requestPool; SVN_JNI_NULL_PTR_EX(path, "path", ); path = svn_path_internal_style(path, requestPool.pool()); svn_repos_t *repos; svn_fs_t *fs; svn_revnum_t start = SVN_INVALID_REVNUM, end = SVN_INVALID_REVNUM; svn_revnum_t youngest, revision; Pool revisionPool; SVN_JNI_ERR(svn_repos_open(&repos, path, requestPool.pool()), ); fs = svn_repos_fs (repos); SVN_JNI_ERR(svn_fs_youngest_rev(&youngest, fs, requestPool.pool()), ); if (revStart.revision()->kind == svn_opt_revision_number) /* ### We only handle revision numbers right now, not dates. */ start = revStart.revision()->value.number; else if (revStart.revision()->kind == svn_opt_revision_head) start = youngest; else start = SVN_INVALID_REVNUM; if (revEnd.revision()->kind == svn_opt_revision_number) end = revEnd.revision()->value.number; else if (revEnd.revision()->kind == svn_opt_revision_head) end = youngest; else end = SVN_INVALID_REVNUM; /* Fill in implied revisions if necessary. */ if (start == SVN_INVALID_REVNUM) start = youngest; if (end == SVN_INVALID_REVNUM) end = start; if (start > end) { SVN_JNI_ERR(svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("First revision cannot be higher than second")), ); }
void Path::init(const char * path) { Pool pool; m_pathIsUrl = false; if (path == 0) m_path = ""; else { const char * int_path = svn_path_internal_style(path, pool.pool()); m_path = int_path; if (svn::Url::isValid(int_path)) m_pathIsUrl = true; } }
/* * Why is this not an svn subcommand? I have this vague idea that it could * be run as part of the build process, with the output embedded in the svn * program. Obviously we don't want to have to run svn when building svn. */ int main(int argc, const char *argv[]) { const char *wc_path, *trail_url; apr_allocator_t *allocator; apr_pool_t *pool; int wc_format; svn_wc_revision_status_t *res; svn_boolean_t no_newline = FALSE, committed = FALSE; svn_error_t *err; apr_getopt_t *os; const apr_getopt_option_t options[] = { {"no-newline", 'n', 0, N_("do not output the trailing newline")}, {"committed", 'c', 0, N_("last changed rather than current revisions")}, {"help", 'h', 0, N_("display this help")}, {"version", SVNVERSION_OPT_VERSION, 0, N_("show program version information")}, {0, 0, 0, 0} }; /* Initialize the app. */ if (svn_cmdline_init("svnversion", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create our top-level pool. Use a separate mutexless allocator, * given this application is single threaded. */ if (apr_allocator_create(&allocator)) return EXIT_FAILURE; apr_allocator_max_free_set(allocator, SVN_ALLOCATOR_RECOMMENDED_MAX_FREE); pool = svn_pool_create_ex(NULL, allocator); apr_allocator_owner_set(allocator, pool); /* Check library versions */ err = check_lib_versions(); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnversion: "); #if defined(WIN32) || defined(__CYGWIN__) /* Set the working copy administrative directory name. */ if (getenv("SVN_ASP_DOT_NET_HACK")) { err = svn_wc_set_adm_dir("_svn", pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnversion: "); } #endif err = svn_cmdline__getopt_init(&os, argc, argv, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnversion: "); os->interleave = 1; while (1) { int opt; const char *arg; apr_status_t status = apr_getopt_long(os, options, &opt, &arg); if (APR_STATUS_IS_EOF(status)) break; if (status != APR_SUCCESS) { usage(pool); return EXIT_FAILURE; } switch (opt) { case 'n': no_newline = TRUE; break; case 'c': committed = TRUE; break; case 'h': help(options, pool); break; case SVNVERSION_OPT_VERSION: SVN_INT_ERR(version(pool)); exit(0); break; default: usage(pool); return EXIT_FAILURE; } } if (os->ind > argc || os->ind < argc - 2) { usage(pool); return EXIT_FAILURE; } SVN_INT_ERR(svn_utf_cstring_to_utf8 (&wc_path, (os->ind < argc) ? os->argv[os->ind] : ".", pool)); wc_path = svn_path_internal_style(wc_path, pool); if (os->ind+1 < argc) SVN_INT_ERR(svn_utf_cstring_to_utf8 (&trail_url, os->argv[os->ind+1], pool)); else trail_url = NULL; SVN_INT_ERR(svn_wc_check_wc(wc_path, &wc_format, pool)); if (! wc_format) { svn_node_kind_t kind; SVN_INT_ERR(svn_io_check_path(wc_path, &kind, pool)); if (kind == svn_node_dir) { SVN_INT_ERR(svn_cmdline_printf(pool, _("exported%s"), no_newline ? "" : "\n")); svn_pool_destroy(pool); return EXIT_SUCCESS; } else { svn_error_clear (svn_cmdline_fprintf(stderr, pool, _("'%s' not versioned, and not exported\n"), wc_path)); svn_pool_destroy(pool); return EXIT_FAILURE; } } SVN_INT_ERR(svn_wc_revision_status(&res, wc_path, trail_url, committed, NULL, NULL, pool)); /* Build compact '123[:456]M?S?' string. */ SVN_INT_ERR(svn_cmdline_printf(pool, "%ld", res->min_rev)); if (res->min_rev != res->max_rev) SVN_INT_ERR(svn_cmdline_printf(pool, ":%ld", res->max_rev)); if (res->modified) SVN_INT_ERR(svn_cmdline_fputs("M", stdout, pool)); if (res->switched) SVN_INT_ERR(svn_cmdline_fputs("S", stdout, pool)); if (res->sparse_checkout) SVN_INT_ERR(svn_cmdline_fputs("P", stdout, pool)); if (! no_newline) SVN_INT_ERR(svn_cmdline_fputs("\n", stdout, pool)); svn_pool_destroy(pool); /* Flush stdout to make sure that the user will see any printing errors. */ SVN_INT_ERR(svn_cmdline_fflush(stdout)); return EXIT_SUCCESS; }
svn_error_t * svn_nls_init(void) { svn_error_t *err = SVN_NO_ERROR; #ifdef ENABLE_NLS #ifdef WIN32 { WCHAR ucs2_path[MAX_PATH]; char* utf8_path; const char* internal_path; apr_pool_t* pool; apr_status_t apr_err; apr_size_t inwords, outbytes, outlength; apr_pool_create(&pool, 0); /* get exe name - our locale info will be in '../share/locale' */ inwords = GetModuleFileNameW(0, ucs2_path, sizeof(ucs2_path) / sizeof(ucs2_path[0])); if (! inwords) { /* We must be on a Win9x machine, so attempt to get an ANSI path, and convert it to Unicode. */ CHAR ansi_path[MAX_PATH]; if (GetModuleFileNameA(0, ansi_path, sizeof(ansi_path))) { inwords = MultiByteToWideChar(CP_ACP, 0, ansi_path, -1, ucs2_path, sizeof(ucs2_path) / sizeof(ucs2_path[0])); if (! inwords) { err = svn_error_createf(APR_EINVAL, NULL, _("Can't convert string to UCS-2: '%s'"), ansi_path); } } else { err = svn_error_create(APR_EINVAL, NULL, _("Can't get module file name")); } } if (! err) { outbytes = outlength = 3 * (inwords + 1); utf8_path = apr_palloc(pool, outlength); apr_err = apr_conv_ucs2_to_utf8(ucs2_path, &inwords, utf8_path, &outbytes); if (!apr_err && (inwords > 0 || outbytes == 0)) apr_err = APR_INCOMPLETE; if (apr_err) { err = svn_error_createf(apr_err, NULL, _("Can't convert module path " "to UTF-8 from UCS-2: '%s'"), ucs2_path); } else { utf8_path[outlength - outbytes] = '\0'; internal_path = svn_path_internal_style(utf8_path, pool); /* get base path name */ internal_path = svn_path_dirname(internal_path, pool); internal_path = svn_path_join(internal_path, SVN_LOCALE_RELATIVE_PATH, pool); bindtextdomain(PACKAGE_NAME, internal_path); } } svn_pool_destroy(pool); } #else bindtextdomain(PACKAGE_NAME, SVN_LOCALE_DIR); #ifdef HAVE_BIND_TEXTDOMAIN_CODESET bind_textdomain_codeset(PACKAGE_NAME, "UTF-8"); #endif #endif #endif return err; }
int main(int argc, char **argv) { apr_pool_t *pool; svn_error_t *err; apr_array_header_t *targets; apr_array_header_t *condensed_targets; const char *common_path = 0; const char *common_path2 = 0; int i; if (argc < 2) { fprintf(stderr, "USAGE: %s <list of entries to be compared>\n", argv[0]); return EXIT_FAILURE; } /* Initialize the app. */ if (svn_cmdline_init("target-test", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create our top-level pool. */ pool = svn_pool_create(NULL); /* Create the target array */ targets = apr_array_make(pool, argc - 1, sizeof(const char *)); for (i = 1; i < argc; i++) { const char *path_utf8; #ifndef AS400_UTF8 err = svn_utf_cstring_to_utf8(&path_utf8, argv[i], pool); #else /* Even when compiled with UTF support in V5R4, argv is still * encoded in ebcdic. */ err = svn_utf_cstring_to_utf8_ex2(&path_utf8, argv[i], (const char *)0, pool); #endif if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); APR_ARRAY_PUSH(targets, const char *) = svn_path_internal_style(path_utf8, pool); } /* Call the function */ err = svn_path_condense_targets(&common_path, &condensed_targets, targets, TRUE, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); /* Display the results */ { const char *common_path_stdout; err = svn_utf_cstring_from_utf8(&common_path_stdout, common_path, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); printf("%s: ", common_path_stdout); } for (i = 0; i < condensed_targets->nelts; i++) { const char * target = APR_ARRAY_IDX(condensed_targets, i, const char*); if (target) { const char *target_stdout; err = svn_utf_cstring_from_utf8(&target_stdout, target, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); printf("%s, ", target_stdout); } else printf("NULL, "); } printf("\n"); /* Now ensure it works without the pbasename */ err = svn_path_condense_targets(&common_path2, NULL, targets, TRUE, pool); if (err != SVN_NO_ERROR) svn_handle_error2(err, stderr, TRUE, "target-test: "); if (strcmp(common_path, common_path2) != 0) { printf("Common path without getting targets does not match common path " "with targets\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
svn_error_t * svn_config__win_config_path(const char **folder, int system_path, apr_pool_t *pool) { /* ### Adding CSIDL_FLAG_CREATE here, because those folders really must exist. I'm not too sure about the SHGFP_TYPE_CURRENT semancics, though; maybe we should use ..._DEFAULT instead? */ const int csidl = ((system_path ? CSIDL_COMMON_APPDATA : CSIDL_APPDATA) | CSIDL_FLAG_CREATE); int style; apr_status_t apr_err = apr_filepath_encoding(&style, pool); if (apr_err) return svn_error_wrap_apr(apr_err, "Can't determine the native path encoding"); if (style == APR_FILEPATH_ENCODING_UTF8) { WCHAR folder_ucs2[MAX_PATH]; apr_size_t inwords, outbytes, outlength; char *folder_utf8; if (S_OK != SHGetFolderPathW(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, folder_ucs2)) goto no_folder_path; /* ### When mapping from UCS-2 to UTF-8, we need at most 3 bytes per wide char, plus extra space for the nul terminator. */ inwords = lstrlenW(folder_ucs2); outbytes = outlength = 3 * (inwords + 1); folder_utf8 = apr_palloc(pool, outlength); apr_err = apr_conv_ucs2_to_utf8(folder_ucs2, &inwords, folder_utf8, &outbytes); if (!apr_err && (inwords > 0 || outbytes == 0)) apr_err = APR_INCOMPLETE; if (apr_err) return svn_error_wrap_apr(apr_err, "Can't convert config path to UTF-8"); /* Note that apr_conv_ucs2_to_utf8 does _not_ terminate the outgoing buffer. */ folder_utf8[outlength - outbytes] = '\0'; *folder = folder_utf8; } else if (style == APR_FILEPATH_ENCODING_LOCALE) { char folder_ansi[MAX_PATH]; if (S_OK != SHGetFolderPathA(NULL, csidl, NULL, SHGFP_TYPE_CURRENT, folder_ansi)) goto no_folder_path; SVN_ERR(svn_utf_cstring_to_utf8(folder, folder_ansi, pool)); } else { /* There is no third option on Windows; we should never get here. */ return svn_error_createf(APR_EINVAL, NULL, "Unknown native path encoding (%d)", style); } *folder = svn_path_internal_style(*folder, pool); return SVN_NO_ERROR; no_folder_path: return svn_error_create(SVN_ERR_BAD_FILENAME, NULL, (system_path ? "Can't determine the system config path" : "Can't determine the user's config path")); }