<commit_before>/*
 * ra-dav-local.c :  basic tests for the RA LOCAL library
 *
 * ====================================================================
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://subversion.tigris.org/license-1.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://subversion.tigris.org/.
 * ====================================================================
 */




#include <apr_general.h>
#include <apr_pools.h>

#ifdef _MSC_VER
#include <direct.h>
#define getcwd _getcwd
#else
#include <unistd.h> /* for getcwd() */
#endif

#include "svn_string.h"
#include "svn_utf.h"
#include "svn_error.h"
#include "svn_delta.h"
#include "svn_ra.h"
#include "svn_client.h"

#include "../svn_test.h"
#include "../svn_test_fs.h"
#include "../../libsvn_ra_local/ra_local.h"

/*-------------------------------------------------------------------*/


/** Helper routines. **/


/* Helper function.  Set URL to a "file://" url for the current directory,
   suffixed by the forward-slash-style relative path SUFFIX, performing all
   allocation in POOL. */
static svn_error_t *
current_directory_url(const char **url,
                      const char *suffix,
                      apr_pool_t *pool)
{
  /* 8KB is a lot, but it almost guarantees that any path will fit. */
  char curdir[8192];
  const char *utf8_ls_curdir, *utf8_is_curdir, *unencoded_url;
  
  if (! getcwd(curdir, sizeof(curdir)))
    return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed");

  SVN_ERR(svn_utf_cstring_to_utf8(&utf8_ls_curdir, curdir, pool));
  utf8_is_curdir = svn_path_internal_style(utf8_ls_curdir, pool);

  unencoded_url = apr_psprintf(pool, "file://%s%s%s%s",
                               (utf8_is_curdir[0] != '/') ? "/" : "",
                               utf8_is_curdir,
                               (suffix[0] && suffix[0] != '/') ? "/" : "",
                               suffix);

  *url = svn_path_uri_encode(unencoded_url, pool);

  return SVN_NO_ERROR;
}


static svn_error_t *
make_and_open_local_repos(svn_ra_plugin_t **plugin,
                          void **session,
                          const char *repos_name,
                          const char *fs_type,
                          apr_pool_t *pool)
{
  svn_repos_t *repos;
  void *ra_baton;
  const char *url;
  svn_ra_callbacks_t *cbtable = apr_pcalloc(pool, sizeof(*cbtable));

  SVN_ERR(svn_test__create_repos(&repos, repos_name, fs_type, pool));
  SVN_ERR(svn_ra_init_ra_libs(&ra_baton, pool));

  /* Get the plugin which handles "file:" URLs */
  SVN_ERR(svn_ra_get_ra_library(plugin, ra_baton, "file:", pool));

  SVN_ERR(current_directory_url(&url, repos_name, pool));

  /* Open an RA session into this repository. */
  SVN_ERR((*plugin)->open(session, url, cbtable, NULL, NULL, pool));

  return SVN_NO_ERROR;
}


/*-------------------------------------------------------------------*/


/** The tests **/

/* Open an RA session to a local repository. */
static svn_error_t *
open_ra_session(const char **msg, 
                svn_boolean_t msg_only, 
                svn_test_opts_t *opts,
                apr_pool_t *pool)
{
  svn_ra_plugin_t *plugin;
  void *session;

  *msg = "open an ra session to a local repository";

  if (msg_only)
    return SVN_NO_ERROR;

  SVN_ERR(make_and_open_local_repos(&plugin, &session,
                                    "test-repo-open", opts->fs_type, pool));

  return SVN_NO_ERROR;
}


/* Discover the youngest revision in a repository.  */
static svn_error_t *
get_youngest_rev(const char **msg, 
                 svn_boolean_t msg_only,
                 svn_test_opts_t *opts, 
                 apr_pool_t *pool)
{
  svn_ra_plugin_t *plugin;
  void *session;
  svn_revnum_t latest_rev;

  *msg = "get the youngest revision in a repository";

  if (msg_only)
    return SVN_NO_ERROR;

  SVN_ERR(make_and_open_local_repos(&plugin, &session,
                                    "test-repo-getrev", opts->fs_type,
                                    pool));

  /* Get the youngest revision and make sure it's 0. */
  SVN_ERR(plugin->get_latest_revnum(session, &latest_rev, pool));
  
  if (latest_rev != 0)
    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,
                            "youngest rev isn't 0!");

  return SVN_NO_ERROR;
}


/* Helper function.  Run svn_ra_local__split_URL with interest only in
   the return error code */
