Advertisement
Guest User

Svn API problem

a guest
Feb 19th, 2011
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #include "svn_client.h"
  2. #include "svn_cmdline.h"
  3. #include "svn_pools.h"
  4.  
  5. int main(int, char *[])
  6. {
  7.   svn_error_t *err = 0;
  8.  
  9.   //  Init subversion.
  10.   svn_cmdline_init( "test", stderr );
  11.   //  Crete memory pool for all ARP operations.
  12.   apr_pool_t *pool = svn_pool_create( 0 );
  13.  
  14.   //  Create subversion context for operations.
  15.   svn_client_ctx_t* ctx = 0;
  16.   err = svn_client_create_context( & ctx, pool );
  17.  
  18.   //  Load the run-time config file into context.
  19.   err = svn_config_get_config( & ctx->config, 0, pool );
  20.  
  21.   //  Get configuration back from context.
  22.   svn_config_t *config = (svn_config_t*)apr_hash_get
  23.   (
  24.     ctx->config,
  25.     SVN_CONFIG_CATEGORY_CONFIG,
  26.     APR_HASH_KEY_STRING
  27.   );
  28.  
  29.   err = svn_cmdline_create_auth_baton
  30.   (
  31.     & ctx->auth_baton,
  32.     //  non-interactive
  33.     TRUE,
  34.     //  username
  35.     "username",
  36.     //  password
  37.     "password",
  38.     //  dir to read config from
  39.     "",
  40.     //  no auth cache
  41.     TRUE,
  42.     //  trust server certificate
  43.     TRUE,
  44.     //  config
  45.     config,
  46.     //  cancel function, |svn_cancel_func_t|
  47.     0,
  48.     //  cancel baton, |void*|
  49.     0,
  50.     //  pool
  51.     pool
  52.   );
  53.  
  54.  
  55.   svn_opt_revision_t revision;
  56.   revision.kind = svn_opt_revision_head;
  57.   apr_hash_t* results = 0;
  58.  
  59.   //  First test: issue subversion "ls" command.
  60.   err = svn_client_ls
  61.   (
  62.     & results,
  63.     //  Give non-existant URL intentionaly to get error.
  64.     "http://wrong.url",
  65.     & revision,
  66.     //  Recursion.
  67.     FALSE,
  68.     ctx,
  69.     pool
  70.   );
  71.  
  72.   //  This will correctly display "Could not resolve hostname 'wrong.url'".
  73.   if( err )
  74.   {
  75.     svn_handle_error2( err, stderr, 0, "ls: " );
  76.   }
  77.  
  78.   apr_array_header_t* poPaths = apr_array_make( pool, 0, sizeof( char* ) );
  79.   //  Give non-existing path to get error.
  80.   const char* pPath = apr_pstrdup( pool, "wrong path" );
  81.   *(const char**)apr_array_push( poPaths ) = pPath;
  82.  
  83.   //  Second test: issue subversion "up" command.
  84.   err = svn_client_update3
  85.   (
  86.     //o Revisions.
  87.     0,
  88.     //i List of target paths.
  89.     poPaths,
  90.     //i Revision to get.
  91.     & oRevision,
  92.     //i Update depth.
  93.     svn_depth_infinity,
  94.     //i depth is sticky.
  95.     FALSE,
  96.     //i ignore externals.
  97.     TRUE,
  98.     //i allow unversioned obstructions,
  99.     TRUE,
  100.     //i context.
  101.     ctx,
  102.     //i pool
  103.     pool
  104.   );
  105.  
  106.   //  This will NOT work. Why? svn_client_update3() can't success with
  107.   //  non-existing path.
  108.   if( err )
  109.   {
  110.     svn_handle_error2( err, stderr, 0, "update: " );
  111.   }
  112.  
  113.   return EXIT_SUCCESS;
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement