You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2012/11/21 01:14:55 UTC
svn commit: r1411948 - in /subversion/trunk/subversion: libsvn_client/diff.c
svnlook/main.c
Author: julianfoad
Date: Wed Nov 21 00:14:54 2012
New Revision: 1411948
URL: http://svn.apache.org/viewvc?rev=1411948&view=rev
Log:
Expose the commonality and differences between two similar prop-diff
functions, mainly by transforming one of them so that the common parts match
exactly.
* subversion/libsvn_client/diff.c
(display_prop_diffs): Adjust white space.
* subversion/svnlook/main.c
(display_prop_diffs): Write all output through a stream. Introduce an
iteration pool. Rename some parameters and local variables.
Modified:
subversion/trunk/subversion/libsvn_client/diff.c
subversion/trunk/subversion/svnlook/main.c
Modified: subversion/trunk/subversion/libsvn_client/diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/diff.c?rev=1411948&r1=1411947&r2=1411948&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/diff.c (original)
+++ subversion/trunk/subversion/libsvn_client/diff.c Wed Nov 21 00:14:54 2012
@@ -619,8 +619,8 @@ display_prop_diffs(const apr_array_heade
{
const char *action;
const svn_string_t *original_value;
- const svn_prop_t *propchange =
- &APR_ARRAY_IDX(propchanges, i, svn_prop_t);
+ const svn_prop_t *propchange
+ = &APR_ARRAY_IDX(propchanges, i, svn_prop_t);
if (original_props)
original_value = apr_hash_get(original_props,
@@ -698,13 +698,11 @@ display_prop_diffs(const apr_array_heade
* UNIX patch could apply the property diff to, so we use "##"
* instead of "@@" as the default hunk delimiter for property diffs.
* We also supress the diff header. */
- SVN_ERR(svn_diff_mem_string_output_unified2(outstream, diff, FALSE,
- "##",
- svn_dirent_local_style(path,
- iterpool),
- svn_dirent_local_style(path,
- iterpool),
- encoding, orig, val, iterpool));
+ SVN_ERR(svn_diff_mem_string_output_unified2(
+ outstream, diff, FALSE, "##",
+ svn_dirent_local_style(path, iterpool),
+ svn_dirent_local_style(path, iterpool),
+ encoding, orig, val, iterpool));
if (!val_has_eol)
{
const char *s = "\\ No newline at end of property" APR_EOL_STR;
Modified: subversion/trunk/subversion/svnlook/main.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnlook/main.c?rev=1411948&r1=1411947&r2=1411948&view=diff
==============================================================================
--- subversion/trunk/subversion/svnlook/main.c (original)
+++ subversion/trunk/subversion/svnlook/main.c Wed Nov 21 00:14:54 2012
@@ -840,42 +840,56 @@ static const char under_string[] =
/* Helper function to display differences in properties of a file */
static svn_error_t *
-display_prop_diffs(const apr_array_header_t *prop_diffs,
- apr_hash_t *orig_props,
+display_prop_diffs(const apr_array_header_t *propchanges,
+ apr_hash_t *original_props,
const char *path,
apr_pool_t *pool)
{
+ const char *encoding = svn_cmdline_output_encoding(pool);
+ svn_stream_t *outstream;
+ apr_pool_t *iterpool;
int i;
- SVN_ERR(svn_cmdline_printf(pool, "\nProperty changes on: %s\n%s\n",
- path, under_string));
+ SVN_ERR(svn_stream_for_stdout(&outstream, pool));
- for (i = 0; i < prop_diffs->nelts; i++)
- {
- const char *header_label;
- const svn_string_t *orig_value;
- const svn_prop_t *pc = &APR_ARRAY_IDX(prop_diffs, i, svn_prop_t);
+ SVN_ERR(svn_stream_printf_from_utf8(outstream, encoding, pool,
+ _("%sProperty changes on: %s%s"),
+ APR_EOL_STR,
+ path,
+ APR_EOL_STR));
+
+ SVN_ERR(svn_stream_printf_from_utf8(outstream, encoding, pool,
+ "%s" APR_EOL_STR, under_string));
+
+ iterpool = svn_pool_create(pool);
+ for (i = 0; i < propchanges->nelts; i++)
+ {
+ const char *action;
+ const svn_string_t *original_value;
+ const svn_prop_t *propchange
+ = &APR_ARRAY_IDX(propchanges, i, svn_prop_t);
SVN_ERR(check_cancel(NULL));
- if (orig_props)
- orig_value = apr_hash_get(orig_props, pc->name, APR_HASH_KEY_STRING);
+ if (original_props)
+ original_value = apr_hash_get(original_props,
+ propchange->name, APR_HASH_KEY_STRING);
else
- orig_value = NULL;
+ original_value = NULL;
- if (! orig_value)
- header_label = "Added";
- else if (! pc->value)
- header_label = "Deleted";
- else
- header_label = "Modified";
- SVN_ERR(svn_cmdline_printf(pool, "%s: %s\n", header_label, pc->name));
+ svn_pool_clear(iterpool);
- /* Flush stdout before we open a stream to it below. */
- SVN_ERR(svn_cmdline_fflush(stdout));
+ if (! original_value)
+ action = "Added";
+ else if (! propchange->value)
+ action = "Deleted";
+ else
+ action = "Modified";
+ SVN_ERR(svn_stream_printf_from_utf8(outstream, encoding, iterpool,
+ "%s: %s%s", action,
+ propchange->name, APR_EOL_STR));
{
- svn_stream_t *out;
svn_diff_t *diff;
svn_diff_file_options_t options;
const svn_string_t *tmp;
@@ -883,20 +897,20 @@ display_prop_diffs(const apr_array_heade
const svn_string_t *val;
svn_boolean_t val_has_eol;
- SVN_ERR(svn_stream_for_stdout(&out, pool));
-
/* The last character in a property is often not a newline.
An eol character is appended to prevent the diff API to add a
'\ No newline at end of file' line. We add
'\ No newline at end of property' manually if needed. */
- tmp = orig_value ? orig_value : svn_string_create_empty(pool);
- orig = maybe_append_eol(tmp, NULL, pool);
-
- tmp = pc->value ? pc->value :
- svn_string_create_empty(pool);
- val = maybe_append_eol(tmp, &val_has_eol, pool);
+ tmp = original_value ? original_value
+ : svn_string_create_empty(iterpool);
+ orig = maybe_append_eol(tmp, NULL, iterpool);
+
+ tmp = propchange->value ? propchange->value :
+ svn_string_create_empty(iterpool);
+ val = maybe_append_eol(tmp, &val_has_eol, iterpool);
- SVN_ERR(svn_diff_mem_string_diff(&diff, orig, val, &options, pool));
+ SVN_ERR(svn_diff_mem_string_diff(&diff, orig, val, &options,
+ iterpool));
/* UNIX patch will try to apply a diff even if the diff header
* is missing. It tries to be helpful by asking the user for a
@@ -905,18 +919,20 @@ display_prop_diffs(const apr_array_heade
* UNIX patch could apply the property diff to, so we use "##"
* instead of "@@" as the default hunk delimiter for property diffs.
* We also supress the diff header. */
- SVN_ERR(svn_diff_mem_string_output_unified2(out, diff, FALSE, "##",
- svn_dirent_local_style(path, pool),
- svn_dirent_local_style(path, pool),
- svn_cmdline_output_encoding(pool),
- orig, val, pool));
+ SVN_ERR(svn_diff_mem_string_output_unified2(
+ outstream, diff, FALSE, "##",
+ svn_dirent_local_style(path, iterpool),
+ svn_dirent_local_style(path, iterpool),
+ encoding, orig, val, iterpool));
if (!val_has_eol)
{
const char *s = "\\ No newline at end of property" APR_EOL_STR;
- SVN_ERR(svn_stream_puts(out, s));
+ SVN_ERR(svn_stream_puts(outstream, s));
}
}
}
+ svn_pool_destroy(iterpool);
+
return svn_cmdline_fflush(stdout);
}