Changeset 123 for trunk/lib/SVN.cc


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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  }
Note: See TracChangeset for help on using the changeset viewer.