<commit_before>/*
 * ====================================================================
 * Copyright (c) 2005 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 "svn_cmdline.h"
#include "svn_config.h"
#include "svn_client.h"
#include "svn_pools.h"
#include "svn_delta.h"
#include "svn_path.h"
#include "svn_auth.h"
#include "svn_opt.h"
#include "svn_ra.h"

#include "svn_private_config.h"

#include <apr_network_io.h>
#include <apr_signal.h>
#include <apr_uuid.h>

#define PROP_PREFIX            "svn:sync-"

#define LOCK_PROP              PROP_PREFIX "lock"
#define FROM_URL_PROP          PROP_PREFIX "from-url"
#define FROM_UUID_PROP         PROP_PREFIX "from-uuid"
#define LAST_MERGED_REV_PROP   PROP_PREFIX "last-merged-rev"
#define CURRENTLY_COPYING_PROP PROP_PREFIX "currently-copying"

static svn_opt_subcommand_t initialize, synchronize, help;

enum {
  svnsync_opt_source_url       = SVN_OPT_FIRST_LONGOPT_ID,
  svnsync_opt_non_interactive,
  svnsync_opt_no_auth_cache,
  svnsync_opt_auth_username,
  svnsync_opt_auth_password,
  svnsync_opt_config_dir,
  svnsync_opt_version
};

#define SVNSYNC_OPTS_DEFAULT svnsync_opt_non_interactive, \
                             svnsync_opt_no_auth_cache, \
                             svnsync_opt_auth_username, \
                             svnsync_opt_auth_password, \
                             svnsync_opt_config_dir

static const svn_opt_subcommand_desc_t svnsync_cmd_table[] =
  {
    { "initialize", initialize, { "init" },
      N_("usage: svnsync initialize DEST_URL --source-url SOURCE_URL\n"
         "Initialize a destination repository.\n"),
      { SVNSYNC_OPTS_DEFAULT,
        svnsync_opt_source_url } },
    { "synchronize", synchronize, { "sync" },
      N_("usage: svnsync synchronize DEST_URL\n"
         "Transfer all pending revisions from source to destination.\n"),
      { SVNSYNC_OPTS_DEFAULT } },
    { "help", help, { "?", "h" },
      N_("usage: svnsync help [SUBCOMMAND...]\n"
         "Describe the usage of this program or its subcommands.\n"),
      { svnsync_opt_version } },
    { NULL, NULL, { 0 }, NULL, { 0 } } 
  };

static const apr_getopt_option_t svnsync_options[] =
  {
    {"source-url",     svnsync_opt_source_url, 1,
                       N_("The url to synchronize from")},
    {"non-interactive", svnsync_opt_non_interactive, 0,
                       N_("do no interactive prompting") },
    {"no-auth-cache",  svnsync_opt_no_auth_cache, 0,
                       N_("do not cache authentication tokens") },
    {"username",       svnsync_opt_auth_username, 1,
                       N_("specify a username ARG") },
    {"password",       svnsync_opt_auth_password, 1,
                       N_("specify a password ARG") },
    {"config-dir",     svnsync_opt_config_dir, 1,
                       N_("read user configuration files from directory ARG")},
    {"version",        svnsync_opt_version, 0,
                       N_("show version information")},
    {"help",           'h', 0,
                       N_("show help on a subcommand")},
    {NULL,             '?', 0,
                       N_("show help on a subcommand")},
    { 0, 0, 0, 0 }
  };

typedef struct {
  const char *source_url;
  svn_auth_baton_t *auth_baton;
  svn_boolean_t non_interactive;
  svn_boolean_t no_auth_cache;
  const char *auth_username;
  const char *auth_password;
  const char *config_dir;
  apr_hash_t *config;
  svn_boolean_t version;
  svn_boolean_t help;
} opt_baton_t;

static volatile sig_atomic_t cancelled = FALSE;

static void
signal_handler (int signum)
{
  apr_signal (signum, SIG_IGN);
  cancelled = TRUE;
}

static svn_error_t *
check_cancel (void *baton)
{
  if (cancelled)
    return svn_error_create (SVN_ERR_CANCELLED, NULL, _("Caught signal"));
  else
    return SVN_NO_ERROR;
}

static svn_error_t *
check_lib_versions (void)
{
  static const svn_version_checklist_t checklist[] =
    {
      { "svn_subr",  svn_subr_version },
      { "svn_delta", svn_delta_version },
      { "svn_ra",    svn_ra_version },
      { NULL, NULL }
    };

  SVN_VERSION_DEFINE (my_version);

  return svn_ver_check_list (&my_version, checklist);
}

static svn_error_t *
get_lock (svn_ra_session_t *session, apr_pool_t *pool)
{
  const char *uuid_str;
  char hostname_str[APRMAXHOSTLEN + 1] = { 0 };
  svn_string_t *mylocktoken, *reposlocktoken;
  apr_status_t apr_err;
  apr_pool_t *subpool;
  int i;

  apr_err = apr_gethostname (hostname_str, sizeof (hostname_str), pool);
  if (apr_err)
    return svn_error_wrap_apr (apr_err, _("Can't get local hostname"));

  mylocktoken = svn_string_createf (pool, "%s:%s", hostname_str, 
                                    svn_uuid_generate (pool));

  subpool = svn_pool_create (pool);

  for (i = 0; i < 10; ++i)
    {
      svn_pool_clear (subpool);

      SVN_ERR (svn_ra_rev_prop (session, 0, LOCK_PROP, &reposlocktoken,
                                subpool));

      if (reposlocktoken)
        {
          /* Did we get it?   If so, we're done, otherwise we sleep. */

          if (strcmp (reposlocktoken->data, mylocktoken->data) == 0)
            return SVN_NO_ERROR;
          else<commit_msg>Remove an unused variable that's breaking my '-Wall -Werror' build. Followup to r18105.<commit_after>/*
 * ====================================================================
 * Copyright (c) 2005 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 "svn_cmdline.h"
