Changeset 1222


Ignore:
Timestamp:
Oct 17, 2010, 5:51:36 PM (13 years ago)
Author:
Peter Johansson
Message:

merge trunk changes to visitor branch

Location:
branches/visitor
Files:
24 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/visitor

  • branches/visitor/bin/Parameter.cc

    r1119 r1222  
    9797      check_existence(root_.value());
    9898      check_readable(root_.value());
     99      check_is_dir(root_.value());
    99100      chdir(root_.value());
    100101      root_.value(pwd());
     
    116117      if (S_ISDIR(nodestat.st_mode)) {
    117118        std::stringstream ss;
    118         ss << cmd_.program_name() << ": `" << config_file_.value()
     119        ss << cmd_.program_name() << ": '" << config_file_.value()
    119120           << "' is a directory";
    120121        throw yat::utility::cmd_error(ss.str());
     
    130131      return;
    131132    std::stringstream ss;
    132     ss << cmd_.program_name() << ": cannot stat `" << path << "': "
     133    ss << cmd_.program_name() << ": cannot stat '" << path << "': "
    133134       << strerror(errno);
    134135    throw yat::utility::cmd_error(ss.str());
     
    136137
    137138 
     139  void Parameter::check_is_dir(std::string path) const
     140  {
     141    if (node_exist(path)) {
     142      struct stat buf;
     143      stat(path.c_str(), &buf);
     144      if (S_ISDIR(buf.st_mode))
     145        return;
     146    }
     147    std::stringstream ss;
     148    ss << cmd_.program_name() << ": '" << path << "': "
     149       << strerror(errno);
     150    throw yat::utility::cmd_error(ss.str());
     151  }
     152
     153 
    138154  void Parameter::check_readable(std::string path) const
    139155  {
     
    141157      return;
    142158    std::stringstream ss;
    143     ss << cmd_.program_name() << ": cannot open `" << path << "': "
     159    ss << cmd_.program_name() << ": cannot open '" << path << "': "
    144160       << strerror(errno);
    145161    throw yat::utility::cmd_error(ss.str());
  • branches/visitor/bin/svndigestParameter.cc

    r1186 r1222  
    8585    std::string save_wd = pwd();
    8686
    87     // check root but not if -g option given
    8887    if (!generate_config()) {
    8988      // check target (only if we write report)
     
    9190        check_existence(target_.value());
    9291        check_readable(target_.value());
     92        check_is_dir(target_.value());
    9393        std::string base_root = file_name(root());
    9494        std::string path = concatenate_path(target_.value(),base_root);
    9595        if (access_rights(target_.value(), "w")) {
    9696          std::stringstream ss;
    97           ss << "svndigest: cannot create directory `" << path
     97          ss << "svndigest: cannot create directory '" << path
    9898             << "': " << strerror(errno);
    9999          throw yat::utility::cmd_error(ss.str());
     
    101101        if (node_exist(path) && !force()) {
    102102          std::stringstream ss;
    103           ss << "svndigest: cannot create directory `" << path << "' "
     103          ss << "svndigest: cannot create directory '" << path << "' "
    104104             << strerror(EEXIST);
    105105          throw yat::utility::cmd_error(ss.str());
  • branches/visitor/lib/File.cc

    r1197 r1222  
    205205  {
    206206    if (verbose)
    207       std::cout << "Parsing " << path_ << std::endl;
     207      std::cout << "Parsing '" << path_ << "'" << std::endl;
    208208    stats_.reset();
    209209    std::string cache_dir = directory_name(path()) + std::string(".svndigest/");
     
    343343      return;
    344344    if (verbose)
    345       std::cout << "Updating copyright in " << path_ << std::endl;
     345      std::cout << "Updating copyright in '" << path_ << "'" << std::endl;
    346346    update_copyright(new_block, start_line, end_line);
    347347  }
  • branches/visitor/lib/Node.cc

    r1186 r1222  
    203203      return;
    204204    if (verbose)
    205       std::cout << "Printing output for " << path_ << std::endl;
     205      std::cout << "Printing output for '" << path_ << "'" << std::endl;
    206206    const SVNlog& log = this->log();
    207207    typedef std::map<std::string, Stats*>::const_iterator iter;
  • branches/visitor/lib/SVN.cc

    r978 r1222  
    3838#include <subversion-1/svn_subst.h>
    3939
     40#include <string>
     41
    4042namespace theplu {
    4143namespace svndigest {
     44
     45
     46  SVNException::SVNException(const std::string& msg, svn_error_t* error)
     47    : std::runtime_error(""), error_(error), msg_(msg)
     48  {
     49    ref_count_ = new int(1);
     50    if (error_) {
     51      apr_size_t bufsize=255;
     52      char buf[255];
     53      msg_ = svn_err_best_message(error_, buf, bufsize);
     54    }
     55    if (msg.size()) {
     56      msg_ += msg;
     57    }
     58  }
     59
     60  SVNException::SVNException(const SVNException& other)
     61    : std::runtime_error(other), error_(other.error_), msg_(other.msg_),
     62      ref_count_(other.ref_count_)
     63  {
     64    ++(*ref_count_);
     65  }
     66
     67
     68  SVNException::~SVNException(void) throw()
     69  {
     70    --(*ref_count_);
     71    if (!(*ref_count_)) {
     72      delete ref_count_;
     73      ref_count_=NULL;
     74      svn_error_clear(error_);
     75      error_=SVN_NO_ERROR;
     76    }
     77  }
     78
     79
     80  const char* SVNException::what(void) const throw()
     81  {
     82    return msg_.c_str();
     83  }
     84
     85
     86  const svn_error_t* SVNException::error(void) const
     87  {
     88    return error_;
     89  }
    4290
    4391
     
    100148                              context_->cancel_baton, pool_))){
    101149      if (err->apr_err == SVN_ERR_WC_NOT_DIRECTORY)
    102         cleanup_failed_init(err, std::string(err->message), true);
     150        cleanup_failed_init(err, std::string(err->message));
    103151      cleanup_failed_init(err, "SVN: svn_wc_adm_open3 failed");
    104152    }
     
    128176                    std::string message, bool mute)
    129177  {
    130     if (!mute)
    131       svn_handle_error2(err,stderr,false,"svndigest: ");
    132178    svn_error_clear(err);
    133179    if (pool){
     
    135181      pool=NULL;
    136182    }
    137     if (message.length()>0)
    138       throw SVNException(message);
    139   }
    140 
    141 
    142   void SVN::cleanup_failed_init(svn_error_t *err, const std::string& message,
    143                                 bool mute)
    144   {
    145     cleanup(err,pool_, "", true);
     183    assert(message.size()); // compatible with r1213
     184    if (!mute)
     185      throw SVNException(message, err);
     186    // mute implies we don't wanna hear the message from svn_error_t
    146187    throw SVNException(message);
    147188  }
    148189
    149190
    150   svn_error_t* SVN::client_blame(const std::string& path,
    151                                  svn_client_blame_receiver_t receiver,
    152                                  void *baton, svn_revnum_t rev)
     191  void SVN::cleanup_failed_init(svn_error_t *err, const std::string& message)
     192  {
     193    assert(message.size()); // compatible with r1213
     194    cleanup(err,pool_, message, true);
     195    assert(false && "cleanup should throw");
     196  }
     197
     198
     199  void SVN::client_blame(const std::string& path,
     200                         svn_client_blame_receiver_t receiver,
     201                         void *baton, svn_revnum_t rev)
    153202  {
    154203    svn_opt_revision_t head;
    155204    head.kind=svn_opt_revision_number;
    156205    head.value.number=rev;
    157     return client_blame_call(path, receiver, baton, head);
    158   }
    159 
    160   svn_error_t* SVN::client_blame(const std::string& path,
    161                                 svn_client_blame_receiver_t receiver,
    162                                 void *baton)
     206    client_blame_call(path, receiver, baton, head);
     207  }
     208
     209  void SVN::client_blame(const std::string& path,
     210                        svn_client_blame_receiver_t receiver,
     211                        void *baton)
    163212  {
    164213    svn_opt_revision_t head;
    165214    head.kind = ( svn_path_is_url(path.c_str()) ?
    166215                  svn_opt_revision_head : svn_opt_revision_base );
    167     return client_blame_call(path, receiver, baton, head);
    168   }
    169 
    170 
    171   svn_error_t* SVN::client_blame_call(const std::string& path,
    172                                       svn_client_blame_receiver_t receiver,
    173                                       void *baton, svn_opt_revision_t& head)
     216    client_blame_call(path, receiver, baton, head);
     217  }
     218
     219
     220  void SVN::client_blame_call(const std::string& path,
     221                              svn_client_blame_receiver_t receiver,
     222                              void *baton, svn_opt_revision_t& head)
    174223  {
    175224    // Setup to use all revisions
     
    183232                                       false, receiver, baton, context_,
    184233                                       subpool);
    185     if (err && err->apr_err!=SVN_ERR_CLIENT_IS_BINARY_FILE)
     234    if (err)
    186235      // cleanup will throw an exception
    187236      cleanup(err, subpool, "SVN::client_blame: svn_client_blame3 failed");
    188237    svn_pool_destroy(subpool);
    189     return err;
    190238  }
    191239
     
    295343    if (info->repos_root_URL)
    296344      rurb->path=info->repos_root_URL;
    297 
    298345    return SVN_NO_ERROR;
    299346  }
  • branches/visitor/lib/SVN.h

    r978 r1222  
    5050  ///
    5151  struct SVNException : public std::runtime_error
    52   { inline SVNException(const std::string& msg) : runtime_error(msg) {} };
     52  {
     53    SVNException(const std::string& msg, svn_error_t* error=NULL);
     54
     55    /**
     56       Copy constructor
     57     */
     58    SVNException(const SVNException& other);
     59
     60    /**
     61       Destructor
     62     */
     63    virtual ~SVNException(void) throw();
     64
     65    /**
     66       override base implementation
     67     */
     68    const char* what(void) const throw();
     69
     70    /**
     71       access svn_error_t
     72     */
     73    const svn_error_t* error(void) const;
     74  private:
     75    svn_error_t* error_;
     76    std::string msg_;
     77    int* ref_count_;
     78
     79    // assignment not allowed
     80    SVNException& operator=(const SVNException&);
     81  };
    5382
    5483  /**
     
    96125
    97126       \a path can be either a URL or an WC target.
    98 
    99        \return SVN_NO_ERROR or SVN_ERR_CLIENT_IS_BINARY_FILE, the
    100        latter can be used to trigger on binary files. Note that errors
    101        return from underlying subversion API must be cleared by the
    102        receiver.
    103 
    104        \see Subversion API (svn_error_clear).
    105     */
    106     svn_error_t * client_blame(const std::string& path,
    107                                svn_client_blame_receiver_t receiver,
    108                                void *baton);
     127    */
     128    void client_blame(const std::string& path,
     129                      svn_client_blame_receiver_t receiver,
     130                      void *baton);
    109131
    110132    /**
     
    112134       \a rev can be set.
    113135     */
    114     svn_error_t * client_blame(const std::string& path,
    115                                svn_client_blame_receiver_t receiver,
    116                                void *baton, svn_revnum_t rev);
     136    void client_blame(const std::string& path,
     137                      svn_client_blame_receiver_t receiver,
     138                      void *baton, svn_revnum_t rev);
    117139
    118140    /**
     
    227249       @brief Free resources when svn API calls fail.
    228250
    229        This function will write an error message to stdout, free \a
    230        err and \a pool resources. If \a err or \a pool are a NULL
    231        pointers the function will do nothing with these resources. If
    232        \a mute is true, no error message is written.
    233 
    234        cleanup will throw a SVNException if \a message has
    235        length>0. The default bahaviour is to free resources and return
    236        normally.
     251       This function will free \a pool resources and throw an
     252       exception holding the \a message. If mute is false, the thrown
     253       exception also contains \a err.
     254
     255       \throw cleanup will throw a SVNException
    237256
    238257       @see SVNException
     
    251270       @see SVNException
    252271    */
    253     void cleanup_failed_init(svn_error_t *err, const std::string& message,
    254                              bool mute=false);
     272    void cleanup_failed_init(svn_error_t *err, const std::string& message);
    255273
    256274    static SVN* instance_;
     
    276294    */
    277295    static svn_error_t*
    278     root_url_receiver(void *baton, const char *path, const svn_info_t *info,
    279                       apr_pool_t *pool);
    280 
    281     svn_error_t* client_blame_call(const std::string& path,
    282                                   svn_client_blame_receiver_t receiver,
    283                                   void *baton, svn_opt_revision_t& head);
     296    root_url_receiver(void *baton, const char *path,
     297                      const svn_info_t *info, apr_pool_t *pool);
     298
     299    void client_blame_call(const std::string& path,
     300                          svn_client_blame_receiver_t receiver,
     301                          void *baton, svn_opt_revision_t& head);
    284302
    285303    svn_wc_adm_access_t* adm_access_;
  • branches/visitor/lib/SVNblame.cc

    r978 r1222  
    3131
    3232  SVNblame::SVNblame(const std::string& path)
    33     : binary_(false), instance_(SVN::instance())
     33    : instance_(SVN::instance())
    3434  {
    35     if (svn_error_t* err=
    36         instance_->client_blame(path.c_str(), blame_receiver,
    37                                 static_cast<void*>(&blame_receiver_baton_))) {
    38       // SVN_ERR_CLIENT_IS_BINARY_FILE is the only error allowed to
    39       // escape the client_blame call
    40       svn_error_clear(err);
    41       binary_=true;
    42     }
     35    instance_->client_blame(path.c_str(), blame_receiver,
     36                            static_cast<void*>(&blame_receiver_baton_));
    4337    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
    4438  }
     
    4640
    4741  SVNblame::SVNblame(const std::string& path, svn_revnum_t rev)
    48     : binary_(false), instance_(SVN::instance())
     42    : instance_(SVN::instance())
    4943  {
    50     if (svn_error_t* err=
    51         instance_->client_blame(path.c_str(), blame_receiver,
    52                                 static_cast<void*>(&blame_receiver_baton_),
    53                                 rev)) {
    54       // SVN_ERR_CLIENT_IS_BINARY_FILE is the only error allowed to
    55       // escape the client_blame call
    56       svn_error_clear(err);
    57       binary_=true;
    58     }
     44    instance_->client_blame(path.c_str(), blame_receiver,
     45                            static_cast<void*>(&blame_receiver_baton_),
     46                            rev);
    5947    blame_info_iterator_ = blame_receiver_baton_.blame_info.begin();
    6048  }
     
    7563  {
    7664    return (*blame_info_iterator_)->author;
    77   }
    78 
    79 
    80   bool SVNblame::binary(void)
    81   {
    82     return binary_;
    8365  }
    8466
  • branches/visitor/lib/SVNblame.h

    r978 r1222  
    7676    */
    7777    std::string author(void);
    78 
    79     /**
    80        Returns true if item is binary false otherwise
    81 
    82        Binary files are invalid for 'svn blame'.
    83     */
    84     bool binary(void);
    8578
    8679    /**
     
    164157    };
    165158
    166     // binary_ is true if item in any revision has been binary.
    167     bool binary_;
    168159    // blame_info_iterator_ is used in statistics analysis to traverse
    169160    // blame_receiver_baton.blame_info vector through calls to next().
  • branches/visitor/lib/rmdirhier.cc

    r1186 r1222  
    2525#include "utility.h"
    2626
     27#include <cstdio>
    2728#include <cstring>
    2829#include <dirent.h>
     
    7576      // Make sure file is removable before removing it
    7677      chmod(dir.c_str(),S_IWRITE);
    77       if (unlink(dir.c_str()))
     78      if (remove(dir.c_str()))
    7879        throw FileDeleteError(concatenate_path(pwd(),dir));
    7980      return;
     
    9798    // Remove the directory from its parent
    9899    chdir("..");
    99     if (rmdir(dir.c_str()))
     100    if (remove(dir.c_str()))
    100101      throw DirectoryDeleteError(concatenate_path(pwd(),dir));
    101102  }
  • branches/visitor/m4/apache_LICENSE-2.0.txt

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/ax_cxx_check_flag.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/ax_cxxcpp_check_flag.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/ax_ld_check_flag.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/find_apr.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/pkg.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/version.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/m4/yat_add_flag.m4

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/visitor/test/Makefile.am

    r1187 r1222  
    3939distributed_TESTS += config3_test.sh
    4040distributed_TESTS += copyright2_test.sh
     41distributed_TESTS += error_test.sh
    4142distributed_TESTS += repo_status_test.sh
    4243distributed_TESTS += repo_test.sh
  • branches/visitor/test/cmd_format_test.sh

    r1092 r1222  
    2727SVNDIGEST_run 1 -f --format=banana
    2828test -s stderr || exit_fail
    29 grep 'invalid argument.*banana.*format' stderr || exit_fail
     29$GREP 'invalid argument.*banana.*format' stderr || exit_fail
    3030
    3131SVNDIGEST_run 0 -g --format=svg --anchor-format=svg
    32 grep 'format = svg' stdout || exit_fail
    33 grep 'anchor_format = svg' stdout || exit_fail
     32$GREP 'format = svg' stdout || exit_fail
     33$GREP 'anchor_format = svg' stdout || exit_fail
    3434
    3535exit_success;
  • branches/visitor/test/config2_test.sh

    r1092 r1222  
    3636
    3737SVNDIGEST_run 1 -g --config-file tmp_config
    38 grep 'unknown format.* apple' stderr || exit_fail
     38$GREP 'unknown format.* apple' stderr || exit_fail
    3939
    4040exit_success
  • branches/visitor/test/config3_test.sh

    r1092 r1222  
    2828SVNDIGEST_run 0 -g --config-file /dev/null
    2929SVNDIGEST_run 1 -g --config-file .
    30 grep 'is a directory' stderr || exit_fail
     30$GREP 'is a directory' stderr || exit_fail
    3131
    3232exit_success
  • branches/visitor/test/init.sh.in

    r1153 r1222  
    5454test -z "$srcdir" && srcdir="@srcdir@";
    5555test -z "$SVN" && SVN=svn;
     56test -z "$GREP" && GREP=@GREP@;
    5657
    5758# some helpful derived variables
  • branches/visitor/test/svncopyright_test.sh

    r1092 r1222  
    3131done
    3232
    33 $SVNCOPYRIGHT --version | head -n 1 | grep svncopyright || exit_fail
     33$SVNCOPYRIGHT --version | head -n 1 | $GREP svncopyright || exit_fail
    3434
    3535exit_success
Note: See TracChangeset for help on using the changeset viewer.