Changeset 1068


Ignore:
Timestamp:
Jun 6, 2010, 4:56:31 AM (11 years ago)
Author:
Peter Johansson
Message:

refs #307. Use Parameter in svndigest rather than Parameter* to make main programs more uniform.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svndigest.cc

    r1067 r1068  
    5959
    6060  // Reading commandline options
    61   svndigestParameter* option = new svndigestParameter;
    62   assert(option);
    63   try {
    64     option->parse(argc,argv);
    65     if (option->verbose())
     61  svndigestParameter option;
     62  try {
     63    option.parse(argc,argv);
     64    if (option.verbose())
    6665      std::cout << "Done parsing parameters" << std::endl;
    6766  }
     
    7271
    7372  try {
    74     load_config(option->config_file());
     73    load_config(option.config_file());
    7574  }
    7675  catch (std::runtime_error& e) {
     
    8382  // set values from commandline into config object
    8483  try {
    85     if (option->format().present())
    86       Configuration::instance().image_format(option->format().value());
     84    if (option.format().present())
     85      Configuration::instance().image_format(option.format().value());
    8786  }
    8887  catch (std::runtime_error& e) {
    8988    std::cerr << PACKAGE_NAME ": invalid argument `"
    90               << option->format().value() << "' for `--"
    91               << option->format().long_name() << "'\n"
     89              << option.format().value() << "' for `--"
     90              << option.format().long_name() << "'\n"
    9291              << e.what() << "\n"
    9392              << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
     
    9594  }
    9695  try {
    97     if (option->anchor_format().present())
    98       config.image_anchor_format(option->anchor_format().value());
     96    if (option.anchor_format().present())
     97      config.image_anchor_format(option.anchor_format().value());
    9998  }
    10099  catch (std::runtime_error& e) {
    101100    std::cerr << PACKAGE_NAME ": invalid argument `"
    102               << option->anchor_format().value() << "' for `--"
    103               << option->anchor_format().long_name() << "'\n"
     101              << option.anchor_format().value() << "' for `--"
     102              << option.anchor_format().long_name() << "'\n"
    104103              << e.what() << "\n"
    105104              << "Try `" << PACKAGE_NAME << " --help' for more information.\n";
     
    108107 
    109108  // write configuration
    110   if (option->generate_config()) {
     109  if (option.generate_config()) {
    111110    std::cout << config;
    112111    exit(EXIT_SUCCESS);
     
    115114  SVN* svn=NULL;
    116115  try {
    117     if (option->verbose())
     116    if (option.verbose())
    118117      std::cout << "Initializing SVN singleton." << std::endl;
    119     svn=SVN::instance(option->root());
     118    svn=SVN::instance(option.root());
    120119  }
    121120  catch (SVNException e) {
     
    126125  // check if target already exists and behave appropriately
    127126  bool need_to_erase_target=false;
    128   std::string target_path=option->targetdir() + '/' + file_name(option->root());
    129   if (option->report()) {
    130     if (option->verbose())
     127  std::string target_path=option.targetdir() + '/' + file_name(option.root());
     128  if (option.report()) {
     129    if (option.verbose())
    131130      std::cout << "Checking target directory" << std::endl;
    132131    need_to_erase_target = node_exist(target_path);
    133     if (need_to_erase_target && !option->force()) {
     132    if (need_to_erase_target && !option.force()) {
    134133      std::cerr << "svndigest: directory `"
    135134                << target_path << "' already exists\n";
     
    141140  std::string repo;
    142141  try {
    143     if (option->verbose())
     142    if (option.verbose())
    144143      std::cout << "Acquiring repository information" << std::endl;
    145     repo=SVNinfo(option->root()).repos_root_url();
     144    repo=SVNinfo(option.root()).repos_root_url();
    146145  }
    147146  catch (SVNException e) {
    148147    std::cerr << "\nsvndigest: " << e.what()
    149148              << "\nsvndigest: Failed to determine repository for "
    150               << option->root() << '\n' << std::endl;
     149              << option.root() << '\n' << std::endl;
    151150    exit(EXIT_FAILURE);
    152151  }
     
    156155  // statements below and will not remove a digest tree below if a
    157156  // tree already exists.
    158   if (option->verbose())
     157  if (option.verbose())
    159158    std::cout << "Building directory tree" << std::endl;
    160159  Node* tree=NULL;
    161160  try {
    162     tree = new Directory(0,option->root(),"");
     161    tree = new Directory(0,option.root(),"");
    163162  }
    164163  catch (NodeException e) {
     
    168167  assert(tree);
    169168
    170   if (option->verbose())
     169  if (option.verbose())
    171170    std::cout << "Parsing directory tree" << std::endl;
    172   StatsCollection stats(tree->parse(option->verbose(), option->ignore_cache()));
    173 
    174   if (option->report()) {
     171  StatsCollection stats(tree->parse(option.verbose(), option.ignore_cache()));
     172
     173  if (option.report()) {
    175174    // remove target if needed
    176175    if (need_to_erase_target) {
    177       if (option->verbose())
     176      if (option.verbose())
    178177        std::cout << "Removing old target tree: " << target_path << "\n";
    179178      rmdirhier(target_path);
     
    186185
    187186
    188     if (option->verbose())
     187    if (option.verbose())
    189188      std::cout << "Generating output" << std::endl;
    190     if (!option->revisions()) {
     189    if (!option.revisions()) {
    191190      SVNlog log(repo);
    192191      std::vector<std::string> dates;
     
    200199      Graph::set_dates(dates);
    201200    }
    202     if (chdir(option->targetdir().c_str()) ) {
    203       std::cerr << "svndigest: chdir " << option->targetdir() << " failed\n";
     201    if (chdir(option.targetdir().c_str()) ) {
     202      std::cerr << "svndigest: chdir " << option.targetdir() << " failed\n";
    204203      exit(EXIT_FAILURE);
    205204    }
     
    216215      create_file_struct(i->first+std::string("/"), *i->second);
    217216    try {
    218       tree->print(option->verbose());
     217      tree->print(option.verbose());
    219218    }
    220219    catch (const std::runtime_error& x) {
     
    224223  }
    225224
    226   if (option->copyright()){
     225  if (option.copyright()){
    227226    try {
    228       if (option->verbose())
     227      if (option.verbose())
    229228        std::cout << "Updating copyright statements" << std::endl;
    230229      std::map<std::string, Alias> alias(config.copyright_alias());
    231       tree->print_copyright(alias, option->verbose());
     230      tree->print_copyright(alias, option.verbose());
    232231    }
    233232    catch (const std::runtime_error& x) {
     
    237236  }
    238237
    239   if (option->verbose())
     238  if (option.verbose())
    240239    std::cout << "Finalizing" << std::endl;
    241240
    242241  delete tree;
    243   if (option->verbose())
     242  if (option.verbose())
    244243    std::cout << "Done!" << std::endl;
    245   delete option;
    246244  exit(EXIT_SUCCESS);       // normal exit
    247245}
Note: See TracChangeset for help on using the changeset viewer.