📄 main.c
字号:
SVN_ERR(svn_cmdline_printf(pool, _("Owner: %s\n"), lock->owner)); SVN_ERR(svn_cmdline_printf(pool, _("Created: %s\n"), cr_date)); SVN_ERR(svn_cmdline_printf(pool, _("Expires: %s\n"), exp_date)); SVN_ERR(svn_cmdline_printf(pool, (comment_lines != 1) ? _("Comment (%i lines):\n%s\n") : _("Comment (%i line):\n%s\n"), comment_lines, lock->comment ? lock->comment : "")); } return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_info(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(do_author(c, pool)); SVN_ERR(do_date(c, pool)); SVN_ERR(do_log(c, TRUE, pool)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_log(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(do_log(c, FALSE, pool)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_pget(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; if (opt_state->arg1 == NULL) { return svn_error_createf (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, opt_state->revprop ? _("Missing propname argument") : _("Missing propname and repository path arguments")); } else if (!opt_state->revprop && opt_state->arg2 == NULL) { return svn_error_create (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, _("Missing propname or repository path argument")); } SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(do_pget(c, opt_state->arg1, opt_state->revprop ? NULL : opt_state->arg2, pool)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_plist(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; if (!opt_state->revprop && opt_state->arg1 == NULL) return svn_error_create (SVN_ERR_CL_INSUFFICIENT_ARGS, NULL, _("Missing repository path argument")); SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(do_plist(c, opt_state->revprop ? NULL : opt_state->arg1, opt_state->verbose, pool)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_tree(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(do_tree(c, opt_state->arg1 ? opt_state->arg1 : "", opt_state->show_ids, opt_state->full_paths, pool)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_youngest(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(svn_cmdline_printf(pool, "%ld\n", c->rev_id)); return SVN_NO_ERROR;}/* This implements `svn_opt_subcommand_t'. */static svn_error_t *subcommand_uuid(apr_getopt_t *os, void *baton, apr_pool_t *pool){ struct svnlook_opt_state *opt_state = baton; svnlook_ctxt_t *c; const char *uuid; SVN_ERR(get_ctxt_baton(&c, opt_state, pool)); SVN_ERR(svn_fs_get_uuid(c->fs, &uuid, pool)); SVN_ERR(svn_cmdline_printf(pool, "%s\n", uuid)); 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 svnlook_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("svnlook", 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, "svnlook: "); /* Initialize the FS library. */ err = svn_fs_initialize(pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnlook: "); 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.rev = SVN_INVALID_REVNUM; /* Parse options. */ err = svn_cmdline__getopt_init(&os, argc, argv, pool); if (err) return svn_cmdline_handle_exit_error(err, pool, "svnlook: "); os->interleave = 1; while (1) { const char *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': { char *digits_end = NULL; opt_state.rev = strtol(opt_arg, &digits_end, 10); if ((! SVN_IS_VALID_REVNUM(opt_state.rev)) || (! digits_end) || *digits_end) SVN_INT_ERR(svn_error_create (SVN_ERR_CL_ARG_PARSING_ERROR, NULL, _("Invalid revision number supplied"))); } break; case 't': opt_state.txn = opt_arg; break; case 'v': opt_state.verbose = TRUE; break; case 'h': case '?': opt_state.help = TRUE; break; case svnlook__revprop_opt: opt_state.revprop = TRUE; break; case svnlook__version: opt_state.version = TRUE; break; case svnlook__show_ids: opt_state.show_ids = TRUE; break; case svnlook__no_diff_deleted: opt_state.no_diff_deleted = TRUE; break; case svnlook__no_diff_added: opt_state.no_diff_added = TRUE; break; case svnlook__diff_copy_from: opt_state.diff_copy_from = TRUE; break; case svnlook__full_paths: opt_state.full_paths = TRUE; break; case svnlook__copy_info: opt_state.copy_info = TRUE; break; default: subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* The --transaction and --revision options may not co-exist. */ if ((opt_state.rev != SVN_INVALID_REVNUM) && opt_state.txn) SVN_INT_ERR(svn_error_create (SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL, _("The '--transaction' (-t) and '--revision' (-r) arguments " "can not co-exist"))); /* 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}, "", {svnlook__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, "svnlook: "); 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 the repository. There may be more arguments following the repository; usually the next one is a path within the repository, or it's a propname and the one after that is the path. Since we don't know, we just call them arg1 and arg2, meaning the first and second arguments following the repository. */ if (subcommand->cmd_func != subcommand_help) { const char *repos_path = NULL; const char *arg1 = NULL, *arg2 = NULL; /* Get the repository. */ if (os->ind < os->argc) { SVN_INT_ERR(svn_utf_cstring_to_utf8(&repos_path, os->argv[os->ind++], pool)); repos_path = svn_path_internal_style(repos_path, pool); } if (repos_path == NULL) { svn_error_clear (svn_cmdline_fprintf(stderr, pool, _("Repository argument required\n"))); subcommand_help(NULL, NULL, pool); svn_pool_destroy(pool); return EXIT_FAILURE; } else if (svn_path_is_url(repos_path)) { svn_error_clear (svn_cmdline_fprintf(stderr, pool, _("'%s' is a URL when it should be a path\n"), repos_path)); svn_pool_destroy(pool); return EXIT_FAILURE; } opt_state.repos_path = repos_path; /* Get next arg (arg1), if any. */ if (os->ind < os->argc) { SVN_INT_ERR(svn_utf_cstring_to_utf8 (&arg1, os->argv[os->ind++], pool)); arg1 = svn_path_internal_style(arg1, pool); } opt_state.arg1 = arg1; /* Get next arg (arg2), if any. */ if (os->ind < os->argc) { SVN_INT_ERR(svn_utf_cstring_to_utf8 (&arg2, os->argv[os->ind++], pool)); arg2 = svn_path_internal_style(arg2, pool); } opt_state.arg2 = arg2; } /* 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 'svnlook help %s' for usage.\n"), subcommand->name, optstr, subcommand->name)); svn_pool_destroy(pool); return EXIT_FAILURE; } } /* Set up our cancellation support. */ apr_signal(SIGINT, signal_handler);#ifdef SIGBREAK /* SIGBREAK is a Win32 specific signal generated by ctr
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -