<commit_before>/*
 * checkout.c : read a repository tree and drive a checkout editor.
 *
 * ====================================================================
 * Copyright (c) 2000-2002 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 "ra_local.h"
#include <assert.h>
#include "svn_pools.h"


/* Helper to read data out of a file at ROOT:PATH and push it to
   EDITOR via FILE_BATON.

   <NAME>: whoa.  The elegance and level of abstraction going on here
   is amazing.  What an amazing design.  It's like a set of opaque
   legos that all perfectly fit together. :) */
static svn_error_t *
send_file_contents (svn_fs_root_t *root,
                    const char *path,
                    void *file_baton,
                    const svn_delta_editor_t *editor,
                    apr_pool_t *pool)
{
  svn_stream_t *contents;
  svn_txdelta_window_handler_t handler;
  void *handler_baton;
  
  /* Get a readable stream of the file's contents. */
  SVN_ERR (svn_fs_file_contents (&contents, root, path, pool));  

  /* Get an editor func that wants to consume the delta stream. */
  SVN_ERR (editor->apply_textdelta (file_baton, &handler, &handler_baton));

  /* Send the file's contents to the delta-window handler. */
  SVN_ERR (svn_txdelta_send_stream (contents, handler, handler_baton, pool));

  return SVN_NO_ERROR;
}



/* Helper to push any properties attached to ROOT:PATH at EDITOR,
   using OBJECT_BATON.  IS_DIR indicates which editor func to call. */
static svn_error_t *
set_any_props (svn_fs_root_t *root,
               const char *path,
               void *object_baton,
               const svn_delta_editor_t *editor,
               int is_dir,
               apr_pool_t *pool)
{
  apr_hash_index_t *hi;
  svn_revnum_t committed_rev;
  const char *last_author, *committed_date, *revision_str;
  apr_hash_t *props = NULL;

  /* Get all user properties attached to PATH. */
  SVN_ERR (svn_fs_node_proplist (&props, root, path, pool));

  /* Query the fs for three 'entry' props:  specifically, the
     last-changed-rev of the file or dir ("created rev"), and the
     associated date & author of said revision.  Add these three props
     to the proplist hash, as a means of getting them into the working
     copy's 'entries' file.  The working copy Update Editor will
     recognize them. */
  if ((props == NULL) || (apr_hash_count (props) == 0))
    props = apr_hash_make (pool);
  
  SVN_ERR (svn_repos_get_committed_info (&committed_rev,
                                         &committed_date,
                                         &last_author,
                                         root, path, pool));
    
  revision_str = apr_psprintf (pool, "%" SVN_REVNUM_T_FMT, committed_rev);
  apr_hash_set (props, SVN_PROP_ENTRY_COMMITTED_REV, 
                strlen(SVN_PROP_ENTRY_COMMITTED_REV),
                svn_string_create (revision_str, pool));
    
  apr_hash_set (props, SVN_PROP_ENTRY_COMMITTED_DATE, 
                strlen(SVN_PROP_ENTRY_COMMITTED_DATE),
                svn_string_create (committed_date, pool));
    
  apr_hash_set (props, SVN_PROP_ENTRY_LAST_AUTHOR, 
                strlen(SVN_PROP_ENTRY_LAST_AUTHOR),
                svn_string_create (last_author, pool));
  
  
  /* Loop over properties, send them through the editor. */
  for (hi = apr_hash_first (pool, props); hi; hi = apr_hash_next (hi))
    {
      const void *key;
      void *val;
      svn_string_t *value;<commit_msg>Yet a small fix for the same problem half fixed in rev 2032.<commit_after>/*
 * checkout.c : read a repository tree and drive a checkout editor.
 *
 * ====================================================================
 * Copyright (c) 2000-2002 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 "ra_local.h"
#include <assert.h>
#include "svn_pools.h"


/* Helper to read data out of a file at ROOT:PATH and push it to
   EDITOR via FILE_BATON.

   <NAME>: whoa.  The elegance and level of abstraction going on here
   is amazing.  What an amazing design.  It's like a set of opaque
   legos that all perfectly fit together. :) */
static svn_error_t *
send_file_contents (svn_fs_root_t *root,
                    const char *path,
                    void *file_baton,
                    const svn_delta_editor_t *editor,
                    apr_pool_t *pool)
{
  svn_stream_t *contents;
  svn_txdelta_window_handler_t handler;
  void *handler_baton;
  
  /* Get a readable stream of the file's contents. */
  SVN_ERR (svn_fs_file_contents (&contents, root, path, pool));  

  /* Get an editor func that wants to consume the delta stream. */
  SVN_ERR (editor->apply_textdelta (file_baton, &handler, &handler_baton));

  /* Send the file's contents to the delta-window handler. */
  SVN_ERR (svn_txdelta_send_stream (contents, handler, handler_baton, pool));

  return SVN_NO_ERROR;
}



/* Helper to push any properties attached to ROOT:PATH at EDITOR,
   using OBJECT_BATON.  IS_DIR indicates which editor func to call. */
static svn_error_t *
set_any_props (svn_fs_root_t *root,
               const char *path,
               void *object_baton,
               const svn_delta_editor_t *editor,
               int is_dir,
               apr_pool_t *pool)
{
  apr_hash_index_t *hi;
  svn_revnum_t committed_rev;
  const char *last_author, *committed_date, *revision_str;
  apr_hash_t *props = NULL;

  /* Get all user properties attached to PATH. */
  SVN_ERR (svn_fs_node_proplist (&props, root, path, pool));

  /* Query the fs for three 'entry' props:  specifically, the
     last-changed-rev of the file or dir ("created rev"), and the
     associated date & author of said revision.  Add these three props
     to the proplist hash, as a means of getting them into the working
     copy's 'entries' file.  The working copy Update Editor will
     recognize them. */
  if ((props == NULL) || (apr_hash_count (props) == 0))
    props = apr_hash_make (pool);
  
  SVN_ERR (svn_repos_get_committed_info (&committed_rev,
                                         &committed_date,
                                         &last_author,
                                         root, path, pool));
    
  revision_str = apr_psprintf (pool, "%" SVN_REVNUM_T_FMT, committed_rev);
  apr_hash_set (props, SVN_PROP_ENTRY_COMMITTED_REV, 
                strlen(SVN_PROP_ENTRY_COMMITTED_REV),
                svn_string_create (revision_str, pool));
    
  apr_hash_set (props, SVN_PROP_ENTRY_COMMITTED_DATE, 
                strlen(SVN_PROP_ENTRY_COMMITTED_DATE),
                committed_date ?
                svn_string_create (committed_date, pool) : NULL);
    
  apr_hash_set (props, SVN_PROP_ENTRY_LAST_AUTHOR, 
                strlen(SVN_PROP_ENTRY_LAST_AUTHOR),
                last_author ?
                svn_string_create (last_author, pool) : NULL);
  
  
  /* Loop over properties, send them through the editor. */
  for (hi = apr_hash_first (pool, props); hi; hi = apr_hash_next (hi))
    {
      const void *key;
      void *val;
      svn_string_t *value;
{'fraction_non_alphanumeric': 0.11088070261039278, 'fraction_numerical': 0.002927543303244694, 'mean_word_length': 2.7713891444342225, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4316938', 'n_tokens_mistral': 2546, 'n_tokens_neox': 2453, 'n_words': 789}