Ignore:
Timestamp:
Jun 4, 2008, 12:05:22 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Merged trunk changes r608:645 to replacing_gnuplot branch.

Location:
branches/replacing_gnuplot/bin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/replacing_gnuplot/bin/Makefile.am

    r585 r646  
    3030noinst_HEADERS = Parameter.h
    3131
    32 LDADD = $(STATICFLAG) @top_builddir@/lib/libsvndigest.la
     32LDADD = @top_builddir@/lib/libsvndigest.la $(SVNDIGEST_LIBS)
     33AM_LDFLAGS = $(STATICFLAG) $(SVNDIGEST_LDFLAGS)
    3334
    34 AM_CPPFLAGS = -I@top_srcdir@/lib
     35AM_CPPFLAGS = -I@top_srcdir@/lib $(SVNDIGEST_CPPFLAGS)
     36AM_CXXFLAGS = $(SVNDIGEST_CXXFLAGS)
     37
    3538
    3639# install versioned binary (excluding patch version)
  • branches/replacing_gnuplot/bin/Parameter.cc

    r581 r646  
    4242
    4343  Parameter::Parameter( int argc, char *argv[])
    44   {
    45     defaults();
     44    : config_file_(""), copyright_(false), force_(false),
     45      generate_config_(false), ignore_cache_(false), report_(true),
     46      revisions_(false), root_("."), root_node_("."), targetdir_("."),
     47      verbose_(false)
     48  {
    4649    for (int i=1; i<argc; ++i) {
    47       bool ok=false;
    4850      std::stringstream ss(argv[i]);
    4951      std::string myargv("");
     
    5456      if (myargv=="--config-file"){
    5557        if (value.size()) {
    56           config_file_= value;
    57           ok=true;
     58          config_file_.value()= value;
    5859        }
    5960        else if (++i<argc){
    60           config_file_= std::string(argv[i]);
    61           ok=true;
     61          config_file_.value()= std::string(argv[i]);
     62        }
     63        else {
     64          missing_argument(myargv);
    6265        }
    6366      }
    6467      else if (myargv=="--copyright"){
    65           copyright_=true;
    66           ok=true;
     68          copyright_.value()=true;
    6769      }
    6870      else if (myargv=="-f" || myargv=="--force"){
    69           force_=true;
    70           ok=true;
     71          force_.value()=true;
    7172      }
    7273      else if (myargv=="-g" || myargv=="--generate-config"){
    73           generate_config_=true;
    74           ok=true;
     74          generate_config_.value()=true;
    7575      }
    7676      else if (myargv=="-h" || myargv=="--help"){
     
    7979      }
    8080      else if (myargv=="--ignore-cache"){
    81           ignore_cache_=true;
    82           ok=true;
     81          ignore_cache_.value()=true;
    8382      }
    8483      else if (myargv=="-r" || myargv=="--root"){
    8584        if (value.size()) {
    86           root_= value;
    87           ok=true;
     85          root_.value()= value;
    8886        }
    8987        else if (++i<argc){
    90           root_= std::string(argv[i]);
    91           ok=true;
     88          root_.value()= std::string(argv[i]);
     89        }
     90        else {
     91          missing_argument(myargv);
    9292        }
    9393      }
    9494      else if (myargv=="--report") {
    95           report_=true;
    96           ok=true;
     95          report_.value()=true;
    9796      }
    9897      else if (myargv=="--no-report") {
    99           report_=false;
    100           ok=true;
     98          report_.value()=false;
    10199      }
    102100      else if (myargv=="--revisions") {
    103           revisions_=true;
    104           ok=true;
     101          revisions_.value()=true;
    105102      }
    106103      else if (myargv=="-t" || myargv=="--target"){
    107104        if (value.size()) {
    108           targetdir_= value;
    109           ok=true;
     105          targetdir_.value()= value;
    110106        }
    111107        else if (++i<argc){
    112           targetdir_= std::string(argv[i]);
    113           ok=true;
     108          targetdir_.value()= std::string(argv[i]);
     109        }
     110        else {
     111          missing_argument(myargv);
    114112        }
    115113      }
    116114      else if (myargv=="-v" || myargv=="--verbose"){
    117           verbose_=true;
    118           ok=true;
     115          verbose_.value()=true;
    119116      }
    120117      else if (myargv=="--version"){
    121         version_=true;
    122         ok=true;
     118        version();
     119        exit(0);
    123120      }
    124121      else if (myargv=="-vf" || myargv=="-fv"){
    125           verbose_=true;
    126           force_=true;
    127           ok=true;
    128       }
    129 
    130       if (!ok)
     122          verbose_.value()=true;
     123          force_.value()=true;
     124      }
     125      else {
    131126        throw std::runtime_error("svndigest: invalid option: " + myargv +
    132127                                 "\nTry `svndigest --help' for usage.");
     128      }
     129  }
     130
     131    analyse();
     132  }
     133
     134
     135  void Parameter::analyse(void)
     136  {
     137    using namespace std;
     138
     139    string workdir(pwd()); // remember current working directory (cwd).
     140
     141    if (!node_exist(root_.value()))
     142      throw runtime_error(string("svndigest: cannot stat `" + root_.value() +
     143                                 "': no such file or directory"));
     144
     145    if (access_rights(root_.value(), "r"))
     146      throw runtime_error(string("svndigest: cannot open `" + root_.value() +
     147                                 "' for reading: Permission denied"));
     148
     149    // Check whether root is directory or file
     150    struct stat nodestat;
     151    stat(root_.value().c_str(), &nodestat);
     152    if (S_ISDIR(nodestat.st_mode)) {
     153      chdir(root_.value().c_str());
     154      root_node_.value() = root_.value() = pwd();
    133155    }
    134 
    135     if (version_){
    136       version(verbose_);
    137       exit(0);
    138     }     
    139     analyse();
    140   }
    141 
    142 
    143   void Parameter::analyse(void)
    144   {
    145     using namespace std;
    146 
    147     string workdir(pwd()); // remember current working directory (cwd).
    148 
    149     bool root_ok = node_exist(root_) && !access_rights(root_, "r");
    150    
    151     if (root_ok) {
    152       // Check that root_ is a directory
    153       struct stat nodestat;
    154       stat(root_.c_str(), &nodestat);
    155       if (!S_ISDIR(nodestat.st_mode))
    156         throw runtime_error(string("svndigest: accessing `") + root_ +
    157                             "': Not a directory.");
     156    else {
     157      std::string fname = file_name(root_.value());
     158      root_.value() = directory_name(root_.value());
     159      chdir(root_.value().c_str());
     160      root_.value() = pwd();
     161      root_node_.value() = root_.value() + "/" + fname;
    158162    }
    159 
    160     // Checking that root_ exists and retrieve the absolute path to root_
    161     if (!root_ok || chdir(root_.c_str()))
    162       throw runtime_error(string("svndigest: Root directory (") + root_ +
    163                           ") access failed.");
    164     root_ = pwd();
    165 
    166      
    167163
    168164    // need to get back to cwd if relative paths are used.
     
    172168    // Checking that targetdir_ exists and retrieve the absolute path
    173169    // to targetdir_
    174     if (chdir(targetdir_.c_str()))
    175       throw runtime_error(string("svndigest: Target directory (") + targetdir_ +
    176                           ") access failed.");
    177     targetdir_ = pwd();
    178     // Checking write permissions for targetdir_
    179     if (access_rights(targetdir_,"w"))
    180       throw runtime_error(string("svndigest: No write permission on target ") +
    181                                  "directory (" + targetdir_ +").");
     170    if (report()) {
     171      if (chdir(targetdir_.value().c_str()))
     172        throw runtime_error(string("svndigest: Target directory (") +
     173                            targetdir_.value() + ") access failed.");
     174      targetdir_.value() = pwd();
     175      // Checking write permissions for targetdir_
     176      if (access_rights(targetdir_.value(),"w"))
     177        throw runtime_error(string("svndigest: No write permission on target ") +
     178                            "directory (" + targetdir_.value() +").");
     179    }
    182180
    183181    // return back to cwd
     
    191189  {
    192190    // not default
    193     if (!config_file_.empty())
    194       return config_file_;
     191    if (!config_file_.value().empty())
     192      return config_file_.value();
    195193   
    196194    // default behaviour
     
    199197
    200198
    201   void Parameter::defaults(void)
    202   {
    203     config_file_ = "";
    204     copyright_=false;
    205     force_=false;
    206     generate_config_=false;
    207     ignore_cache_=false;
    208     report_=true;
    209     revisions_=false;
    210     root_=".";
    211     targetdir_=".";
    212     verbose_=false;
    213     version_=false;
    214   }
    215 
    216 
    217   void Parameter::help(void)
    218   {
    219     defaults();
    220 
     199  void Parameter::help(void) const
     200  {
    221201    ColumnStream cs(std::cout, 1);
    222202    cs.width(0)=79;
    223203    cs.margin(0)=0;
    224204    ColumnStream cs2(std::cout, 2);
    225     cs2.width(0)=24;
     205    // Widest line should fit exactly
     206    cs2.width(0)=21;
    226207    cs2.width(1)=52;
    227208    cs2.margin(0)=2;
     209    // Gnits standard suggest three characters gap between option and description
     210    cs2.margin(1)=3;
    228211
    229212    std::cout << "Usage: svndigest [OPTION]...\n"
     
    235218       << "short options too.\n";
    236219
    237     cs2  << "    --copyright\tupdate copyright statement\n"
    238          << "    --config-file=ARG\tconfiguration file "
     220    cs2  << "    --config-file=ARG\tconfiguration file "
    239221         << "[<ROOT>/.svndigest/config]\n"
     222         << "    --copyright\tupdate copyright statement\n"
    240223         << "-f, --force\tif sub-directory named <ROOT> exists in "
    241224         << "target directory, remove sub-directory before writing results\n"
     
    243226         << "to standard output and exit\n"
    244227         << "-h, --help\tdisplay this help and exit\n"
    245          << "    --ignore-cache\tIgnore cache files and analyze "
     228         << "    --ignore-cache\tignore cache files and analyze "
    246229         << "everything from repository\n"
    247          << "    --no-report\tCreate no HTML report\n"
    248          << "    --revisions\tUse revision numbers as time scale "
     230         << "    --no-report\tcreate no HTML report\n"
     231         << "    --revisions\tuse revision numbers as time scale "
    249232         << "instead of dates [dates]\n"
    250233         << "-r, --root=ROOT\tsvn controlled directory to perform "
    251          << "statistics calculation on [" << root_ << "]\n"
    252          << "-t, --target=TARGET\toutput directory [" << targetdir_ << "]\n"
     234         << "statistics calculation on [" << root_.default_value() << "]\n"
     235         << "-t, --target=TARGET\toutput directory ["
     236         << targetdir_.default_value() << "]\n"
    253237         << "-v, --verbose\texplain what is being done\n"
    254238         << "    --version\tprint version information and exit\n";
     
    259243
    260244
     245  void Parameter::missing_argument(std::string opt) const
     246  {
     247    if (opt.size()>0 && opt[0]=='-')
     248      opt = opt.substr(1);
     249    if (opt.size()>0 && opt[0]=='-')
     250      opt = opt.substr(1);
     251    std::stringstream ss;
     252    ss << "svndigest: option requires an argument -- " << opt << "\n"
     253       << "Try `svndigest --help' for usage.";
     254    throw std::runtime_error(ss.str());
     255  }
     256
    261257  void Parameter::version(bool verbose) const
    262258  {
    263259    ColumnStream cs(std::cout, 1);
    264260    cs.width(0)=79;
    265     cs << PACKAGE_STRING;
    266     cs << " (";
    267     if (DEV_BUILD)
    268       cs << "r" << svn_revision() << " ";
    269     cs << "compiled " << __DATE__ ", " << __TIME__ << ")\n";
    270    
     261    cs << PACKAGE_STRING << version_string() << "\n";
    271262    cs << "\nCopyright (C) " << svn_year()
    272263       << " Jari H\u00E4kkinen and Peter Johansson.\n"
  • branches/replacing_gnuplot/bin/Parameter.h

    r540 r646  
    2626*/
    2727
     28#include "Option.h"
     29
    2830#include <map>
    2931#include <string>
     
    3739    Parameter( int argc, char *argv[]);
    3840    std::string config_file(void) const;
    39     inline bool copyright(void) const { return copyright_; }
     41    inline bool copyright(void) const { return copyright_.value(); }
    4042    /// @todo
    41     inline bool force(void) const { return force_; }
    42     inline bool generate_config(void) const { return generate_config_; }
    43     inline bool ignore_cache(void) const { return ignore_cache_; }
    44     inline bool report(void) const { return report_; }
    45     inline bool revisions(void) const { return revisions_; }
     43    inline bool force(void) const { return force_.value(); }
     44    inline bool generate_config(void) const { return generate_config_.value(); }
     45    // Until we fix caching (#313) ignore caching
     46    //inline bool ignore_cache(void) const { return ignore_cache_.value(); }
     47    inline bool ignore_cache(void) const { return true; }
     48    inline bool report(void) const { return report_.value(); }
     49    inline bool revisions(void) const { return revisions_.value(); }
    4650    /// @return absolute path to root directory
    47     inline const std::string& root(void) const { return root_; }
     51    inline const std::string& root(void) const { return root_.value(); }
     52    /// @return absolute path to root node
     53    inline const std::string& root_node(void) const {return root_node_.value();}
    4854    /// @return absolute path to target directory
    49     inline const std::string& targetdir(void) const { return targetdir_; }
    50     inline bool verbose(void) const { return verbose_; }
     55    inline const std::string& targetdir(void) const
     56    { return targetdir_.value(); }
     57    inline bool verbose(void) const { return verbose_.value(); }
    5158
    5259  private:
    5360    void analyse(void);
    54     void defaults(void);
    55     void help(void);
     61    void help(void) const;
     62    void missing_argument(std::string opt) const;
    5663    void version(bool=false) const;
    5764
    58     std::string config_file_;
    59     bool copyright_;
    60     bool force_;
    61     bool generate_config_;
    62     bool ignore_cache_;
    63     bool report_;
    64     bool revisions_;
    65     std::string root_;
    66     std::string targetdir_;
    67     bool verbose_;
    68     bool version_;
     65    Option<std::string> config_file_;
     66    Option<bool> copyright_;
     67    Option<bool> force_;
     68    Option<bool> generate_config_;
     69    Option<bool> ignore_cache_;
     70    Option<bool> report_;
     71    Option<bool> revisions_;
     72    Option<std::string> root_;
     73    Option<std::string> root_node_;
     74    Option<std::string> targetdir_;
     75    Option<bool> verbose_;
    6976  };
    7077
  • branches/replacing_gnuplot/bin/svndigest.cc

    r579 r646  
    160160    if (option->verbose())
    161161      std::cout << "Generating output" << std::endl;
    162     if (!option->revisions())
    163       GnuplotFE::instance()->set_dates(SVNlog(repo).date());
     162    if (!option->revisions()) {
     163      SVNlog log(repo);
     164      std::vector<std::string> dates;
     165      dates.reserve(log.commits().size());
     166      for (size_t i=0; i<log.commits().size(); ++i) {
     167        assert(static_cast<svn_revnum_t>(i)==log.commits()[i].revision());
     168        dates.push_back(log.commits()[i].date());
     169      }
     170      GnuplotFE::instance()->set_dates(dates);
     171    }
    164172    chdir(option->targetdir().c_str());
    165173    mkdir(tree->name());
Note: See TracChangeset for help on using the changeset viewer.