<commit_before>/*
 * questions.c:  routines for asking questions about working copies
 *
 * ====================================================================
 * Copyright (c) 2000-2004, 2006, 2008 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 <string.h>
#include <apr_pools.h>
#include <apr_file_io.h>
#include <apr_file_info.h>
#include <apr_time.h>
#include "svn_pools.h"
#include "svn_types.h"
#include "svn_string.h"
#include "svn_error.h"
#include "svn_dirent_uri.h"
#include "svn_path.h"
#include "svn_time.h"
#include "svn_io.h"
#include "svn_props.h"

#include "wc.h"
#include "adm_files.h"
#include "questions.h"
#include "entries.h"
#include "props.h"
#include "translate.h"
#include "wc_db.h"

#include "svn_private_config.h"
#include "private/svn_wc_private.h"



/* ### todo: make this compare repository too?  Or do so in parallel
   code.  */
svn_error_t *
svn_wc_check_wc(const char *path,
                int *wc_format,
                apr_pool_t *pool)
{
  svn_error_t *err;
  svn_node_kind_t kind;

  err = svn_wc__db_version(wc_format, path, pool);
  if (err && err->apr_err != SVN_ERR_WC_MISSING)
    return err;

  if (err)
    {
      svn_error_clear(err);

      /* Check path itself exists. */
      SVN_ERR(svn_io_check_path(path, &kind, pool));

      if (kind == svn_node_none)
        {
          return svn_error_createf
            (APR_ENOENT, NULL, _("'%s' does not exist"),
            svn_path_local_style(path, pool));
        }

      /* If the metadata does not exist or path not directory, then for
         our purposes this is not a working copy, so return 0. */
      *wc_format = 0;
      return SVN_NO_ERROR;
    }
  else
    {
      /* If we managed to read the format we assume that we
          are dealing with a real wc so we can return a nice
          error. */
      return svn_wc__check_format(*wc_format, path, pool);
    }
}


svn_error_t *
svn_wc__check_format(int wc_format, const char *path, apr_pool_t *pool)
{
  if (wc_format < 2)
    {
      return svn_error_createf<commit_msg>Fix a valgrind Unitialized Memory Read seen in various places, e.g.<commit_after>/*
 * questions.c:  routines for asking questions about working copies
 *
 * ====================================================================
 * Copyright (c) 2000-2004, 2006, 2008 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 <string.h>
#include <apr_pools.h>
#include <apr_file_io.h>
#include <apr_file_info.h>
#include <apr_time.h>
#include "svn_pools.h"
#include "svn_types.h"
#include "svn_string.h"
#include "svn_error.h"
#include "svn_dirent_uri.h"
#include "svn_path.h"
#include "svn_time.h"
#include "svn_io.h"
#include "svn_props.h"

#include "wc.h"
#include "adm_files.h"
#include "questions.h"
#include "entries.h"
#include "props.h"
#include "translate.h"
#include "wc_db.h"

#include "svn_private_config.h"
#include "private/svn_wc_private.h"



/* ### todo: make this compare repository too?  Or do so in parallel
   code.  */
svn_error_t *
svn_wc_check_wc(const char *path,
                int *wc_format,
                apr_pool_t *pool)
{
  svn_error_t *err;
  svn_node_kind_t kind;

  err = svn_wc__db_version(wc_format, path, pool);
  if (err && err->apr_err != SVN_ERR_WC_MISSING)
    return err;

  if (err)
    {
      svn_error_clear(err);

      /* If the format file does not exist or path not directory, then for
         our purposes this is not a working copy, so return 0. */
      *wc_format = 0;

      /* Check path itself exists. */
      SVN_ERR(svn_io_check_path(path, &kind, pool));

      if (kind == svn_node_none)
        {
          return svn_error_createf
            (APR_ENOENT, NULL, _("'%s' does not exist"),
            svn_path_local_style(path, pool));
        }

      return SVN_NO_ERROR;
    }
  else
    {
      /* If we managed to read the format we assume that we
          are dealing with a real wc so we can return a nice
          error. */
      return svn_wc__check_format(*wc_format, path, pool);
    }
}


svn_error_t *
svn_wc__check_format(int wc_format, const char *path, apr_pool_t *pool)
{
  if (wc_format < 2)
    {
      return svn_error_createf
{'fraction_non_alphanumeric': 0.150374531835206, 'fraction_numerical': 0.00749063670411985, 'mean_word_length': 3.30378726833199, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5878731', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1766, 'n_words': 528}