Alien-SVN

 view release on metacpan or  search on metacpan

src/subversion/subversion/libsvn_diff/diff_file.c  view on Meta::CPAN

      apr_size_t p;
      const char *invalid_character;

      /* Save the extra context for later use.
       * Note that the last byte of the hunk_extra_context array is never
       * touched after it is zero-initialized, so the array is always
       * 0-terminated. */
      strncpy(output_baton->hunk_extra_context,
              output_baton->extra_context->data,
              SVN_DIFF__EXTRA_CONTEXT_LENGTH);
      /* Trim whitespace at the end, most notably to get rid of any
       * newline characters. */
      p = strlen(output_baton->hunk_extra_context);
      while (p > 0
             && svn_ctype_isspace(output_baton->hunk_extra_context[p - 1]))
        {
          output_baton->hunk_extra_context[--p] = '\0';
        }
      invalid_character =
        svn_utf__last_valid(output_baton->hunk_extra_context,
                            SVN_DIFF__EXTRA_CONTEXT_LENGTH);
      for (p = invalid_character - output_baton->hunk_extra_context;
           p < SVN_DIFF__EXTRA_CONTEXT_LENGTH; p++)
        {
          output_baton->hunk_extra_context[p] = '\0';
        }
    }

  /* Modified: Skip lines until we are at the start of the changed range */
  SVN_ERR(output_unified_diff_range(output_baton, 1 /* modified */,
                                    svn_diff__file_output_unified_skip,
                                    modified_start));

  /* Original: Output the context preceding the changed range */
  SVN_ERR(output_unified_diff_range(output_baton, 0 /* original */,
                                    svn_diff__file_output_unified_context,
                                    original_start));

  /* Both: Output the changed range */
  SVN_ERR(output_unified_diff_range(output_baton, 0 /* original */,
                                    svn_diff__file_output_unified_delete,
                                    original_start + original_length));
  SVN_ERR(output_unified_diff_range(output_baton, 1 /* modified */,
                                    svn_diff__file_output_unified_insert,
                                    modified_start + modified_length));

  return SVN_NO_ERROR;
}

/* Set *HEADER to a new string consisting of PATH, a tab, and PATH's mtime. */
static svn_error_t *
output_unified_default_hdr(const char **header, const char *path,
                           apr_pool_t *pool)
{
  apr_finfo_t file_info;
  apr_time_exp_t exploded_time;
  char time_buffer[64];
  apr_size_t time_len;
  const char *utf8_timestr;

  SVN_ERR(svn_io_stat(&file_info, path, APR_FINFO_MTIME, pool));
  apr_time_exp_lt(&exploded_time, file_info.mtime);

  apr_strftime(time_buffer, &time_len, sizeof(time_buffer) - 1,
  /* Order of date components can be different in different languages */
               _("%a %b %e %H:%M:%S %Y"), &exploded_time);

  SVN_ERR(svn_utf_cstring_to_utf8(&utf8_timestr, time_buffer, pool));

  *header = apr_psprintf(pool, "%s\t%s", path, utf8_timestr);

  return SVN_NO_ERROR;
}

static const svn_diff_output_fns_t svn_diff__file_output_unified_vtable =
{
  NULL, /* output_common */
  output_unified_diff_modified,
  NULL, /* output_diff_latest */
  NULL, /* output_diff_common */
  NULL  /* output_conflict */
};

svn_error_t *
svn_diff_file_output_unified3(svn_stream_t *output_stream,
                              svn_diff_t *diff,
                              const char *original_path,
                              const char *modified_path,
                              const char *original_header,
                              const char *modified_header,
                              const char *header_encoding,
                              const char *relative_to_dir,
                              svn_boolean_t show_c_function,
                              apr_pool_t *pool)
{
  if (svn_diff_contains_diffs(diff))
    {
      svn_diff__file_output_baton_t baton;
      int i;

      memset(&baton, 0, sizeof(baton));
      baton.output_stream = output_stream;
      baton.pool = pool;
      baton.header_encoding = header_encoding;
      baton.path[0] = original_path;
      baton.path[1] = modified_path;
      baton.hunk = svn_stringbuf_create_empty(pool);
      baton.show_c_function = show_c_function;
      baton.extra_context = svn_stringbuf_create_empty(pool);

      if (show_c_function)
        {
          baton.extra_skip_match = apr_array_make(pool, 3, sizeof(char **));

          APR_ARRAY_PUSH(baton.extra_skip_match, const char *) = "public:*";
          APR_ARRAY_PUSH(baton.extra_skip_match, const char *) = "private:*";
          APR_ARRAY_PUSH(baton.extra_skip_match, const char *) = "protected:*";
        }

      SVN_ERR(svn_utf_cstring_from_utf8_ex2(&baton.context_str, " ",
                                            header_encoding, pool));



( run in 1.170 second using v1.01-cache-2.11-cpan-39bf76dae61 )