#include "svn_config.h"
#include "svn_client.h"
#include "svn_pools.h"
#include "svn_delta.h"
#include "svn_path.h"
#include "svn_auth.h"
#include "svn_opt.h"
#include "svn_ra.h"

#include "svn_private_config.h"

#include <apr_network_io.h>
#include <apr_signal.h>
#include <apr_uuid.h>

#define PROP_PREFIX            "svn:sync-"

#define LOCK_PROP              PROP_PREFIX "lock"
#define FROM_URL_PROP          PROP_PREFIX "from-url"
#define FROM_UUID_PROP         PROP_PREFIX "from-uuid"
#define LAST_MERGED_REV_PROP   PROP_PREFIX "last-merged-rev"
#define CURRENTLY_COPYING_PROP PROP_PREFIX "currently-copying"

static svn_opt_subcommand_t initialize, synchronize, help;

enum {
  svnsync_opt_source_url       = SVN_OPT_FIRST_LONGOPT_ID,
  svnsync_opt_non_interactive,
  svnsync_opt_no_auth_cache,
  svnsync_opt_auth_username,
  svnsync_opt_auth_password,
  svnsync_opt_config_dir,
  svnsync_opt_version
};

#define SVNSYNC_OPTS_DEFAULT svnsync_opt_non_interactive, \
                             svnsync_opt_no_auth_cache, \
                             svnsync_opt_auth_username, \
                             svnsync_opt_auth_password, \
                             svnsync_opt_config_dir

static const svn_opt_subcommand_desc_t svnsync_cmd_table[] =
  {
    { "initialize", initialize, { "init" },
      N_("usage: svnsync initialize DEST_URL --source-url SOURCE_URL\n"
         "Initialize a destination repository.\n"),
      { SVNSYNC_OPTS_DEFAULT,
        svnsync_opt_source_url } },
    { "synchronize", synchronize, { "sync" },
      N_("usage: svnsync synchronize DEST_URL\n"
         "Transfer all pending revisions from source to destination.\n"),
      { SVNSYNC_OPTS_DEFAULT } },
    { "help", help, { "?", "h" },
      N_("usage: svnsync help [SUBCOMMAND...]\n"
         "Describe the usage of this program or its subcommands.\n"),
      { svnsync_opt_version } },
    { NULL, NULL, { 0 }, NULL, { 0 } } 
  };

