📄 main.c
字号:
move_on: if (err) { /* Print the error, but move on to the next lock. */ svn_handle_error2(err, stderr, FALSE /* non-fatal */, "svnadmin: "); svn_error_clear(err); } svn_pool_clear(subpool); } return SVN_NO_ERROR;}/** Main. **/intmain(int argc, const char *argv[]){ svn_error_t *err; apr_status_t apr_err; apr_allocator_t *allocator; apr_pool_t *pool; const svn_opt_subcommand_desc_t *subcommand = NULL; struct svnadmin_opt_state opt_state; apr_getopt_t *os; int opt_id; apr_array_header_t *received_opts; int i; /* Initialize the app. */ if (svn_cmdline_init("svnadmin", stderr) != EXIT_SUCCESS) return EXIT_FAILURE; /* Create our top-level pool. Use a seperate 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); received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int)); /* Check library versions */ err = check_lib_versions(); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); /* Initialize the FS library. */ err = svn_fs_initialize(pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); if (argc <= 1) { subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } /* Initialize opt_state. */ memset(&opt_state, 0, sizeof(opt_state)); opt_state.start_revision.kind = svn_opt_revision_unspecified; opt_state.end_revision.kind = svn_opt_revision_unspecified; /* Parse options. */ err = svn_cmdline__getopt_init(&os, argc, argv, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); os->interleave = 1; while (1) { const char *opt_arg; const char *utf8_opt_arg; /* Parse the next option. */ apr_err = apr_getopt_long(os, options_table, &opt_id, &opt_arg); if (APR_STATUS_IS_EOF(apr_err)) break; else if (apr_err) { subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } /* Stash the option code in an array before parsing it. */ APR_ARRAY_PUSH(received_opts, int) = opt_id; switch (opt_id) { case 'r': { if (opt_state.start_revision.kind != svn_opt_revision_unspecified) { err = svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Multiple revision arguments encountered; " "try '-r N:M' instead of '-r N -r M'")); return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); } if (svn_opt_parse_revision(&(opt_state.start_revision), &(opt_state.end_revision), opt_arg, pool) != 0) { err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool); if (! err) err = svn_error_createf (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Syntax error in revision argument '%s'"), utf8_opt_arg); return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); } } break; case 'q': opt_state.quiet = TRUE; break; case 'h': case '?': opt_state.help = TRUE; break; case svnadmin__version: opt_state.version = TRUE; break; case svnadmin__incremental: opt_state.incremental = TRUE; break; case svnadmin__deltas: opt_state.use_deltas = TRUE; break; case svnadmin__ignore_uuid: opt_state.uuid_action = svn_repos_load_uuid_ignore; break; case svnadmin__force_uuid: opt_state.uuid_action = svn_repos_load_uuid_force; break; case svnadmin__pre_1_4_compatible: opt_state.pre_1_4_compatible = TRUE; break; case svnadmin__fs_type: err = svn_utf_cstring_to_utf8(&opt_state.fs_type, opt_arg, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); break; case svnadmin__parent_dir: err = svn_utf_cstring_to_utf8(&opt_state.parent_dir, opt_arg, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); opt_state.parent_dir = svn_path_internal_style(opt_state.parent_dir, pool); break; case svnadmin__use_pre_commit_hook: opt_state.use_pre_commit_hook = TRUE; break; case svnadmin__use_post_commit_hook: opt_state.use_post_commit_hook = TRUE; break; case svnadmin__bdb_txn_nosync: opt_state.bdb_txn_nosync = TRUE; break; case svnadmin__bdb_log_keep: opt_state.bdb_log_keep = TRUE; break; case svnadmin__bypass_hooks: opt_state.bypass_hooks = TRUE; break; case svnadmin__clean_logs: opt_state.clean_logs = TRUE; break; case svnadmin__config_dir: opt_state.config_dir = apr_pstrdup(pool, svn_path_canonicalize(opt_arg, pool)); break; case svnadmin__wait: opt_state.wait = TRUE; break; default: { subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* close `switch' */ } /* close `while' */ /* If the user asked for help, then the rest of the arguments are the names of subcommands to get help on (if any), or else they're just typos/mistakes. Whatever the case, the subcommand to actually run is subcommand_help(). */ if (opt_state.help) subcommand = svn_opt_get_canonical_subcommand(cmd_table, "help"); /* If we're not running the `help' subcommand, then look for a subcommand in the first argument. */ if (subcommand == NULL) { if (os->ind >= os->argc) { if (opt_state.version) { /* Use the "help" subcommand to handle the "--version" option. */ static const svn_opt_subcommand_desc_t pseudo_cmd = { "--version", subcommand_help, {0}, "", {svnadmin__version, /* must accept its own option */ } }; subcommand = &pseudo_cmd; } else { svn_error_clear (svn_cmdline_fprintf(stderr, pool, _("subcommand argument required\n"))); subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } } else { const char *first_arg = os->argv[os->ind++]; subcommand = svn_opt_get_canonical_subcommand(cmd_table, first_arg); if (subcommand == NULL) { const char* first_arg_utf8; err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnadmin: "); svn_error_clear (svn_cmdline_fprintf(stderr, pool, _("Unknown command: '%s'\n"), first_arg_utf8)); subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } } } /* If there's a second argument, it's probably the repository. Every subcommand except `help' requires one, so we parse it out here and store it in opt_state. */ if (subcommand->cmd_func != subcommand_help) { err = parse_local_repos_path(os, &(opt_state.repository_path), pool); if(err) { svn_handle_error2(err, stderr, FALSE, "svnadmin: "); svn_error_clear(err); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* If command is hot copy the third argument will be the new repository path. */ if (subcommand->cmd_func == subcommand_hotcopy) { err = parse_local_repos_path(os, &(opt_state.new_repository_path), pool); if(err) { svn_handle_error2(err, stderr, FALSE, "svnadmin: "); svn_error_clear(err); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* Check that the subcommand wasn't passed any inappropriate options. */ for (i = 0; i < received_opts->nelts; i++) { opt_id = APR_ARRAY_IDX(received_opts, i, int); /* All commands implicitly accept --help, so just skip over this when we see it. Note that we don't want to include this option in their "accepted options" list because it would be awfully redundant to display it in every commands' help text. */ if (opt_id == 'h' || opt_id == '?') continue; if (! svn_opt_subcommand_takes_option(subcommand, opt_id)) { const char *optstr; const apr_getopt_option_t *badopt = svn_opt_get_option_from_code(opt_id, options_table); svn_opt_format_option(&optstr, badopt, FALSE, pool); if (subcommand->name[0] == '-') subcommand_help(NULL, NULL, pool); else svn_error_clear (svn_cmdline_fprintf (stderr, pool, _("subcommand '%s' doesn't accept option '%s'\n" "Type 'svnadmin help %s' for usage.\n"), subcommand->name, optstr, subcommand->name)); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* Set up our cancellation support. */ setup_cancellation_signals(signal_handler);#ifdef SIGPIPE /* Disable SIGPIPE generation for the platforms that have it. */ apr_signal(SIGPIPE, SIG_IGN);#endif#ifdef SIGXFSZ /* Disable SIGXFSZ generation for the platforms that have it, otherwise * working with large files when compiled against an APR that doesn't have * large file support will crash the program, which is uncool. */ apr_signal(SIGXFSZ, SIG_IGN);#endif /* Run the subcommand. */ err = (*subcommand->cmd_func)(os, &opt_state, pool); if (err) { svn_handle_error2(err, stderr, FALSE, "svnadmin: "); svn_error_clear(err); svn_pool_destroy(pool); return EXIT_FAILURE; } else { svn_pool_destroy(pool); /* Ensure that everything is written to stdout, so the user will see any print errors. */ err = svn_cmdline_fflush(stdout); if (err) { svn_handle_error2(err, stderr, FALSE, "svnadmin: "); svn_error_clear(err); return EXIT_FAILURE; } return EXIT_SUCCESS; }}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_crashtest(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnadmin_opt_state *opt_state = baton; svn_repos_t *repos; SVN_ERR(open_repos(&repos, opt_state->repository_path, pool)); abort(); return SVN_NO_ERROR;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -