<commit_before>/*
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 */

#include "svn_repos.h"

#include "svnrdump.h"

void
write_hash_to_stringbuf(apr_hash_t *properties,
                        svn_boolean_t deleted,
                        svn_stringbuf_t **strbuf,
                        apr_pool_t *pool)
{
  apr_hash_index_t *this;
  const void *key;
  void *val;
  apr_ssize_t keylen;
  svn_string_t *value;

  if (!deleted) {
    for (this = apr_hash_first(pool, properties); this;
         this = apr_hash_next(this)) {
      /* Get this key and val. */
      apr_hash_this(this, &key, &keylen, &val);
      value = val;

      /* Output name length, then name. */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "K %" APR_SSIZE_T_FMT "\n",
                    keylen));

      svn_stringbuf_appendbytes(*strbuf, (const char *) key, keylen);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);

      /* Output value length, then value. */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "V %" APR_SIZE_T_FMT "\n",
                    value->len));

      svn_stringbuf_appendbytes(*strbuf, value->data, value->len);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);
    }
  }
  else {
    /* Output a "D " entry for each deleted property */
    for (this = apr_hash_first(pool, properties); this;
         this = apr_hash_next(this)) {
      /* Get this key */
      apr_hash_this(this, &key, &keylen, NULL);

      /* Output name length, then name */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "D %" APR_SSIZE_T_FMT "\n",
                    keylen));

      svn_stringbuf_appendbytes(*strbuf, (const char *) key, keylen);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);
    }
  }
}

svn_error_t *
dump_props(struct dump_edit_baton *eb,
           svn_boolean_t *trigger_var,
           svn_boolean_t dump_data_too,
           apr_pool_t *pool)
{
  if (trigger_var && !*trigger_var)
    return SVN_NO_ERROR;

  /* Build a propstring to print */
  svn_stringbuf_setempty(eb->propstring);
  write_hash_to_stringbuf(eb->properties,
        FALSE,
        &(eb->propstring), eb->pool);
  write_hash_to_stringbuf(eb->del_properties,
        TRUE,
        &(eb->propstring), eb->pool);
  svn_stringbuf_appendbytes(eb->propstring, "PROPS-END\n", 10);

  /* prop-delta header */
  SVN_ERR(svn_stream_printf(eb->stream, pool,
          SVN_REPOS_DUMPFILE_PROP_DELTA
          ": true\n"));

  /* prop-content-length header */
  SVN_ERR(svn_stream_printf(eb->stream, pool,
          SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH
          ": %" APR_SIZE_T_FMT "\n", eb->propstring->len));

  if (dump_data_too) {
    /* content-length header */
    SVN_ERR(svn_stream_printf(eb->stream, pool,
            SVN_REPOS_DUMPFILE_CONTENT_LENGTH
            ": %" APR_SIZE_T_FMT "\n\n",
            eb->propstring->len));

    /* the properties themselves */
    SVN_ERR(svn_stream_write(eb->stream, eb->propstring->data,
           &(eb->propstring->len)));

    /* Cleanup so that data is never dumped twice */
    apr_hash_clear(eb->properties);
    apr_hash_clear(eb->del_properties);
    if (trigger_var)
      *trigger_var = FALSE;
  }
  return SVN_NO_ERROR;
}<commit_msg>Follow-up to 965126: replace 2 more apr_hash_clear() invocations.<commit_after>/*
 * ====================================================================
 *    Licensed to the Apache Software Foundation (ASF) under one
 *    or more contributor license agreements.  See the NOTICE file
 *    distributed with this work for additional information
 *    regarding copyright ownership.  The ASF licenses this file
 *    to you under the Apache License, Version 2.0 (the
 *    "License"); you may not use this file except in compliance
 *    with the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing,
 *    software distributed under the License is distributed on an
 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *    KIND, either express or implied.  See the License for the
 *    specific language governing permissions and limitations
 *    under the License.
 * ====================================================================
 */

#include "svn_repos.h"
#include "svn_hash.h"

#include "svnrdump.h"

void
write_hash_to_stringbuf(apr_hash_t *properties,
                        svn_boolean_t deleted,
                        svn_stringbuf_t **strbuf,
                        apr_pool_t *pool)
{
  apr_hash_index_t *this;
  const void *key;
  void *val;
  apr_ssize_t keylen;
  svn_string_t *value;

  if (!deleted) {
    for (this = apr_hash_first(pool, properties); this;
         this = apr_hash_next(this)) {
      /* Get this key and val. */
      apr_hash_this(this, &key, &keylen, &val);
      value = val;

      /* Output name length, then name. */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "K %" APR_SSIZE_T_FMT "\n",
                    keylen));

      svn_stringbuf_appendbytes(*strbuf, (const char *) key, keylen);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);

      /* Output value length, then value. */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "V %" APR_SIZE_T_FMT "\n",
                    value->len));

      svn_stringbuf_appendbytes(*strbuf, value->data, value->len);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);
    }
  }
  else {
    /* Output a "D " entry for each deleted property */
    for (this = apr_hash_first(pool, properties); this;
         this = apr_hash_next(this)) {
      /* Get this key */
      apr_hash_this(this, &key, &keylen, NULL);

      /* Output name length, then name */
      svn_stringbuf_appendcstr(*strbuf,
             apr_psprintf(pool, "D %" APR_SSIZE_T_FMT "\n",
                    keylen));

      svn_stringbuf_appendbytes(*strbuf, (const char *) key, keylen);
      svn_stringbuf_appendbytes(*strbuf, "\n", 1);
    }
  }
}

svn_error_t *
dump_props(struct dump_edit_baton *eb,
           svn_boolean_t *trigger_var,
           svn_boolean_t dump_data_too,
           apr_pool_t *pool)
{
  if (trigger_var && !*trigger_var)
    return SVN_NO_ERROR;

  /* Build a propstring to print */
  svn_stringbuf_setempty(eb->propstring);
  write_hash_to_stringbuf(eb->properties,
        FALSE,
        &(eb->propstring), eb->pool);
  write_hash_to_stringbuf(eb->del_properties,
        TRUE,
        &(eb->propstring), eb->pool);
  svn_stringbuf_appendbytes(eb->propstring, "PROPS-END\n", 10);

  /* prop-delta header */
  SVN_ERR(svn_stream_printf(eb->stream, pool,
          SVN_REPOS_DUMPFILE_PROP_DELTA
          ": true\n"));

  /* prop-content-length header */
  SVN_ERR(svn_stream_printf(eb->stream, pool,
          SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH
          ": %" APR_SIZE_T_FMT "\n", eb->propstring->len));

  if (dump_data_too) {
    /* content-length header */
    SVN_ERR(svn_stream_printf(eb->stream, pool,
            SVN_REPOS_DUMPFILE_CONTENT_LENGTH
            ": %" APR_SIZE_T_FMT "\n\n",
            eb->propstring->len));

    /* the properties themselves */
    SVN_ERR(svn_stream_write(eb->stream, eb->propstring->data,
           &(eb->propstring->len)));

    /* Cleanup so that data is never dumped twice */
    svn_hash__clear(eb->properties, pool);
    svn_hash__clear(eb->del_properties, pool);
    if (trigger_var)
      *trigger_var = FALSE;
  }
  return SVN_NO_ERROR;
}
{'fraction_non_alphanumeric': 0.1410832544938505, 'fraction_numerical': 0.002956480605487228, 'mean_word_length': 2.787281683833408, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2458253', 'n_tokens_mistral': 2754, 'n_tokens_neox': 2727, 'n_words': 637}