You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2012/05/21 16:03:46 UTC
svn commit: r1341031 - /subversion/trunk/subversion/svn/props.c
Author: stsp
Date: Mon May 21 14:03:46 2012
New Revision: 1341031
URL: http://svn.apache.org/viewvc?rev=1341031&view=rev
Log:
Make 'svn proplist' print property lists in sorted order.
Avoids random output ordering with APR-1.4.6.
* subversion/svn/props.c
(svn_cl__print_prop_hash, svn_cl__print_xml_prop_hash): Iterate over a sorted
hash key array rather than iterating over the property hash table itself.
Modified:
subversion/trunk/subversion/svn/props.c
Modified: subversion/trunk/subversion/svn/props.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/props.c?rev=1341031&r1=1341030&r2=1341031&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/props.c (original)
+++ subversion/trunk/subversion/svn/props.c Mon May 21 14:03:46 2012
@@ -31,6 +31,7 @@
#include "svn_cmdline.h"
#include "svn_string.h"
#include "svn_error.h"
+#include "svn_sorts.h"
#include "svn_subst.h"
#include "svn_props.h"
#include "svn_string.h"
@@ -87,12 +88,16 @@ svn_cl__print_prop_hash(svn_stream_t *ou
svn_boolean_t names_only,
apr_pool_t *pool)
{
- apr_hash_index_t *hi;
+ apr_array_header_t *sorted_props;
+ int i;
- for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
+ sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
+ pool);
+ for (i = 0; i < sorted_props->nelts; i++)
{
- const char *pname = svn__apr_hash_index_key(hi);
- svn_string_t *propval = svn__apr_hash_index_val(hi);
+ svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
+ const char *pname = item.key;
+ svn_string_t *propval = item.value;
const char *pname_stdout;
if (svn_prop_needs_translation(pname))
@@ -150,15 +155,19 @@ svn_cl__print_xml_prop_hash(svn_stringbu
svn_boolean_t names_only,
apr_pool_t *pool)
{
- apr_hash_index_t *hi;
+ apr_array_header_t *sorted_props;
+ int i;
if (*outstr == NULL)
*outstr = svn_stringbuf_create_empty(pool);
- for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
+ sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
+ pool);
+ for (i = 0; i < sorted_props->nelts; i++)
{
- const char *pname = svn__apr_hash_index_key(hi);
- svn_string_t *propval = svn__apr_hash_index_val(hi);
+ svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
+ const char *pname = item.key;
+ svn_string_t *propval = item.value;
if (names_only)
{
Re: svn commit: r1341031 - /subversion/trunk/subversion/svn/props.c
Posted by Greg Stein <gs...@gmail.com>.
On May 21, 2012 11:06 AM, "Hyrum K Wright" <hy...@wandisco.com>
wrote:
>
> On Mon, May 21, 2012 at 9:03 AM, <st...@apache.org> wrote:
> > Author: stsp
> > Date: Mon May 21 14:03:46 2012
> > New Revision: 1341031
> >
> > URL: http://svn.apache.org/viewvc?rev=1341031&view=rev
> > Log:
> > Make 'svn proplist' print property lists in sorted order.
> > Avoids random output ordering with APR-1.4.6.
>
> If we do this on a regular basis, it might be useful to implement a
> wrapper which takes a baton and handler function and then calls the
> handler with the hash key/value in sorted order. It might add some
> overhead, but it also consolidates the sorting into one location,
> rather than sprinkled everywhere. It doesn't matter much to me; just
> a thought that arose upon review. :)
We have svn_iter.h already, and I hate it. Setting up a baton and a
function to avoid a for-loop sucks.
An encapsulated iterator might be nice, however. Essentially a replacement
for apr_hash_index_t.
Cheers,
-g
Re: svn commit: r1341031 - /subversion/trunk/subversion/svn/props.c
Posted by Julian Foad <ju...@btopenworld.com>.
Hyrum K Wright wrote:
> On Mon, May 21, 2012 at 9:03 AM, <st...@apache.org> wrote:
>> Make 'svn proplist' print property lists in sorted order.
>> Avoids random output ordering with APR-1.4.6.
>
> If we do this on a regular basis, it might be useful to implement a
> wrapper which takes a baton and handler function and then calls the
> handler with the hash key/value in sorted order. It might add some
> overhead, but it also consolidates the sorting into one location,
> rather than sprinkled everywhere. It doesn't matter much to me; just
> a thought that arose upon review. :)
I wrote the attached patch some time back, to experiment with the idea of making a simple-to-use hash iterator that iterates in sorted order.
- Julian
Re: svn commit: r1341031 - /subversion/trunk/subversion/svn/props.c
Posted by Hyrum K Wright <hy...@wandisco.com>.
On Mon, May 21, 2012 at 9:03 AM, <st...@apache.org> wrote:
> Author: stsp
> Date: Mon May 21 14:03:46 2012
> New Revision: 1341031
>
> URL: http://svn.apache.org/viewvc?rev=1341031&view=rev
> Log:
> Make 'svn proplist' print property lists in sorted order.
> Avoids random output ordering with APR-1.4.6.
If we do this on a regular basis, it might be useful to implement a
wrapper which takes a baton and handler function and then calls the
handler with the hash key/value in sorted order. It might add some
overhead, but it also consolidates the sorting into one location,
rather than sprinkled everywhere. It doesn't matter much to me; just
a thought that arose upon review. :)
-Hyrum
> * subversion/svn/props.c
> (svn_cl__print_prop_hash, svn_cl__print_xml_prop_hash): Iterate over a sorted
> hash key array rather than iterating over the property hash table itself.
>
> Modified:
> subversion/trunk/subversion/svn/props.c
>
> Modified: subversion/trunk/subversion/svn/props.c
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/props.c?rev=1341031&r1=1341030&r2=1341031&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/svn/props.c (original)
> +++ subversion/trunk/subversion/svn/props.c Mon May 21 14:03:46 2012
> @@ -31,6 +31,7 @@
> #include "svn_cmdline.h"
> #include "svn_string.h"
> #include "svn_error.h"
> +#include "svn_sorts.h"
> #include "svn_subst.h"
> #include "svn_props.h"
> #include "svn_string.h"
> @@ -87,12 +88,16 @@ svn_cl__print_prop_hash(svn_stream_t *ou
> svn_boolean_t names_only,
> apr_pool_t *pool)
> {
> - apr_hash_index_t *hi;
> + apr_array_header_t *sorted_props;
> + int i;
>
> - for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
> + sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
> + pool);
> + for (i = 0; i < sorted_props->nelts; i++)
> {
> - const char *pname = svn__apr_hash_index_key(hi);
> - svn_string_t *propval = svn__apr_hash_index_val(hi);
> + svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
> + const char *pname = item.key;
> + svn_string_t *propval = item.value;
> const char *pname_stdout;
>
> if (svn_prop_needs_translation(pname))
> @@ -150,15 +155,19 @@ svn_cl__print_xml_prop_hash(svn_stringbu
> svn_boolean_t names_only,
> apr_pool_t *pool)
> {
> - apr_hash_index_t *hi;
> + apr_array_header_t *sorted_props;
> + int i;
>
> if (*outstr == NULL)
> *outstr = svn_stringbuf_create_empty(pool);
>
> - for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
> + sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
> + pool);
> + for (i = 0; i < sorted_props->nelts; i++)
> {
> - const char *pname = svn__apr_hash_index_key(hi);
> - svn_string_t *propval = svn__apr_hash_index_val(hi);
> + svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
> + const char *pname = item.key;
> + svn_string_t *propval = item.value;
>
> if (names_only)
> {
>
>
--
uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/
Re: svn commit: r1341031 - /subversion/trunk/subversion/svn/props.c
Posted by Hyrum K Wright <hy...@wandisco.com>.
On Mon, May 21, 2012 at 9:03 AM, <st...@apache.org> wrote:
> Author: stsp
> Date: Mon May 21 14:03:46 2012
> New Revision: 1341031
>
> URL: http://svn.apache.org/viewvc?rev=1341031&view=rev
> Log:
> Make 'svn proplist' print property lists in sorted order.
> Avoids random output ordering with APR-1.4.6.
If we do this on a regular basis, it might be useful to implement a
wrapper which takes a baton and handler function and then calls the
handler with the hash key/value in sorted order. It might add some
overhead, but it also consolidates the sorting into one location,
rather than sprinkled everywhere. It doesn't matter much to me; just
a thought that arose upon review. :)
-Hyrum
> * subversion/svn/props.c
> (svn_cl__print_prop_hash, svn_cl__print_xml_prop_hash): Iterate over a sorted
> hash key array rather than iterating over the property hash table itself.
>
> Modified:
> subversion/trunk/subversion/svn/props.c
>
> Modified: subversion/trunk/subversion/svn/props.c
> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/props.c?rev=1341031&r1=1341030&r2=1341031&view=diff
> ==============================================================================
> --- subversion/trunk/subversion/svn/props.c (original)
> +++ subversion/trunk/subversion/svn/props.c Mon May 21 14:03:46 2012
> @@ -31,6 +31,7 @@
> #include "svn_cmdline.h"
> #include "svn_string.h"
> #include "svn_error.h"
> +#include "svn_sorts.h"
> #include "svn_subst.h"
> #include "svn_props.h"
> #include "svn_string.h"
> @@ -87,12 +88,16 @@ svn_cl__print_prop_hash(svn_stream_t *ou
> svn_boolean_t names_only,
> apr_pool_t *pool)
> {
> - apr_hash_index_t *hi;
> + apr_array_header_t *sorted_props;
> + int i;
>
> - for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
> + sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
> + pool);
> + for (i = 0; i < sorted_props->nelts; i++)
> {
> - const char *pname = svn__apr_hash_index_key(hi);
> - svn_string_t *propval = svn__apr_hash_index_val(hi);
> + svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
> + const char *pname = item.key;
> + svn_string_t *propval = item.value;
> const char *pname_stdout;
>
> if (svn_prop_needs_translation(pname))
> @@ -150,15 +155,19 @@ svn_cl__print_xml_prop_hash(svn_stringbu
> svn_boolean_t names_only,
> apr_pool_t *pool)
> {
> - apr_hash_index_t *hi;
> + apr_array_header_t *sorted_props;
> + int i;
>
> if (*outstr == NULL)
> *outstr = svn_stringbuf_create_empty(pool);
>
> - for (hi = apr_hash_first(pool, prop_hash); hi; hi = apr_hash_next(hi))
> + sorted_props = svn_sort__hash(prop_hash, svn_sort_compare_items_lexically,
> + pool);
> + for (i = 0; i < sorted_props->nelts; i++)
> {
> - const char *pname = svn__apr_hash_index_key(hi);
> - svn_string_t *propval = svn__apr_hash_index_val(hi);
> + svn_sort__item_t item = APR_ARRAY_IDX(sorted_props, i, svn_sort__item_t);
> + const char *pname = item.key;
> + svn_string_t *propval = item.value;
>
> if (names_only)
> {
>
>
--
uberSVN: Apache Subversion Made Easy
http://www.uberSVN.com/