You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2011/04/15 17:38:26 UTC

svn commit: r1092744 - in /subversion/trunk/subversion/svnrdump: dump_editor.c svnrdump.c svnrdump.h util.c

Author: hwright
Date: Fri Apr 15 15:38:25 2011
New Revision: 1092744

URL: http://svn.apache.org/viewvc?rev=1092744&view=rev
Log:
Avoid a function with magical side effects by introducing an output parameter
instead of changing the hash inplace.

* subversion/svnrdump/svnrdump.c
  (replay_revstart): Update caller.

* subversion/svnrdump/svnrdump.h
  (svn_rdump__normalize_props): Add output parameter and update docs.

* subversion/svnrdump/dump_editor.c
  (do_dump_props): Update caller.
 
* subversion/svnrdump/util.c
  (svn_rdump__normalize_props): Add output parameter, and populate it from
    the input param.

Modified:
    subversion/trunk/subversion/svnrdump/dump_editor.c
    subversion/trunk/subversion/svnrdump/svnrdump.c
    subversion/trunk/subversion/svnrdump/svnrdump.h
    subversion/trunk/subversion/svnrdump/util.c

Modified: subversion/trunk/subversion/svnrdump/dump_editor.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/dump_editor.c?rev=1092744&r1=1092743&r2=1092744&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/dump_editor.c (original)
+++ subversion/trunk/subversion/svnrdump/dump_editor.c Fri Apr 15 15:38:25 2011
@@ -174,14 +174,15 @@ do_dump_props(struct dump_edit_baton *eb
               apr_pool_t *pool)
 {
   svn_stream_t *propstream;
+  apr_hash_t *normal_props;
 
   if (trigger_var && !*trigger_var)
     return SVN_NO_ERROR;
 
-  SVN_ERR(svn_rdump__normalize_props(eb->props, eb->pool));
+  SVN_ERR(svn_rdump__normalize_props(&normal_props, eb->props, eb->pool));
   svn_stringbuf_setempty(eb->propstring);
   propstream = svn_stream_from_stringbuf(eb->propstring, eb->pool);
-  SVN_ERR(svn_hash_write_incremental(eb->props, eb->deleted_props,
+  SVN_ERR(svn_hash_write_incremental(normal_props, eb->deleted_props,
                                      propstream, "PROPS-END", pool));
   SVN_ERR(svn_stream_close(propstream));
 

Modified: subversion/trunk/subversion/svnrdump/svnrdump.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/svnrdump.c?rev=1092744&r1=1092743&r2=1092744&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/svnrdump.c (original)
+++ subversion/trunk/subversion/svnrdump/svnrdump.c Fri Apr 15 15:38:25 2011
@@ -178,6 +178,7 @@ replay_revstart(svn_revnum_t revision,
                 apr_pool_t *pool)
 {
   struct replay_baton *rb = replay_baton;
+  apr_hash_t *normal_props;
   svn_stringbuf_t *propstring;
   svn_stream_t *stdout_stream;
   svn_stream_t *revprop_stream;
@@ -188,10 +189,10 @@ replay_revstart(svn_revnum_t revision,
   SVN_ERR(svn_stream_printf(stdout_stream, pool,
                             SVN_REPOS_DUMPFILE_REVISION_NUMBER
                             ": %ld\n", revision));
-  SVN_ERR(svn_rdump__normalize_props(rev_props, pool));
+  SVN_ERR(svn_rdump__normalize_props(&normal_props, rev_props, pool));
   propstring = svn_stringbuf_create_ensure(0, pool);
   revprop_stream = svn_stream_from_stringbuf(propstring, pool);
-  SVN_ERR(svn_hash_write2(rev_props, revprop_stream, "PROPS-END", pool));
+  SVN_ERR(svn_hash_write2(normal_props, revprop_stream, "PROPS-END", pool));
   SVN_ERR(svn_stream_close(revprop_stream));
 
   /* Prop-content-length: 13 */

Modified: subversion/trunk/subversion/svnrdump/svnrdump.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/svnrdump.h?rev=1092744&r1=1092743&r2=1092744&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/svnrdump.h (original)
+++ subversion/trunk/subversion/svnrdump/svnrdump.h Fri Apr 15 15:38:25 2011
@@ -72,10 +72,16 @@ svn_rdump__load_dumpstream(svn_stream_t 
 /* Normalize the line ending style of the values of properties in PROPS
  * that "need translation" (according to svn_prop_needs_translation(),
  * currently all svn:* props) so that they contain only LF (\n) line endings.
+ *
+ * Put the normalized props into NORMAL_PROPS, allocated in RESULT_POOL.
+ *
+ * Note: this function does not do a deep copy; it is expected that PROPS has
+ * a longer lifetime than NORMAL_PROPS.
  */
 svn_error_t *
-svn_rdump__normalize_props(apr_hash_t *props,
-                           apr_pool_t *pool);
+svn_rdump__normalize_props(apr_hash_t **normal_props,
+                           apr_hash_t *props,
+                           apr_pool_t *result_pool);
 
 #ifdef __cplusplus
 }

Modified: subversion/trunk/subversion/svnrdump/util.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/util.c?rev=1092744&r1=1092743&r2=1092744&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/util.c (original)
+++ subversion/trunk/subversion/svnrdump/util.c Fri Apr 15 15:38:25 2011
@@ -30,17 +30,17 @@
 #include "svnrdump.h"
 
 
-/* Normalize the line ending style of the values of properties in PROPS
- * that "need translation" (according to svn_prop_needs_translation(),
- * currently all svn:* props) so that they contain only LF (\n) line endings.
- */
 svn_error_t *
-svn_rdump__normalize_props(apr_hash_t *props,
-                           apr_pool_t *pool)
+svn_rdump__normalize_props(apr_hash_t **normal_props,
+                           apr_hash_t *props,
+                           apr_pool_t *result_pool)
 {
   apr_hash_index_t *hi;
 
-  for (hi = apr_hash_first(pool, props); hi; hi = apr_hash_next(hi))
+  *normal_props = apr_hash_make(result_pool);
+
+  for (hi = apr_hash_first(result_pool, props); hi;
+        hi = apr_hash_next(hi))
     {
       const char *key = svn__apr_hash_index_key(hi);
       const svn_string_t *value = svn__apr_hash_index_val(hi);
@@ -52,10 +52,11 @@ svn_rdump__normalize_props(apr_hash_t *p
           SVN_ERR(svn_subst_translate_cstring2(value->data, &cstring,
                                                "\n", TRUE,
                                                NULL, FALSE,
-                                               pool));
-          value = svn_string_create(cstring, pool);
-          apr_hash_set(props, key, APR_HASH_KEY_STRING, value);
+                                               result_pool));
+          value = svn_string_create(cstring, result_pool);
         }
+
+      apr_hash_set(*normal_props, key, APR_HASH_KEY_STRING, value);
     }
   return SVN_NO_ERROR;
 }