[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: Factor out a print-property-as-XML function

From: Karl Fogel <kfogel_at_red-bean.com>
Date: Fri, 04 Jul 2008 11:41:05 -0400

Julian Foad <julianfoad_at_btopenworld.com> writes:

> OK, here's a go at factoring out this print-a-property-as-XML function
> "svn_cl__print_xml_prop()" function so that it can be shared with
> "svnlook", by moving it into libsvn_client and calling it
> "svn_client__print_xml_prop()".
>
> I didn't put it in "cmdline.c" because it's not actually doing
> command-line output, just forming XML in a string buffer, and generating
> XML-formatting output is not specific to command-line clients.
>
> So it's in a new file "subversion/libsvn_client/xml.c".

Another possibility is to put it in libsvn_subr/xml.c, in the
"svn_xml__" namespace in include/private/svn_xml_private.h (which would
have to be created).

-Karl

> Factor out an XML-printing function that was common to "svn" and "svnlook"
> since r31978.
>
> * subversion/include/svn_client.h,
> (svn_client__print_xml_prop): New function.
>
> * subversion/libsvn_client/xml.c
> New file, containing svn_client__print_xml_prop().
>
> * subversion/svnlook/main.c
> (print_xml_prop): Remove.
> (do_plist): Call svn_client__print_xml_prop() instead of print_xml_prop().
>
> * subversion/svn/propget-cmd.c
> (print_properties_xml, svn_cl__propget): Call svn_client__print_xml_prop()
> instead of svn_cl__print_xml_prop().
>
> * subversion/svn/props.c
> (svn_cl__print_xml_prop): Remove.
> (svn_cl__print_xml_prop_hash): Call svn_client__print_xml_prop() instead
> of svn_cl__print_xml_prop().
>
> * build.conf
> Add "libsvn_client" to the libraries needed by "svnlook".
>
> Index: subversion/include/svn_client.h
> ===================================================================
> --- subversion/include/svn_client.h (revision 31998)
> +++ subversion/include/svn_client.h (working copy)
> @@ -3636,6 +3636,24 @@ svn_client_revprop_list(apr_hash_t **pro
> svn_revnum_t *set_rev,
> svn_client_ctx_t *ctx,
> apr_pool_t *pool);
> +
> +/** Write a property as an XML element into @a *outstr.
> + *
> + * If @a outstr is NULL, allocate @a *outstr in @a pool; else append to
> + * @a *outstr, allocating in @a outstr's pool
> + *
> + * @a propname is the property name. @a propval is the property value, which
> + * will be encoded it if contains unsafe bytes.
> + *
> + * @since New in 1.6.
> + *
> + * This is a private API for Subversion's own use.
> + */
> +void
> +svn_client__print_xml_prop(svn_stringbuf_t **outstr,
> + const char *propname,
> + svn_string_t *propval,
> + apr_pool_t *pool);
> /** @} */
>
>
> Index: subversion/svnlook/main.c
> ===================================================================
> --- subversion/svnlook/main.c (revision 31998)
> +++ subversion/svnlook/main.c (working copy)
> @@ -44,7 +44,7 @@
> #include "svn_props.h"
> #include "svn_diff.h"
> #include "svn_xml.h"
> -#include "svn_base64.h"
> +#include "svn_client.h"
>
> #include "svn_private_config.h"
>
> @@ -1540,48 +1540,6 @@ do_pget(svnlook_ctxt_t *c,
> }
>
>
> -/* A copy of svn_cl__print_xml_prop(). */
> -static void
> -print_xml_prop(svn_stringbuf_t **outstr,
> - const char* propname,
> - svn_string_t *propval,
> - apr_pool_t *pool)
> -{
> - const char *xml_safe;
> - const char *encoding = NULL;
> -
> - if (*outstr == NULL)
> - *outstr = svn_stringbuf_create("", pool);
> -
> - if (svn_xml_is_xml_safe(propval->data, propval->len))
> - {
> - svn_stringbuf_t *xml_esc = NULL;
> - svn_xml_escape_cdata_string(&xml_esc, propval, pool);
> - xml_safe = xml_esc->data;
> - }
> - else
> - {
> - const svn_string_t *base64ed = svn_base64_encode_string(propval, pool);
> - encoding = "base64";
> - xml_safe = base64ed->data;
> - }
> -
> - if (encoding)
> - svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> - "property", "name", propname,
> - "encoding", encoding, NULL);
> - else
> - svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> - "property", "name", propname, NULL);
> -
> - svn_stringbuf_appendcstr(*outstr, xml_safe);
> -
> - svn_xml_make_close_tag(outstr, pool, "property");
> -
> - return;
> -}
> -
> -
> /* Print the property names of all properties on PATH in the repository.
> If VERBOSE, print their values too.
> If XML, print as XML rather than as plain text.
> @@ -1666,7 +1624,7 @@ do_plist(svnlook_ctxt_t *c,
> const char *pname_stdout;
> SVN_ERR(svn_cmdline_cstring_from_utf8(&pname_stdout, pname, pool));
> if (xml)
> - print_xml_prop(&sb, pname_stdout, propval, pool);
> + svn_client__print_xml_prop(&sb, pname_stdout, propval, pool);
> else
> printf(" %s : %s\n", pname_stdout, propval->data);
> }
> Index: subversion/svn/propget-cmd.c
> ===================================================================
> --- subversion/svn/propget-cmd.c (revision 31998)
> +++ subversion/svn/propget-cmd.c (working copy)
> @@ -81,7 +81,7 @@ print_properties_xml(const char *pname,
>
> svn_xml_make_open_tag(&sb, iterpool, svn_xml_normal, "target",
> "path", filename, NULL);
> - svn_cl__print_xml_prop(&sb, pname, propval, iterpool);
> + svn_client__print_xml_prop(&sb, pname, propval, iterpool);
> svn_xml_make_close_tag(&sb, iterpool, "target");
>
> SVN_ERR(svn_cl__error_checked_fputs(sb->data, stdout));
> @@ -217,7 +217,7 @@ svn_cl__propget(apr_getopt_t *os,
> "revprops",
> "rev", revstr, NULL);
>
> - svn_cl__print_xml_prop(&sb, pname_utf8, propval, pool);
> + svn_client__print_xml_prop(&sb, pname_utf8, propval, pool);
>
> svn_xml_make_close_tag(&sb, pool, "revprops");
>
> Index: subversion/svn/props.c
> ===================================================================
> --- subversion/svn/props.c (revision 31998)
> +++ subversion/svn/props.c (working copy)
> @@ -110,46 +110,6 @@ svn_cl__print_prop_hash(apr_hash_t *prop
> return SVN_NO_ERROR;
> }
>
> -void
> -svn_cl__print_xml_prop(svn_stringbuf_t **outstr,
> - const char* propname,
> - svn_string_t *propval,
> - apr_pool_t *pool)
> -{
> - const char *xml_safe;
> - const char *encoding = NULL;
> -
> - if (*outstr == NULL)
> - *outstr = svn_stringbuf_create("", pool);
> -
> - if (svn_xml_is_xml_safe(propval->data, propval->len))
> - {
> - svn_stringbuf_t *xml_esc = NULL;
> - svn_xml_escape_cdata_string(&xml_esc, propval, pool);
> - xml_safe = xml_esc->data;
> - }
> - else
> - {
> - const svn_string_t *base64ed = svn_base64_encode_string(propval, pool);
> - encoding = "base64";
> - xml_safe = base64ed->data;
> - }
> -
> - if (encoding)
> - svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> - "property", "name", propname,
> - "encoding", encoding, NULL);
> - else
> - svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> - "property", "name", propname, NULL);
> -
> - svn_stringbuf_appendcstr(*outstr, xml_safe);
> -
> - svn_xml_make_close_tag(outstr, pool, "property");
> -
> - return;
> -}
> -
> svn_error_t *
> svn_cl__print_xml_prop_hash(svn_stringbuf_t **outstr,
> apr_hash_t *prop_hash,
> @@ -187,7 +147,7 @@ svn_cl__print_xml_prop_hash(svn_stringbu
>
> SVN_ERR(svn_cmdline_cstring_from_utf8(&pname_out, pname, pool));
>
> - svn_cl__print_xml_prop(outstr, pname_out, propval, pool);
> + svn_client__print_xml_prop(outstr, pname_out, propval, pool);
> }
> }
>
> Index: build.conf
> ===================================================================
> --- build.conf (revision 31998)
> +++ build.conf (working copy)
> @@ -174,7 +174,7 @@
> path = subversion/svnlook
> install = bin
> manpages = subversion/svnlook/svnlook.1
> -libs = libsvn_repos libsvn_fs libsvn_delta libsvn_diff libsvn_subr apriconv apr
> +libs = libsvn_client libsvn_repos libsvn_fs libsvn_delta libsvn_diff libsvn_subr apriconv apr
>
> [svnserve]
> description = Subversion Server
> Index: subversion/libsvn_client/xml.c
> ===================================================================
> --- subversion/libsvn_client/xml.c (revision 0)
> +++ subversion/libsvn_client/xml.c (revision 0)
> @@ -0,0 +1,69 @@
> +/*
> + * xml.c: XML output of Subversion data
> + *
> + * ====================================================================
> + * Copyright (c) 2008 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/.
> + * ====================================================================
> + */
> +
> +/* ==================================================================== */
> +
> +
> +/*** Includes. ***/
> +#include "svn_client.h"
> +#include "svn_string.h"
> +#include "svn_xml.h"
> +#include "svn_base64.h"
> +
> +#include "svn_private_config.h"
> +
> +
> +/*** Code. ***/
> +
> +void
> +svn_client__print_xml_prop(svn_stringbuf_t **outstr,
> + const char* propname,
> + svn_string_t *propval,
> + apr_pool_t *pool)
> +{
> + const char *xml_safe;
> + const char *encoding = NULL;
> +
> + if (*outstr == NULL)
> + *outstr = svn_stringbuf_create("", pool);
> +
> + if (svn_xml_is_xml_safe(propval->data, propval->len))
> + {
> + svn_stringbuf_t *xml_esc = NULL;
> + svn_xml_escape_cdata_string(&xml_esc, propval, pool);
> + xml_safe = xml_esc->data;
> + }
> + else
> + {
> + const svn_string_t *base64ed = svn_base64_encode_string(propval, pool);
> + encoding = "base64";
> + xml_safe = base64ed->data;
> + }
> +
> + if (encoding)
> + svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> + "property", "name", propname,
> + "encoding", encoding, NULL);
> + else
> + svn_xml_make_open_tag(outstr, pool, svn_xml_protect_pcdata,
> + "property", "name", propname, NULL);
> +
> + svn_stringbuf_appendcstr(*outstr, xml_safe);
> +
> + svn_xml_make_close_tag(outstr, pool, "property");
> +}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_subversion.tigris.org
For additional commands, e-mail: dev-help_at_subversion.tigris.org
Received on 2008-07-04 17:42:04 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.