static const apr_getopt_option_t svnsync_options[] =
  {
    {"source-url",     svnsync_opt_source_url, 1,
                       N_("The url to synchronize from")},
    {"non-interactive", svnsync_opt_non_interactive, 0,
                       N_("do no interactive prompting") },
    {"no-auth-cache",  svnsync_opt_no_auth_cache, 0,
                       N_("do not cache authentication tokens") },
    {"username",       svnsync_opt_auth_username, 1,
                       N_("specify a username ARG") },
    {"password",       svnsync_opt_auth_password, 1,
                       N_("specify a password ARG") },
    {"config-dir",     svnsync_opt_config_dir, 1,
                       N_("read user configuration files from directory ARG")},
    {"version",        svnsync_opt_version, 0,
                       N_("show version information")},
    {"help",           'h', 0,
                       N_("show help on a subcommand")},
    {NULL,             '?', 0,
                       N_("show help on a subcommand")},
    { 0, 0, 0, 0 }
  };

typedef struct {
  const char *source_url;
  svn_auth_baton_t *auth_baton;
  svn_boolean_t non_interactive;
  svn_boolean_t no_auth_cache;
  const char *auth_username;
  const char *auth_password;
  const char *config_dir;
  apr_hash_t *config;
  svn_boolean_t version;
  svn_boolean_t help;
} opt_baton_t;

static volatile sig_atomic_t cancelled = FALSE;

static void
signal_handler (int signum)
{
  apr_signal (signum, SIG_IGN);
  cancelled = TRUE;
}

static svn_error_t *
check_cancel (void *baton)
{
  if (cancelled)
    return svn_error_create (SVN_ERR_CANCELLED, NULL, _("Caught signal"));
  else
    return SVN_NO_ERROR;
}

static svn_error_t *
check_lib_versions (void)
{
  static const svn_version_checklist_t checklist[] =
    {
      { "svn_subr",  svn_subr_version },
      { "svn_delta", svn_delta_version },
      { "svn_ra",    svn_ra_version },
      { NULL, NULL }
    };

  SVN_VERSION_DEFINE (my_version);

  return svn_ver_check_list (&my_version, checklist);
}

static svn_error_t *
get_lock (svn_ra_session_t *session, apr_pool_t *pool)
{
  char hostname_str[APRMAXHOSTLEN + 1] = { 0 };
  svn_string_t *mylocktoken, *reposlocktoken;
  apr_status_t apr_err;
  apr_pool_t *subpool;
  int i;

  apr_err = apr_gethostname (hostname_str, sizeof (hostname_str), pool);
  if (apr_err)
    return svn_error_wrap_apr (apr_err, _("Can't get local hostname"));

  mylocktoken = svn_string_createf (pool, "%s:%s", hostname_str, 
                                    svn_uuid_generate (pool));

  subpool = svn_pool_create (pool);

  for (i = 0; i < 10; ++i)
    {
      svn_pool_clear (subpool);

      SVN_ERR (svn_ra_rev_prop (session, 0, LOCK_PROP, &reposlocktoken,
                                subpool));

      if (reposlocktoken)
        {
          /* Did we get it?   If so, we're done, otherwise we sleep. */

          if (strcmp (reposlocktoken->data, mylocktoken->data) == 0)
            return SVN_NO_ERROR;
          else
{'fraction_non_alphanumeric': 0.12365498090940645, 'fraction_numerical': 0.0051197500867754256, 'mean_word_length': 2.896213657876944, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6312676', 'n_tokens_mistral': 4003, 'n_tokens_neox': 3876, 'n_words': 896}