static apr_status_t
try_split_url(const char *url, apr_pool_t *pool)
{
  svn_repos_t *repos;
  const char *repos_path, *fs_path;
  svn_error_t *err;
  apr_status_t apr_err;

  err = svn_ra_local__split_URL(&repos, &repos_path, &fs_path, url, pool);

  if (! err)
    return SVN_NO_ERROR;

  apr_err = err->apr_err;
  svn_error_clear(err);
  return apr_err;<commit_msg>Update ra_local C test to modern RA API.<commit_after>/*
 * ra-dav-local.c :  basic tests for the RA LOCAL library
 *
 * ====================================================================
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 *
 * This software is licensed as described in the file COPYING, which
 * you should have received as part of this distribution.  The terms
 * are also available at http://subversion.tigris.org/license-1.html.
 * If newer versions of this license are posted there, you may use a
 * newer version instead, at your option.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://subversion.tigris.org/.
 * ====================================================================
 */




#include <apr_general.h>
#include <apr_pools.h>

#ifdef _MSC_VER
#include <direct.h>
#define getcwd _getcwd
#else
#include <unistd.h> /* for getcwd() */
#endif

#include "svn_string.h"
#include "svn_utf.h"
#include "svn_error.h"
#include "svn_delta.h"
#include "svn_ra.h"
#include "svn_client.h"

#include "../svn_test.h"
#include "../svn_test_fs.h"
#include "../../libsvn_ra_local/ra_local.h"

/*-------------------------------------------------------------------*/


/** Helper routines. **/


/* Helper function.  Set URL to a "file://" url for the current directory,
   suffixed by the forward-slash-style relative path SUFFIX, performing all
   allocation in POOL. */
static svn_error_t *
current_directory_url(const char **url,
                      const char *suffix,
                      apr_pool_t *pool)
{
  /* 8KB is a lot, but it almost guarantees that any path will fit. */
  char curdir[8192];
  const char *utf8_ls_curdir, *utf8_is_curdir, *unencoded_url;
  
  if (! getcwd(curdir, sizeof(curdir)))
    return svn_error_create(SVN_ERR_BASE, NULL, "getcwd() failed");

  SVN_ERR(svn_utf_cstring_to_utf8(&utf8_ls_curdir, curdir, pool));
  utf8_is_curdir = svn_path_internal_style(utf8_ls_curdir, pool);

  unencoded_url = apr_psprintf(pool, "file://%s%s%s%s",
                               (utf8_is_curdir[0] != '/') ? "/" : "",
                               utf8_is_curdir,
                               (suffix[0] && suffix[0] != '/') ? "/" : "",
                               suffix);

  *url = svn_path_uri_encode(unencoded_url, pool);

  return SVN_NO_ERROR;
}


static svn_error_t *
make_and_open_local_repos(svn_ra_session_t **session,
                          const char *repos_name,
                          const char *fs_type,
                          apr_pool_t *pool)
{
  svn_repos_t *repos;
  const char *url;
  svn_ra_callbacks2_t *cbtable;
  
  SVN_ERR(svn_ra_create_callbacks(&cbtable, pool));

  SVN_ERR(svn_test__create_repos(&repos, repos_name, fs_type, pool));
  SVN_ERR(svn_ra_initialize(pool));

  SVN_ERR(current_directory_url(&url, repos_name, pool));
  
  SVN_ERR(svn_ra_open2(session,
                       url,
                       cbtable,
                       NULL,
                       NULL,
                       pool));

  return SVN_NO_ERROR;
}


/*-------------------------------------------------------------------*/


/** The tests **/

/* Open an RA session to a local repository. */
static svn_error_t *
open_ra_session(const char **msg, 
                svn_boolean_t msg_only, 
                svn_test_opts_t *opts,
                apr_pool_t *pool)
{
  svn_ra_session_t *session;

  *msg = "open an ra session to a local repository";

  if (msg_only)
    return SVN_NO_ERROR;

  SVN_ERR(make_and_open_local_repos(&session,
                                    "test-repo-open", opts->fs_type, pool));

  return SVN_NO_ERROR;
}


/* Discover the youngest revision in a repository.  */
static svn_error_t *
get_youngest_rev(const char **msg, 
                 svn_boolean_t msg_only,
                 svn_test_opts_t *opts, 
                 apr_pool_t *pool)
{
  svn_ra_session_t *session;
  svn_revnum_t latest_rev;

  *msg = "get the youngest revision in a repository";

  if (msg_only)
    return SVN_NO_ERROR;

  SVN_ERR(make_and_open_local_repos(&session,
                                    "test-repo-getrev", opts->fs_type,
                                    pool));

  /* Get the youngest revision and make sure it's 0. */
  SVN_ERR(svn_ra_get_latest_revnum(session, &latest_rev, pool));
  
  if (latest_rev != 0)
    return svn_error_create(SVN_ERR_FS_GENERAL, NULL,
                            "youngest rev isn't 0!");

  return SVN_NO_ERROR;
}


/* Helper function.  Run svn_ra_local__split_URL with interest only in
   the return error code */
static apr_status_t
try_split_url(const char *url, apr_pool_t *pool)
{
  svn_repos_t *repos;
  const char *repos_path, *fs_path;
  svn_error_t *err;
  apr_status_t apr_err;

  err = svn_ra_local__split_URL(&repos, &repos_path, &fs_path, url, pool);

  if (! err)
    return SVN_NO_ERROR;

  apr_err = err->apr_err;
  svn_error_clear(err);
  return apr_err;
{'fraction_non_alphanumeric': 0.15523324186593493, 'fraction_numerical': 0.005684045472363779, 'mean_word_length': 2.4817468440805186, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3307128', 'n_tokens_mistral': 3521, 'n_tokens_neox': 3353, 'n_words': 811}