<commit_before>/*
 * commit.c:  wrappers around wc commit functionality.
 *
 * ====================================================================
 * Copyright (c) 2000 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.
 * ====================================================================
 */

/* ==================================================================== */




/*** Includes. ***/

#include <assert.h>
#include <apr_strings.h>
#include "svn_wc.h"
#include "svn_ra.h"
#include "svn_delta.h"
#include "svn_client.h"
#include "svn_string.h"
#include "svn_error.h"
#include "svn_path.h"
#include "svn_test.h"
#include "svn_io.h"





/*** Public Interface. ***/

svn_error_t *
svn_client_commit (const svn_delta_edit_fns_t *before_editor,
                   void *before_edit_baton,
                   const svn_delta_edit_fns_t *after_editor,
                   void *after_edit_baton,                   
                   svn_string_t *path,
                   svn_string_t *log_msg,
                   svn_string_t *xml_dst,
                   svn_revnum_t revision,
                   apr_pool_t *pool)
{
  apr_status_t apr_err;
  apr_file_t *dst = NULL; /* old habits die hard */
  svn_delta_edit_fns_t *track_editor;
  const svn_delta_edit_fns_t *commit_editor;
  void *commit_edit_baton, *track_edit_baton;
  const svn_delta_edit_fns_t *editor;
  void *edit_baton;
  apr_hash_t *targets = NULL;
  struct svn_wc_close_commit_baton ccb = {path, pool};
  apr_array_header_t *tgt_array = apr_array_make (pool, 1,
                                                  sizeof(svn_string_t *));
  
  /* If we're committing to XML... */
  if (xml_dst && xml_dst->data)
    {
      /* Open the xml file for writing. */
      apr_err = apr_file_open (&dst, xml_dst->data,
                               (APR_WRITE | APR_CREATE),
                               APR_OS_DEFAULT,
                               pool);
      if (apr_err)
        return svn_error_createf (apr_err, 0, NULL, pool,
                                  "error opening %s", xml_dst->data);
      

      /* Fetch the xml commit editor. */
      SVN_ERR (svn_delta_get_xml_editor (svn_stream_from_aprfile (dst, pool),
                                         &commit_editor, &commit_edit_baton,
                                         pool));

      if (SVN_IS_VALID_REVNUM(revision))
        {
          /* If we're supposed to bump revisions to REVISION, then
             fetch tracking editor and compose it.  Committed targets
             will be stored in tgt_array, and bumped by
             svn_wc_set_revision().  */
          SVN_ERR (svn_delta_get_commit_track_editor (&track_editor,
                                                      &track_edit_baton,
                                                      pool,
                                                      tgt_array,
                                                      revision,
                                                      svn_wc_set_revision,
                                                      &ccb));
                                                      
          svn_delta_compose_editors (&editor, &edit_baton,
                                     commit_editor, commit_edit_baton,
                                     track_editor, track_edit_baton, pool);
        }        
    }
  else /* We're committing to an RA layer */
    {
      void *ra_baton, *session;
      svn_ra_plugin_t *ra_lib;

      /* Construct full URL from PATH. */
      /* todo:  API here??  need to get from working copy. */
      const char *URL = "";

      /* Get the RA vtable that matches URL. */
      SVN_ERR (svn_ra_init_ra_libs (&ra_baton, pool));
      SVN_ERR (svn_ra_get_ra_library (&ra_lib, ra_baton, URL, pool));

      /* Open an RA session to URL */
      SVN_ERR (ra_lib->open (&session, svn_string_create (URL, pool), pool));
      
      /* Fetch RA commit editor, giving it svn_wc_set_revision(). */<commit_msg>* libsvn_client/commit.c<commit_after>/*
 * commit.c:  wrappers around wc commit functionality.
 *
 * ====================================================================
 * Copyright (c) 2000 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.
 * ====================================================================
 */

/* ==================================================================== */




/*** Includes. ***/

#include <assert.h>
#include <apr_strings.h>
#include "svn_wc.h"
#include "svn_ra.h"
#include "svn_delta.h"
#include "svn_client.h"
#include "svn_string.h"
#include "svn_error.h"
#include "svn_path.h"
#include "svn_test.h"
#include "svn_io.h"





/*** Public Interface. ***/

svn_error_t *
svn_client_commit (const svn_delta_edit_fns_t *before_editor,
                   void *before_edit_baton,
                   const svn_delta_edit_fns_t *after_editor,
                   void *after_edit_baton,                   
                   svn_string_t *path,
                   svn_string_t *log_msg,
                   svn_string_t *xml_dst,
                   svn_revnum_t revision,
                   apr_pool_t *pool)
{
  apr_status_t apr_err;
  apr_file_t *dst = NULL; /* old habits die hard */
  svn_delta_edit_fns_t *track_editor;
  const svn_delta_edit_fns_t *commit_editor;
  void *commit_edit_baton, *track_edit_baton;
  const svn_delta_edit_fns_t *editor;
  void *edit_baton;
  apr_hash_t *targets = NULL;
  struct svn_wc_close_commit_baton ccb = {path, pool};
  apr_array_header_t *tgt_array = apr_array_make (pool, 1,
                                                  sizeof(svn_string_t *));
  
  /* If we're committing to XML... */
  if (xml_dst && xml_dst->data)
    {
      /* Open the xml file for writing. */
      apr_err = apr_file_open (&dst, xml_dst->data,
                               (APR_WRITE | APR_CREATE),
                               APR_OS_DEFAULT,
                               pool);
      if (apr_err)
        return svn_error_createf (apr_err, 0, NULL, pool,
                                  "error opening %s", xml_dst->data);
      

      /* Fetch the xml commit editor. */
      SVN_ERR (svn_delta_get_xml_editor (svn_stream_from_aprfile (dst, pool),
                                         &commit_editor, &commit_edit_baton,
                                         pool));

      if (SVN_IS_VALID_REVNUM(revision))
        {
          /* If we're supposed to bump revisions to REVISION, then
             fetch tracking editor and compose it.  Committed targets
             will be stored in tgt_array, and bumped by
             svn_wc_set_revision().  */
          SVN_ERR (svn_delta_get_commit_track_editor (&track_editor,
                                                      &track_edit_baton,
                                                      pool,
                                                      tgt_array,
                                                      revision,
                                                      svn_wc_set_revision,
                                                      &ccb));
                                                      
          svn_delta_compose_editors (&editor, &edit_baton,
                                     commit_editor, commit_edit_baton,
                                     track_editor, track_edit_baton, pool);
        }        
    }
  else /* We're committing to an RA layer */
    {
      void *ra_baton, *session;
      svn_ra_plugin_t *ra_lib;
      svn_wc_entry_t *entry;
      const char *URL;

      /* Construct full URL from PATH. */
      /* todo:  API here??  need to get from working copy. */
      SVN_ERR (svn_wc_entry (&entry, path, pool));
      URL = entry->ancestor->data;

      /* Make sure our log message at least exists, even if empty. */
      if (! log_msg)
        log_msg = svn_string_create ("", pool);

      /* Get the RA vtable that matches URL. */
      SVN_ERR (svn_ra_init_ra_libs (&ra_baton, pool));
      SVN_ERR (svn_ra_get_ra_library (&ra_lib, ra_baton, URL, pool));

      /* Open an RA session to URL */
      SVN_ERR (ra_lib->open (&session, svn_string_create (URL, pool), pool));
      
      /* Fetch RA commit editor, giving it svn_wc_set_revision(). */
{'fraction_non_alphanumeric': 0.1288058856819468, 'fraction_numerical': 0.0015846066779852859, 'mean_word_length': 1.681638846737481, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 46, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6181271', 'n_tokens_mistral': 2614, 'n_tokens_neox': 2508, 'n_words': 628}