Changeset 123


Ignore:
Timestamp:
Jul 30, 2006, 12:42:54 AM (15 years ago)
Author:
Jari Häkkinen
Message:

Addresses ticket:23. Removed 'svn log' for revision-date extraction.

Location:
trunk
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/svnstat.cc

    r117 r123  
    2424#include "Parameter.h"
    2525
    26 #include "CommitStat.h"
    2726#include "Directory.h"
    2827#include "GnuplotFE.h"
     
    5150  }
    5251
     52  // Make sure that root directory is under subversion control.
    5353  SVN* svn=SVN::instance();
    5454  try {
     
    6161  }
    6262
     63  // Extract repository location
     64  std::string repo;
     65  try {
     66    repo=svn->repository(option->root());
     67  }
     68  catch (SVNException e) {
     69    std::cerr << "\nsvnstat: " << e.what()
     70              << "\nsvnstat: Failed to determine repository for "
     71              << option->root() << '\n' << std::endl;
     72    exit(-1);
     73  }
     74
     75  // Retrieve commit dates.
     76  std::vector<std::string> commit_dates;
     77  try {
     78    svn->setup_ra_session(repo);
     79    commit_dates=svn->commit_dates(repo);
     80  }
     81  catch (SVNException e) {
     82    std::cerr << "\nsvnstat: " << e.what() << std::endl;
     83    exit(-1);
     84  }
     85
     86  // check if target already exists and behave appropriately
    6387  if (option->force()){
    6488    std::string root_path(option->targetdir()+'/'+file_name(option->root()));
     
    78102      exit(-1);
    79103    }
    80 
    81104  }
    82105
    83   if (!option->revisions()) {
    84     if (option->verbose())
    85       std::cout << "Parsing the log." << std::endl;
    86     CommitStat cs;
    87     cs.parse(option->root());
    88     GnuplotFE::instance()->set_dates(cs.date());
    89   }
     106  if (!option->revisions())
     107    GnuplotFE::instance()->set_dates(commit_dates);
    90108
    91109  Directory tree(0,option->root(),"");
  • trunk/lib/Gnuplot.h

    r111 r123  
    4949  /// The Gnuplot class creates a pipe to 'gnuplot' and facilitates
    5050  /// communication with the gnuplot binary.
     51  ///
     52  /// @see GnuplotFE
    5153  ///
    5254  class Gnuplot
  • trunk/lib/GnuplotFE.h

    r97 r123  
    3535  ///
    3636  /// The GnuplotFE class is a front end to the Gnuplot class. This is
    37   /// a utility function needed to communicate plotting related
     37  /// a utility class needed to communicate plotting related
    3838  /// information between objects.
    3939  ///
     
    4343  ///
    4444  /// @see Design Patterns (the singleton pattern).
     45  /// @see Gnuplot
    4546  ///
    4647  class GnuplotFE : public Gnuplot
     
    8586    ///
    8687    inline void set_dates(const std::vector<std::string>& date,
    87                           const std::string& format="%Y-%m-%d")
     88                          const std::string& format="%Y-%m-%dT%H:%M:%SZ")
    8889    { date_=date; date_input_format_=format; }
    8990
  • trunk/lib/Makefile.am

    r103 r123  
    2525noinst_LIBRARIES = libsvnstat.a
    2626
    27 noinst_HEADERS = CommitStat.h Directory.h File.h Gnuplot.h GnuplotFE.h  \
    28   Node.h Parser.h rmdirhier.h Stats.h SVN.h utility.h
     27noinst_HEADERS = Directory.h File.h Gnuplot.h GnuplotFE.h Node.h  \
     28  Parser.h rmdirhier.h Stats.h SVN.h utility.h
    2929
    30 libsvnstat_a_SOURCES = CommitStat.cc Directory.cc File.cc Gnuplot.cc  \
    31   GnuplotFE.cc Node.cc Parser.cc rmdirhier.cc Stats.cc SVN.cc utility.cc
     30libsvnstat_a_SOURCES = Directory.cc File.cc Gnuplot.cc GnuplotFE.cc \
     31  Node.cc Parser.cc rmdirhier.cc Stats.cc SVN.cc utility.cc
    3232
    3333INCLUDES = -I$(SVN_PATH)/include/subversion-1 -I$(APR_PATH)/include/apr-0
  • trunk/lib/SVN.cc

    r91 r123  
    4444    // doing, most bits here are stolen from subversion source for the
    4545    // svn command line binary (subverion/svn/main.c)
     46
     47    svn_error_t* err=NULL;
    4648
    4749    // initialize something (APR subsystem and more). The APR
     
    5658    if (apr_allocator_create(&allocator_))
    5759      throw SVNException("SVN(void): apr_allocator_create failed");
    58 
    5960    apr_allocator_max_free_set(allocator_,SVN_ALLOCATOR_RECOMMENDED_MAX_FREE);
    6061    pool_ = svn_pool_create_ex(NULL, allocator_);
     
    6263
    6364    // initialize the repository access library
    64     svn_error_t* err = svn_ra_initialize(pool_);
    65     if (err) {
     65    if ((err=svn_ra_initialize(pool_))) {
    6666      // destroys pool and clears err
    6767      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     
    7474    // command line option to change the location of the .subversion
    7575    // stuff (compare with the svn binary).
    76     err = svn_config_ensure(NULL, pool_);
    77     if (err) {
     76    if ((err=svn_config_ensure(NULL, pool_))) {
    7877      // destroys pool and clears err
    7978      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     
    8382
    8483    // create a client context object
    85     err = svn_client_create_context(&context_, pool_);
    86     if (err) {
     84    if ((err=svn_client_create_context(&context_, pool_))) {
    8785      // destroys pool and clears err
    8886      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     
    9189    }
    9290
    93     err = svn_config_get_config(&(context_->config), NULL, pool_);
    94     if (err) {
     91    if ((err=svn_config_get_config(&(context_->config), NULL, pool_))) {
    9592      // destroys pool and clears err
    9693      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     
    121118
    122119
     120  std::vector<std::string> SVN::commit_dates(const std::string& path)
     121  {
     122    // Allocate space in pool_ for apr_path (here a string).
     123    apr_array_header_t* apr_path=apr_array_make(pool_,1,4);
     124    // Copy path to apr_path.
     125    (*((const char **) apr_array_push(apr_path))) =
     126      apr_pstrdup(pool_, svn_path_internal_style(path.c_str(),pool_));
     127
     128    // Setup to retrieve all commit logs.
     129    svn_opt_revision_t peg, start, head;
     130    peg.kind=svn_opt_revision_unspecified;
     131    start.kind=svn_opt_revision_number;
     132    start.value.number=0;
     133    head.kind=svn_opt_revision_head;
     134    svn_error_t* err=NULL;
     135    // Retrieving the last revision is only needed for the reserve
     136    // call below, not needed for the functionality here.
     137    if ((err=svn_ra_get_latest_revnum(ra_session_,&(head.value.number),pool_))) {
     138      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     139      throw SVNException("commit_dates: svn_ra_get_latest_revnum failed");
     140    }
     141    // The struct we want to pass through to all log_message_receiver
     142    // calls, here we only want to push all commit dates into a
     143    // std::vector<std::string>.
     144    struct log_receiver_baton lb;
     145    lb.commit_dates.reserve(head.value.number+1); // revision 0 is also stored.
     146    if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, true,
     147                             log_message_receiver, static_cast<void*>(&lb),
     148                             context_, pool_))) {
     149      svn_cmdline_handle_exit_error(err, pool_, "svnstat: ");
     150      throw SVNException("commit_dates: svn_client_log3 failed");
     151    }
     152    return lb.commit_dates;
     153  }
     154
     155
     156  svn_error_t *
     157  SVN::info_receiver(void *baton, const char *, const svn_info_t *info,
     158                     apr_pool_t *)
     159  {
     160    if (!info || !info->repos_root_URL)
     161      throw SVNException("Failed to acquire repository root URL");
     162    static_cast<struct info_receiver_baton*>(baton)->repos_root_url=
     163      info->repos_root_URL;
     164    return SVN_NO_ERROR;
     165  }
     166
     167
     168  svn_error_t *
     169  SVN::log_message_receiver(void *baton, apr_hash_t *changed_paths,
     170                            svn_revnum_t rev, const char *author,
     171                            const char *date, const char *msg, apr_pool_t *pool)
     172  {
     173    struct log_receiver_baton *lb=static_cast<struct log_receiver_baton*>(baton);
     174    if (date && date[0])
     175      lb->commit_dates.push_back(date);
     176    else
     177      throw SVNException("No date defined for revision: " + rev);
     178    return SVN_NO_ERROR;
     179  }
     180
     181
     182  std::string SVN::repository(const std::string& path)
     183  {
     184    struct info_receiver_baton ib;
     185    if (svn_client_info(path.c_str(), NULL, NULL, info_receiver,
     186                        static_cast<void*>(&ib), false, context_, pool_))
     187      throw SVNException("repository: svn_client_info failed");
     188    return ib.repos_root_url;
     189  }
     190
     191
     192  void SVN::setup_ra_session(const std::string& path) {
     193    // get a session to the repository
     194    if (svn_client_open_ra_session(&ra_session_, path.c_str(), context_,pool_)) {
     195      // Jari, should the error space be cleared?
     196      throw SVNException("setup_ra_session: svn_client_open_ra_session failed");
     197    }
     198  }
     199
     200
    123201  void SVN::setup_wc_adm_access(const std::string& path)
    124202  {
     
    128206    if (svn_wc_adm_open3(&adm_access_, NULL, canonical_path, false, -1,
    129207                         context_->cancel_func,context_->cancel_baton, pool_))
    130       // should the error space be cleared?
     208      // Jari, should the error space be cleared?
    131209      throw SVNException("setup_wc_adm_access: svn_wc_adm_open3 failed");
    132210  }
  • trunk/lib/SVN.h

    r91 r123  
    2626
    2727#include <stdexcept>
     28#include <string>
     29#include <vector>
    2830
     31// Jari, most of these can be replaced with forward declarations.
    2932#include <apr_allocator.h>
    3033#include <svn_client.h>
     34#include <svn_ra.h>
    3135#include <svn_wc.h>
    3236
     
    4852  /// SVN provides one single global access point to the underlying
    4953  /// subversion API and makes sure that there is only one point of
    50   /// access to the binary.
     54  /// access for the binary.
    5155  ///
    5256  /// @see Design Patterns (the singleton pattern). Subversion API
     
    6872
    6973    ///
     74    /// @brief Get revision dates.
     75    ///
     76    /// Get dates for all commits to the repository. \a root can be a
     77    /// repository path or a path within a working copy. In the latter
     78    /// case the corresponding repository will be used to retrieve
     79    /// commit dates.
     80    ///
     81    /// @return Revision dates in a vector where revision is
     82    /// implicitly defined by vector index, i.e., element 56 in the
     83    /// resulting vector implies revision 56.
     84    ///
     85    /// @note Currently revision 0 (repositoy creation) is not
     86    /// supported.
     87    ///
     88    /// @throw Various error messages generated from the subversion
     89    /// API.
     90    ///
     91    std::vector<std::string> commit_dates(const std::string& path);
     92
     93    ///
    7094    /// @brief Get an instance of SVN.
    7195    ///
    72     /// @throw Throws a SVNException if one is received from the
    73     /// underlying constructor call.
     96    /// @throw Throws an SVNException if initialization fails in the
     97    /// underlying subversion API calls.
    7498    ///
    7599    /// @todo Make sure that the underlying constructor performs
     
    80104
    81105    ///
    82     /// @throws SCNException if access setup fails.
     106    /// @brief Determine the repository root URL for \a path.
     107    ///
     108    /// @throws SVNException if repository location cannot be
     109    /// determined.
     110    ///
     111    /// @return The repository root URL.
     112    ///
     113    std::string repository(const std::string& path);
     114
     115    ///
     116    /// @throws SVNException if session setup fails.
     117    ///
     118    void setup_ra_session(const std::string& path);
     119
     120    ///
     121    /// @throws SVNException if access setup fails.
    83122    ///
    84123    void setup_wc_adm_access(const std::string& path);
     
    111150    static SVN* instance_;
    112151
    113     // subversion API stuff
     152    // Subversion API stuff
     153
     154    // Info receiver
     155    struct info_receiver_baton {
     156      std::string repos_root_url;
     157    };
     158    static svn_error_t * info_receiver(void *baton, const char *path,
     159                                       const svn_info_t *info, apr_pool_t *pool);
     160
     161    // Log message receiver
     162    struct log_receiver_baton {
     163      std::vector<std::string> commit_dates;
     164    };
     165    static svn_error_t *
     166    log_message_receiver(void *baton, apr_hash_t *changed_paths,
     167                         svn_revnum_t rev, const char *author, const char *date,
     168                         const char *msg, apr_pool_t *pool);
     169
    114170    svn_wc_adm_access_t* adm_access_;
    115171    apr_allocator_t* allocator_;
    116172    svn_client_ctx_t* context_;
    117173    apr_pool_t* pool_;
     174    svn_ra_session_t* ra_session_;
    118175  };
    119176
Note: See TracChangeset for help on using the changeset viewer.