main.c

来自「subversion-1.4.5.tar.gz 配置svn的源码」· C语言 代码 · 共 1,314 行 · 第 1/3 页

C
1,314
字号
  *pb = baton;  return SVN_NO_ERROR;}/* This implements `help` subcommand. */static svn_error_t *subcommand_help(apr_getopt_t *os, void *baton, apr_pool_t *pool){  struct svndumpfilter_opt_state *opt_state = baton;  const char *header =    _("general usage: svndumpfilter SUBCOMMAND [ARGS & OPTIONS ...]\n"      "Type 'svndumpfilter help <subcommand>' for help on a "      "specific subcommand.\n"      "Type 'svndumpfilter --version' to see the program version number.\n"      "\n"      "Available subcommands:\n");  SVN_ERR(svn_opt_print_help(os, "svndumpfilter",                             opt_state ? opt_state->version : FALSE,                             FALSE, NULL,                             header, cmd_table, options_table, NULL,                             pool));  return SVN_NO_ERROR;}/* Version compatibility check */static svn_error_t *check_lib_versions(void){  static const svn_version_checklist_t checklist[] =    {      { "svn_subr",  svn_subr_version },      { "svn_repos", svn_repos_version },      { "svn_delta", svn_delta_version },      { NULL, NULL }    };  SVN_VERSION_DEFINE(my_version);  return svn_ver_check_list(&my_version, checklist);}/* Do the real work of filtering. */static svn_error_t *do_filter(apr_getopt_t *os,           void *baton,           svn_boolean_t do_exclude,          apr_pool_t *pool){  struct svndumpfilter_opt_state *opt_state = baton;  struct parse_baton_t *pb;  apr_hash_index_t *hi;  apr_array_header_t *keys;  const void *key;  int i, num_keys;  if (! opt_state->quiet)    {      apr_pool_t *subpool = svn_pool_create(pool);      SVN_ERR(svn_cmdline_fprintf(stderr, subpool,                                  do_exclude                                  ? opt_state->drop_empty_revs                                  ? _("Excluding (and dropping empty "                                      "revisions for) prefixes:\n")                                  : _("Excluding prefixes:\n")                                  : opt_state->drop_empty_revs                                  ? _("Including (and dropping empty "                                      "revisions for) prefixes:\n")                                  : _("Including prefixes:\n")));      for (i = 0; i < opt_state->prefixes->nelts; i++)        {          svn_pool_clear(subpool);          SVN_ERR(svn_cmdline_fprintf                  (stderr, subpool, "   '%s'\n",                   APR_ARRAY_IDX(opt_state->prefixes, i, const char *)));        }      SVN_ERR(svn_cmdline_fputs("\n", stderr, subpool));      svn_pool_destroy(subpool);    }  SVN_ERR(parse_baton_initialize(&pb, opt_state, do_exclude, pool));  SVN_ERR(svn_repos_parse_dumpstream2(pb->in_stream, &filtering_vtable, pb,                                      NULL, NULL, pool));  /* The rest of this is just reporting.  If we aren't reporting, get     outta here. */  if (opt_state->quiet)    return SVN_NO_ERROR;  SVN_ERR(svn_cmdline_fputs("\n", stderr, pool));  if (pb->rev_drop_count)    SVN_ERR(svn_cmdline_fprintf(stderr, pool,                                _("Dropped %d revision(s).\n\n"),                                pb->rev_drop_count));  if (pb->do_renumber_revs)    {      apr_pool_t *subpool = svn_pool_create(pool);      SVN_ERR(svn_cmdline_fputs(_("Revisions renumbered as follows:\n"),                                stderr, subpool));      /* Get the keys of the hash, sort them, then print the hash keys         and values, sorted by keys. */      num_keys = apr_hash_count(pb->renumber_history);      keys = apr_array_make(pool, num_keys + 1, sizeof(svn_revnum_t));      for (hi = apr_hash_first(pool, pb->renumber_history);            hi;            hi = apr_hash_next(hi))        {          apr_hash_this(hi, &key, NULL, NULL);          APR_ARRAY_PUSH(keys, svn_revnum_t) = *((const svn_revnum_t *) key);        }      qsort(keys->elts, keys->nelts,             keys->elt_size, svn_sort_compare_revisions);      for (i = 0; i < keys->nelts; i++)        {          svn_revnum_t this_key;          struct revmap_t *this_val;          svn_pool_clear(subpool);          this_key = APR_ARRAY_IDX(keys, i, svn_revnum_t);          this_val = apr_hash_get(pb->renumber_history, &this_key,                                   sizeof(this_key));          if (this_val->was_dropped)            SVN_ERR(svn_cmdline_fprintf(stderr, subpool,                                        _("   %ld => (dropped)\n"),                                        this_key));          else            SVN_ERR(svn_cmdline_fprintf(stderr, subpool,                                        "   %ld => %ld\n",                                        this_key, this_val->rev));        }      SVN_ERR(svn_cmdline_fputs("\n", stderr, subpool));      svn_pool_destroy(subpool);    }  if (apr_hash_count(pb->dropped_nodes))    {      apr_pool_t *subpool = svn_pool_create(pool);      SVN_ERR(svn_cmdline_fprintf(stderr, subpool,                                  _("Dropped %d node(s):\n"),                                   apr_hash_count(pb->dropped_nodes)));      /* Get the keys of the hash, sort them, then print the hash keys         and values, sorted by keys. */      num_keys = apr_hash_count(pb->dropped_nodes);      keys = apr_array_make(pool, num_keys + 1, sizeof(const char *));      for (hi = apr_hash_first(pool, pb->dropped_nodes);           hi;            hi = apr_hash_next(hi))        {          apr_hash_this(hi, &key, NULL, NULL);          APR_ARRAY_PUSH(keys, const char *) = key;        }      qsort(keys->elts, keys->nelts, keys->elt_size, svn_sort_compare_paths);      for (i = 0; i < keys->nelts; i++)        {          svn_pool_clear(subpool);          SVN_ERR(svn_cmdline_fprintf                  (stderr, subpool, "   '%s'\n",                    (const char *)APR_ARRAY_IDX(keys, i, const char *)));        }      SVN_ERR(svn_cmdline_fputs("\n", stderr, subpool));      svn_pool_destroy(subpool);    }  return SVN_NO_ERROR;}/* This implements `exclude' subcommand. */static svn_error_t *subcommand_exclude(apr_getopt_t *os, void *baton, apr_pool_t *pool){  return do_filter(os, baton, TRUE, pool);}/* This implements `include` subcommand. */static svn_error_t *subcommand_include(apr_getopt_t *os, void *baton, apr_pool_t *pool){  return do_filter(os, baton, FALSE, pool);}/** 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 svndumpfilter_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("svndumpfilter", 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);		    /* Check library versions */  err = check_lib_versions();  if (err)    return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");  received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));  /* Initialize the FS library. */  err = svn_fs_initialize(pool);  if (err)    return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");  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, "svndumpfilter: ");  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 'h':        case '?':          opt_state.help = TRUE;          break;        case svndumpfilter__version:          opt_state.version = TRUE;        case svndumpfilter__quiet:          opt_state.quiet = TRUE;          break;        case svndumpfilter__drop_empty_revs:          opt_state.drop_empty_revs = TRUE;          break;        case svndumpfilter__renumber_revs:          opt_state.renumber_revs = TRUE;          break;        case svndumpfilter__preserve_revprops:          opt_state.preserve_revprops = 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}, "",                  {svndumpfilter__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;              if ((err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,                                                 pool)))                return svn_cmdline_handle_exit_error(err, pool,                                                     "svndumpfilter: ");                              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 [one of] prefixes.     Every subcommand except `help' requires at least one, so we parse     them out here and store in opt_state. */  if (subcommand->cmd_func != subcommand_help)    {      if (os->ind >= os->argc)        {          svn_error_clear(svn_cmdline_fprintf                          (stderr, pool,                           _("\nError: no prefixes supplied.\n")));          svn_pool_destroy(pool);          return EXIT_FAILURE;        }      opt_state.prefixes = apr_array_make(pool, os->argc - os->ind,                                          sizeof(const char *));      for (i = os->ind ; i< os->argc; i++)        {          const char *prefix;          /* Ensure that each prefix is UTF8-encoded, in internal             style, and absolute. */          SVN_INT_ERR(svn_utf_cstring_to_utf8(&prefix, os->argv[i], pool));          prefix = svn_path_internal_style(prefix, pool);          prefix = svn_path_join("/", prefix, pool);          APR_ARRAY_PUSH(opt_state.prefixes, const char *) = prefix;        }    }  /* 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 'svndumpfilter help %s' for usage.\n"),                             subcommand->name, optstr, subcommand->name));          svn_pool_destroy(pool);          return EXIT_FAILURE;        }    }  /* Run the subcommand. */  err = (*subcommand->cmd_func)(os, &opt_state, pool);  if (err)    {      svn_handle_error2(err, stderr, FALSE, "svndumpfilter: ");      svn_pool_destroy(pool);      return EXIT_FAILURE;    }  else    {      svn_pool_destroy(pool);      /* Flush stdout, making sure the user will see any print errors. */      SVN_INT_ERR(svn_cmdline_fflush(stdout));      return EXIT_SUCCESS;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?