This would be an easy one to add an automated test for -- you could
put it in subversion/tests/libsvn_subr/stream-test.c.
On Mon, 16 Jul 2007, cacknin@tigris.org wrote:
> Author: cacknin
> Date: Mon Jul 16 08:35:22 2007
> New Revision: 25758
>
> Log:
> Add svn_stringbuf_appendformat, similar to svn_stringbuf_append{str,cstr,bytes}
> except it uses variable-length argument like printf, and make use of it.
>
> * subversion/include/svn_string.h
> * subversion/libsvn_subr/svn_string.c
> (svn_stringbuf_appendformat): new function using variable-length argument,
> wrapping svn_stringbuf_append() + apr_pvsprintf().
>
> * subversion/libsvn_client/diff.c
> (svnpatch_append): remove the function, useless against
> svn_stringbuf_appendformat.
> (diff_content_changed, diff_file_added, diff_file_deleted_with_diff,
> diff_file_deleted_no_diff, diff_dir_added, diff_dir_deleted): use
> svn_stringbuf_appendformat() now on when playing with the svnpatch buffer.
> (diff_props_changed): move svnpatch-buffer edition deeper.
> (display_prop_diffs): add svnpatch_format and svnpatch_buff arguments to
> satisfy svnpatch-diff needs, and edit svnpatch-buffer here.
>
>
>
> Modified:
> branches/svnpatch-diff/subversion/include/svn_string.h
> branches/svnpatch-diff/subversion/libsvn_client/diff.c
> branches/svnpatch-diff/subversion/libsvn_subr/svn_string.c
>
> Modified: branches/svnpatch-diff/subversion/include/svn_string.h
> URL: http://svn.collab.net/viewvc/svn/branches/svnpatch-diff/subversion/include/svn_string.h?pathrev=25758&r1=25757&r2=25758
> ==============================================================================
> --- branches/svnpatch-diff/subversion/include/svn_string.h (original)
> +++ branches/svnpatch-diff/subversion/include/svn_string.h Mon Jul 16 08:35:22 2007
> @@ -234,6 +234,14 @@
> const char *bytes,
> apr_size_t count);
>
> +/** Append bytes onto @a targetstr in a printf-like fashion.
> + *
> + * reallocs if necessary. @a targetstr is affected, nothing else is.
> + */
> +void svn_stringbuf_appendformat(svn_stringbuf_t *targetstr,
> + const char *fmt,
> + ...);
> +
> /** Append an @c svn_stringbuf_t onto @a targetstr.
> *
> * reallocs if necessary. @a targetstr is affected, nothing else is.
>
> Modified: branches/svnpatch-diff/subversion/libsvn_client/diff.c
> URL: http://svn.collab.net/viewvc/svn/branches/svnpatch-diff/subversion/libsvn_client/diff.c?pathrev=25758&r1=25757&r2=25758
> ==============================================================================
> --- branches/svnpatch-diff/subversion/libsvn_client/diff.c (original)
> +++ branches/svnpatch-diff/subversion/libsvn_client/diff.c Mon Jul 16 08:35:22 2007
> @@ -167,6 +167,8 @@
> const char *path,
> const char *encoding,
> apr_file_t *file,
> + svn_boolean_t svnpatch_format,
> + svn_stringbuf_t *svnpatch_buff,
> apr_pool_t *pool)
> {
> int i;
> @@ -251,6 +253,15 @@
> propchange->value->data);
> }
> }
> +
> + if (svnpatch_format)
> + svn_stringbuf_appendformat(svnpatch_buff,
> + APR_EOL_STR "diff_props_changed;" \
> + "path: %s, name: %s, val: %s",
> + path,
> + propchange->name,
> + original_value ? original_value->data :
> + propchange->value->data);
> }
> }
>
> @@ -313,26 +324,6 @@
> svn_stringbuf_t *svnpatch_buff;
> };
>
> -/* Somehow wraps svn_stringbuf_appendbytes in a printf-style fashion thanks to
> - apr_pvsprintf(). This could be moved into svn_string.h after some
> - generic-tweaking. (This needs diff_cmd_baton struct symbols, defined right
> - above) */
> -svn_error_t *
> -svnpatch_append(struct diff_cmd_baton *diff_cmd_baton, const char *fmt, ...)
> -{
> - va_list ap;
> - char *buff;
> - apr_pool_t *subpool = svn_pool_create(diff_cmd_baton->pool);
> -
> - va_start(ap, fmt);
> - buff = apr_pvsprintf(subpool, fmt, ap);
> - va_end(ap);
> - svn_stringbuf_appendbytes(diff_cmd_baton->svnpatch_buff, buff, strlen(buff));
> -
> - svn_pool_destroy(subpool);
> - return SVN_NO_ERROR;
> -}
> -
>
> /* Generate a label for the diff output for file PATH at revision REVNUM.
> If REVNUM is invalid then it is assumed to be the current working
> @@ -371,16 +362,14 @@
> if (props->nelts > 0)
> SVN_ERR(display_prop_diffs(props, original_props, path,
> diff_cmd_baton->header_encoding,
> - diff_cmd_baton->outfile, subpool));
> + diff_cmd_baton->outfile,
> + diff_cmd_baton->svnpatch_format,
> + diff_cmd_baton->svnpatch_buff,
> + subpool));
>
> if (state)
> *state = svn_wc_notify_state_unknown;
>
> - if (diff_cmd_baton->svnpatch_format)
> - SVN_ERR(svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_props_changed; path:%s",
> - path));
> -
> svn_pool_destroy(subpool);
> return SVN_NO_ERROR;
> }
> @@ -521,9 +510,10 @@
> }
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_content_changed(binary); path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR \
> + "diff_content_changed(binary); path: %s",
> + path);
>
> /* Exit early. */
> svn_pool_destroy(subpool);
> @@ -658,9 +648,9 @@
> prop_changes, original_props, diff_baton));
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_file_added; path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR "diff_file_added; path: %s",
> + path);
>
> diff_cmd_baton->force_empty = FALSE;
>
> @@ -682,9 +672,10 @@
> struct diff_cmd_baton *diff_cmd_baton = diff_baton;
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_file_deleted_with_diff; path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR \
> + "diff_file_deleted_with_diff; path: %s",
> + path);
>
> /* We don't list all the deleted properties. */
> return diff_file_changed(adm_access, state, NULL, path,
> @@ -714,9 +705,10 @@
> *state = svn_wc_notify_state_unknown;
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_file_deleted_no_diff; path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR \
> + "diff_file_deleted_no_diff; path: %s",
> + path);
>
> SVN_ERR(file_printf_from_utf8
> (diff_cmd_baton->outfile,
> @@ -744,9 +736,9 @@
> *state = svn_wc_notify_state_unknown;
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_dir_added; path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR "diff_dir_added; path: %s",
> + path);
>
> /* ### todo: send feedback to app */
> return SVN_NO_ERROR;
> @@ -765,9 +757,9 @@
> *state = svn_wc_notify_state_unknown;
>
> if (diff_cmd_baton->svnpatch_format)
> - svnpatch_append(diff_cmd_baton,
> - APR_EOL_STR "diff_dir_deleted; path:%s",
> - path);
> + svn_stringbuf_appendformat(diff_cmd_baton->svnpatch_buff,
> + APR_EOL_STR "diff_dir_deleted; path: %s",
> + path);
>
> return SVN_NO_ERROR;
> }
>
> Modified: branches/svnpatch-diff/subversion/libsvn_subr/svn_string.c
> URL: http://svn.collab.net/viewvc/svn/branches/svnpatch-diff/subversion/libsvn_subr/svn_string.c?pathrev=25758&r1=25757&r2=25758
> ==============================================================================
> --- branches/svnpatch-diff/subversion/libsvn_subr/svn_string.c (original)
> +++ branches/svnpatch-diff/subversion/libsvn_subr/svn_string.c Mon Jul 16 08:35:22 2007
> @@ -391,6 +391,20 @@
>
>
> void
> +svn_stringbuf_appendformat(svn_stringbuf_t *targetstr,
> + const char *fmt,
> + ...)
> +{
> + va_list ap;
> + char *buff;
> +
> + va_start(ap, fmt);
> + buff = apr_pvsprintf(targetstr->pool, fmt, ap);
> + va_end(ap);
> + svn_stringbuf_appendbytes(targetstr, buff, strlen(buff));
> +}
> +
> +void
> svn_stringbuf_appendstr(svn_stringbuf_t *targetstr,
> const svn_stringbuf_t *appendstr)
> {
- application/pgp-signature attachment: stored
Received on Mon Jul 16 19:46:39 2007