Changeset 191


Ignore:
Timestamp:
Sep 7, 2006, 1:14:45 PM (13 years ago)
Author:
Jari Häkkinen
Message:

Fixes #81. Changed behaviour of the cleanup functionalities in the SVN class.

Location:
trunk/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/SVN.cc

    r185 r191  
    6565
    6666    // initialize the repository access library
    67     if ((err=svn_ra_initialize(pool_))) {
    68       cleanup_failed_initialization(err);
    69       throw SVNException("SVN(void): svn_ra_initialize failed");
    70     }
     67    if ((err=svn_ra_initialize(pool_)))
     68      cleanup_failed_init(err, "SVN(void): svn_ra_initialize failed");
    7169
    7270    // Check that users .subversion exist. Should this really be done?
     
    7472    // command line option to change the location of the .subversion
    7573    // stuff (compare with the svn binary).
    76     if ((err=svn_config_ensure(NULL, pool_))) {
    77       cleanup_failed_initialization(err);
    78       throw SVNException("SVN(void): svn_config_ensure failed");
    79     }
     74    if ((err=svn_config_ensure(NULL, pool_)))
     75      cleanup_failed_init(err, "SVN(void): svn_config_ensure failed");
    8076
    8177    // create a client context object
    82     if ((err=svn_client_create_context(&context_, pool_))) {
    83       cleanup_failed_initialization(err);
    84       throw SVNException("SVN(void): svn_client_create_context failed");
    85     }
    86 
    87     if ((err=svn_config_get_config(&(context_->config), NULL, pool_))) {
    88       cleanup_failed_initialization(err);
    89       throw SVNException("SVN(void): svn_config_get_config failed");
    90     }
     78    if ((err=svn_client_create_context(&context_, pool_)))
     79      cleanup_failed_init(err, "SVN(void): svn_client_create_context failed");
     80
     81    if ((err=svn_config_get_config(&(context_->config), NULL, pool_)))
     82      cleanup_failed_init(err, "SVN(void): svn_config_get_config failed");
    9183
    9284    // set up authentication stuff
    9385    if ((err=svn_cmdline_setup_auth_baton(&(context_->auth_baton), false, NULL,
    9486                                          NULL, NULL, false,
    95             static_cast<svn_config_t*>(apr_hash_get(context_->config,
     87                        static_cast<svn_config_t*>(apr_hash_get(context_->config,
    9688                                                    SVN_CONFIG_CATEGORY_CONFIG,
    9789                                                    APR_HASH_KEY_STRING)),
    9890                                          context_->cancel_func,
    99                                           context_->cancel_baton, pool_))) {
    100       cleanup_failed_initialization(err);
    101       throw SVNException("SVN(void): svn_cmdline_setup_auth_baton failed");
    102     }
     91                                          context_->cancel_baton, pool_)))
     92      cleanup_failed_init(err, "SVN(void): svn_cmdline_setup_auth_baton failed");
    10393  }
    10494
     
    131121                                       false, receiver, baton, context_,
    132122                                       subpool);
    133     if (err && err->apr_err!=SVN_ERR_CLIENT_IS_BINARY_FILE) {
    134       cleanup(err,subpool);
    135       throw SVNException("SVN::client_blame: svn_client_blame3 failed");
    136     }
     123    if (err && err->apr_err!=SVN_ERR_CLIENT_IS_BINARY_FILE)
     124      // cleanup will throw an exception
     125      cleanup(err, subpool, "SVN::client_blame: svn_client_blame3 failed");
    137126    svn_pool_destroy(subpool);
    138127    return err;
     
    145134    apr_pool_t *subpool = svn_pool_create(pool_);
    146135    if (svn_error_t *err=svn_client_info(path.c_str(), NULL, NULL, receiver,
    147                                          baton, false, context_, subpool)) {
    148       cleanup(err,subpool);
    149       throw SVNException("repository: svn_client_info failed");
    150     }
     136                                         baton, false, context_, subpool))
     137      // cleanup will throw an exception
     138      cleanup(err, subpool, "repository: svn_client_info failed");
    151139    svn_pool_destroy(subpool);
    152140  }
     
    163151    svn_error_t *err=svn_client_proplist2(&properties, path.c_str(), &peg,
    164152                                          &revision, false, context_, subpool);
    165     if (err) {
    166       cleanup(err,subpool);
    167       throw SVNException("repository: svn_client_proplist2 failed");
    168     }
     153    if (err)
     154      cleanup(err, subpool, "repository: svn_client_proplist2 failed");
     155
    169156    for (int j = 0; j < properties->nelts; ++j) {
    170157      svn_client_proplist_item_t *item =
     
    179166                                         static_cast<const svn_string_t*>(val),
    180167                                         false, subpool);
    181         if (err) {
    182           cleanup(err,subpool);
    183           throw SVNException("property: svn_subst_detranslate_string failed");
    184         }
     168        if (err)
     169          cleanup(err, subpool, "property: svn_subst_detranslate_string failed");
    185170        property[static_cast<const char*>(key)]=value->data;
    186171      }
     
    209194    // call below, not needed for the functionality here.
    210195    if ((err=svn_ra_get_latest_revnum(ra_session_, &(head.value.number),
    211                                       subpool))) {
    212       cleanup(err,subpool);
    213       throw SVNException("commit_dates: svn_ra_get_latest_revnum failed");
    214     }
     196                                      subpool)))
     197      cleanup(err, subpool, "commit_dates: svn_ra_get_latest_revnum failed");
    215198    // The struct we want to pass through to all log_message_receiver
    216199    // calls, here we only want to push all commit dates into a
     
    220203    if ((err=svn_client_log3(apr_path, &peg, &start, &head, 0, false, true,
    221204                             log_message_receiver, static_cast<void*>(&lb),
    222                              context_, subpool))) {
    223       cleanup(err,subpool);
    224       throw SVNException("commit_dates: svn_client_log3 failed");
    225     }
     205                             context_, subpool)))
     206      // cleanupp will throw an exception
     207      cleanup(err, subpool, "commit_dates: svn_client_log3 failed");
    226208    svn_pool_destroy(subpool);
    227209    return lb.commit_dates;
     
    229211
    230212
    231   void SVN::cleanup(svn_error_t *err,apr_pool_t *pool)
     213  void SVN::cleanup(svn_error_t *err,apr_pool_t *pool,
     214                    const std::string& message)
    232215  {
    233216    svn_handle_error2(err,stderr,false,"svndigest:");
    234217    svn_error_clear(err);
    235     svn_pool_destroy(pool);
    236   }
    237 
    238 
    239   void SVN::cleanup_failed_initialization(svn_error_t *err)
     218    if (pool)
     219      svn_pool_destroy(pool);
     220    if (message.length()>0)
     221      throw SVNException(message);
     222  }
     223
     224
     225  void SVN::cleanup_failed_init(svn_error_t *err, const std::string& message)
    240226  {
    241227    cleanup(err,pool_);
    242228    apr_allocator_destroy(allocator_);
     229    throw SVNException(message);
    243230  }
    244231
     
    261248    // get a session to the repository
    262249    if (svn_error_t *err=svn_client_open_ra_session(&ra_session_, path.c_str(),
    263                                                     context_,pool_)) {
    264       // cleanup could be called if a null pool can be passed to
    265       // svn_pool_destroy (which is just a #define to apr_pool_destroy
    266       svn_handle_error2(err,stderr,false,"svndigest:");
    267       svn_error_clear(err);
    268       throw SVNException("setup_ra_session: svn_client_open_ra_session failed");
    269     }
     250                                                    context_,pool_))
     251      cleanup(err, NULL, "setup_ra_session: svn_client_open_ra_session failed");
    270252  }
    271253
     
    278260    if (svn_error_t *err=svn_wc_adm_open3(&adm_access_, NULL, canonical_path,
    279261                                          false, -1, context_->cancel_func,
    280                                           context_->cancel_baton, pool_)) {
    281       // cleanup could be called if a null pool can be passed to
    282       // svn_pool_destroy (which is just a #define to apr_pool_destroy
    283       svn_handle_error2(err,stderr,false,"svndigest:");
    284       svn_error_clear(err);
    285       throw SVNException("setup_wc_adm_access: svn_wc_adm_open3 failed");
    286     }
     262                                          context_->cancel_baton, pool_))
     263      cleanup(err, NULL, "setup_wc_adm_access: svn_wc_adm_open3 failed");
    287264  }
    288265
     
    294271    if (svn_error_t *err=
    295272        svn_wc_status2(&status,svn_path_internal_style(path.c_str(), subpool),
    296                        adm_access_, subpool)) {
    297       cleanup(err,subpool);
    298       throw SVNException("version_controlled(): svn_config_get_config failed");
    299     }
     273                       adm_access_, subpool))
     274      // cleanup will throw an exception
     275      cleanup(err, subpool,"version_controlled(): svn_config_get_config failed");
    300276    svn_pool_destroy(subpool);
    301277
  • trunk/lib/SVN.h

    r185 r191  
    180180    /**
    181181       @brief Free resources when svn API calls fail.
     182
     183       This function will write an error message to stdout, free \a
     184       err and \a pool resources. If \a err or \a pool are a NULL
     185       pointers the function will do nothing with these resources.
     186
     187       cleanup will throw a SVNException if \a message has
     188       length>0. The default bahaviour is to free resources and return
     189       normally.
     190
     191       @see SVNException
    182192    */
    183     void cleanup(svn_error_t *err,apr_pool_t *pool);
     193    void cleanup(svn_error_t *err, apr_pool_t *pool,
     194                 const std::string& message=std::string());
    184195
    185196    /**
    186197       @brief Free resources when failing to reach end of
    187198       constructor.
     199
     200       cleanup_failed_init will free all resource acquired in the
     201       constructor and throw an SVNException with \a message as the
     202       message.
     203
     204       @see SVNException
    188205    */
    189     void cleanup_failed_initialization(svn_error_t *err);
     206    void cleanup_failed_init(svn_error_t *err, const std::string& message);
    190207
    191208    static SVN* instance_;
Note: See TracChangeset for help on using the changeset viewer.