FreeBSD/contrib/subversion/subversion/libsvn_repos/config_pool.c
/* Set *CFG to the configuration stored in URL@HEAD and cache it in
 * CONFIG_POOL.  CASE_SENSITIVE controls
 * option and section name matching.  If PREFERRED_REPOS is given,
 * use that if it also matches URL.
 *
 * RESULT_POOL determines the lifetime of the returned reference and
 * SCRATCH_POOL is being used for temporary allocations.
 */
Set *CFG to the configuration stored in URL@HEAD and cache it in
CONFIG_POOL.  CASE_SENSITIVE controls
option and section name matching.  If PREFERRED_REPOS is given,
use that if it also matches URL.

RESULT_POOL determines the lifetime of the returned reference and
SCRATCH_POOL is being used for temporary allocations.
Set * CFG to the configuration stored in URL@HEAD and cache it in CONFIG_POOL . CASE_SENSITIVE controls option and section name matching . If PREFERRED_REPOS is given use that if it also matches URL . RESULT_POOL determines the lifetime of the returned reference and SCRATCH_POOL is being used for temporary allocations .
static svn_error_t *
find_repos_config(svn_config_t **cfg,
                  svn_membuf_t **key,
                  svn_repos__config_pool_t *config_pool,
                  const char *url,
                  svn_boolean_t case_sensitive,
                  svn_repos_t *preferred_repos,
                  apr_pool_t *result_pool,
                  apr_pool_t *scratch_pool)
{
  svn_repos_t *repos = NULL;
  svn_fs_t *fs;
  svn_fs_root_t *root;
  svn_revnum_t youngest_rev;
  svn_node_kind_t node_kind;
  const char *dirent;
  svn_stream_t *stream;
  const char *fs_path;
  const char *repos_root_dirent;
  svn_checksum_t *checksum;
  svn_stringbuf_t *contents;
  *cfg = NULL;
  SVN_ERR(svn_uri_get_dirent_from_file_url(&dirent, url, scratch_pool));
  if (preferred_repos)
    {
      repos_root_dirent = svn_repos_path(preferred_repos, scratch_pool);
      if (!svn_dirent_is_absolute(repos_root_dirent))
        SVN_ERR(svn_dirent_get_absolute(&repos_root_dirent,
                                        repos_root_dirent,
                                        scratch_pool));
      if (svn_dirent_is_ancestor(repos_root_dirent, dirent))
        repos = preferred_repos;
    }
  if (!repos)
    {
      repos_root_dirent = svn_repos_find_root_path(dirent, scratch_pool);
      SVN_ERR(svn_repos_open3(&repos, repos_root_dirent, NULL,
                              scratch_pool, scratch_pool));
    }
  fs_path = &dirent[strlen(repos_root_dirent)];
  fs = svn_repos_fs(repos);
  SVN_ERR(svn_fs_youngest_rev(&youngest_rev, fs, scratch_pool));
  SVN_ERR(svn_fs_revision_root(&root, fs, youngest_rev, scratch_pool));
  SVN_ERR(svn_fs_file_checksum(&checksum, svn_checksum_sha1, root, fs_path,
                               FALSE, scratch_pool));
  if (checksum)
    {
      *key = checksum_as_key(checksum, scratch_pool);
      SVN_ERR(svn_object_pool__lookup((void **)cfg, config_pool->object_pool,
                                      *key, &case_sensitive, result_pool));
    }
  if (!*cfg)
    {
      svn_filesize_t length;
      SVN_ERR(svn_fs_check_path(&node_kind, root, fs_path, scratch_pool));
      if (node_kind != svn_node_file)
        return SVN_NO_ERROR;
      SVN_ERR(svn_fs_file_length(&length, root, fs_path, scratch_pool));
      SVN_ERR(svn_fs_file_contents(&stream, root, fs_path, scratch_pool));
      SVN_ERR(svn_stringbuf_from_stream(&contents, stream,
                                        (apr_size_t)length, scratch_pool));
      SVN_ERR(auto_parse(cfg, key, config_pool, contents, case_sensitive,
                         result_pool, scratch_pool));
    }
  if (*cfg && checksum)
    SVN_MUTEX__WITH_LOCK(svn_object_pool__mutex(config_pool->object_pool),
                         add_checksum(config_pool, url, repos_root_dirent,
                                      youngest_rev, checksum));
  return SVN_NO_ERROR;
}
static svn_error_t * find_repos_config ( svn_config_t * * cfg , svn_membuf_t * * key , svn_repos__config_pool_t * config_pool , const char * url , svn_boolean_t case_sensitive , svn_repos_t * preferred_repos , apr_pool_t * result_pool , apr_pool_t * scratch_pool ) { svn_repos_t * repos = NULL ; svn_fs_t * fs ; svn_fs_root_t * root ; svn_revnum_t youngest_rev ; svn_node_kind_t node_kind ; const char * dirent ; svn_stream_t * stream ; const char * fs_path ; const char * repos_root_dirent ; svn_checksum_t * checksum ; svn_stringbuf_t * contents ; * cfg = NULL ; SVN_ERR ( svn_uri_get_dirent_from_file_url ( & dirent , url , scratch_pool ) ) ; if ( preferred_repos ) { repos_root_dirent = svn_repos_path ( preferred_repos , scratch_pool ) ; if ( ! svn_dirent_is_absolute ( repos_root_dirent ) ) SVN_ERR ( svn_dirent_get_absolute ( & repos_root_dirent , repos_root_dirent , scratch_pool ) ) ; if ( svn_dirent_is_ancestor ( repos_root_dirent , dirent ) ) repos = preferred_repos ; } if ( ! repos ) { repos_root_dirent = svn_repos_find_root_path ( dirent , scratch_pool ) ; SVN_ERR ( svn_repos_open3 ( & repos , repos_root_dirent , NULL , scratch_pool , scratch_pool ) ) ; } fs_path = & dirent [ strlen ( repos_root_dirent ) ] ; fs = svn_repos_fs ( repos ) ; SVN_ERR ( svn_fs_youngest_rev ( & youngest_rev , fs , scratch_pool ) ) ; SVN_ERR ( svn_fs_revision_root ( & root , fs , youngest_rev , scratch_pool ) ) ; SVN_ERR ( svn_fs_file_checksum ( & checksum , svn_checksum_sha1 , root , fs_path , FALSE , scratch_pool ) ) ; if ( checksum ) { * key = checksum_as_key ( checksum , scratch_pool ) ; SVN_ERR ( svn_object_pool__lookup ( ( void * * ) cfg , config_pool -> object_pool , * key , & case_sensitive , result_pool ) ) ; } if ( ! * cfg ) { svn_filesize_t length ; SVN_ERR ( svn_fs_check_path ( & node_kind , root , fs_path , scratch_pool ) ) ; if ( node_kind != svn_node_file ) return SVN_NO_ERROR ; SVN_ERR ( svn_fs_file_length ( & length , root , fs_path , scratch_pool ) ) ; SVN_ERR ( svn_fs_file_contents ( & stream , root , fs_path , scratch_pool ) ) ; SVN_ERR ( svn_stringbuf_from_stream ( & contents , stream , ( apr_size_t ) length , scratch_pool ) ) ; SVN_ERR ( auto_parse ( cfg , key , config_pool , contents , case_sensitive , result_pool , scratch_pool ) ) ; } if ( * cfg && checksum ) SVN_MUTEX__WITH_LOCK ( svn_object_pool__mutex ( config_pool -> object_pool ) , add_checksum ( config_pool , url , repos_root_dirent , youngest_rev , checksum ) ) ; return SVN_NO_ERROR ; }
Set *CFG to the configuration stored in URL@HEAD and cache it in
 CONFIG_POOL.
Set * CFG to the configuration stored in URL@HEAD and cache it in CONFIG_POOL .
/* maybe we can use the preferred repos instance instead of creating a
   * new one */ /* open repos if no suitable preferred repos was provided. */ /* Search for a repository in the full path. */ /* Attempt to open a repository at repos_root_dirent. */ /* Get the filesystem. */ /* Find HEAD and the revision root */ /* Fetch checksum and see whether we already have a matching config */ /* not parsed, yet? */ /* fetch the file contents */ /* handle it like ordinary file contents and cache it */ /* store the (path,rev) -> checksum mapping as well */