You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2015/10/22 19:08:26 UTC

svn commit: r1710065 - in /subversion/trunk: subversion/include/svn_io.h subversion/libsvn_fs_x/reps.c subversion/libsvn_subr/deprecated.c subversion/libsvn_subr/stream.c subversion/libsvn_wc/old-and-busted.c tools/dev/x509-parser.c

Author: ivan
Date: Thu Oct 22 17:08:26 2015
New Revision: 1710065

URL: http://svn.apache.org/viewvc?rev=1710065&view=rev
Log:
Revv svn_string_from_stream() function and share implementation with
svn_stringbuf_from_stream().

Suggested by: julianf

* subversion/include/svn_io.h
  (svn_string_from_stream2): New.
  (svn_string_from_stream): Deprecate.

* subversion/libsvn_subr/stream.c
  (svn_string_from_stream2): Revv from svn_string_from_stream(): add LEN_HINT
   argument. Use svn_stringbuf_from_stream() as implementation.

* subversion/libsvn_subr/deprecated.c
  (svn_string_from_stream): Call svn_string_from_stream2() with LEN_HINT=0.

* subversion/libsvn_fs_x/reps.c
* subversion/libsvn_wc/old-and-busted.c
* tools/dev/x509-parser.c
  (svn_fs_x__reps_add_base, svn_wc__read_entries_old,
   get_der_cert_from_stream): Use svn_string_from_stream2() with
   LEN_HINT=SVN__STREAM_CHUNK_SIZE. It doesn't increase memory usage because
   we use same pool for SCRATCH and RESULT pool.

Modified:
    subversion/trunk/subversion/include/svn_io.h
    subversion/trunk/subversion/libsvn_fs_x/reps.c
    subversion/trunk/subversion/libsvn_subr/deprecated.c
    subversion/trunk/subversion/libsvn_subr/stream.c
    subversion/trunk/subversion/libsvn_wc/old-and-busted.c
    subversion/trunk/tools/dev/x509-parser.c

Modified: subversion/trunk/subversion/include/svn_io.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_io.h?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_io.h (original)
+++ subversion/trunk/subversion/include/svn_io.h Thu Oct 22 17:08:26 2015
@@ -1524,21 +1524,36 @@ svn_stream_contents_same(svn_boolean_t *
  * @a result. The stream will be closed when it has been successfully and
  * completely read.
  *
+ * @a len_hint specifies the initial capacity of the string buffer and
+ * may be 0.
+ *
  * The returned memory is allocated in @a result_pool, and any temporary
  * allocations are performed in @a scratch_pool.
  *
  * @note due to memory pseudo-reallocation behavior (due to pools), this
  *   can be a memory-intensive operation for large files.
  *
- * @since New in 1.6
+ * @since New in 1.10
+ */
+svn_error_t *
+svn_string_from_stream2(svn_string_t **result,
+                        svn_stream_t *stream,
+                        apr_size_t len_hint,
+                        apr_pool_t *result_pool,
+                        apr_pool_t *scratch_pool);
+
+/** Similar to svn_string_from_stream2(), but always passes 0 for
+ * @a len_hint.
+ *
+ * @deprecated Provided for backwards compatibility with the 1.9 API.
  */
+SVN_DEPRECATED
 svn_error_t *
 svn_string_from_stream(svn_string_t **result,
                        svn_stream_t *stream,
                        apr_pool_t *result_pool,
                        apr_pool_t *scratch_pool);
 
-
 /** A function type provided for use as a callback from
  * @c svn_stream_lazyopen_create().
  *

Modified: subversion/trunk/subversion/libsvn_fs_x/reps.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_fs_x/reps.c?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_fs_x/reps.c (original)
+++ subversion/trunk/subversion/libsvn_fs_x/reps.c Thu Oct 22 17:08:26 2015
@@ -417,8 +417,8 @@ svn_fs_x__reps_add_base(svn_fs_x__reps_b
   apr_size_t idx;
   SVN_ERR(svn_fs_x__get_contents(&stream, builder->fs, rep, FALSE,
                                  scratch_pool));
-  SVN_ERR(svn_string_from_stream(&contents, stream, scratch_pool,
-                                 scratch_pool));
+  SVN_ERR(svn_string_from_stream2(&contents, stream, SVN__STREAM_CHUNK_SIZE,
+                                  scratch_pool, scratch_pool));
   SVN_ERR(svn_fs_x__reps_add(&idx, builder, contents));
 
   base.revision = svn_fs_x__get_revnum(rep->id.change_set);

Modified: subversion/trunk/subversion/libsvn_subr/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/deprecated.c?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_subr/deprecated.c Thu Oct 22 17:08:26 2015
@@ -1209,6 +1209,16 @@ svn_stream_checksummed(svn_stream_t *str
   return s;
 }
 
+svn_error_t *
+svn_string_from_stream(svn_string_t **result,
+                       svn_stream_t *stream,
+                       apr_pool_t *result_pool,
+                       apr_pool_t *scratch_pool)
+{
+  return svn_error_trace(svn_string_from_stream2(result, stream, 0,
+                                                 result_pool, scratch_pool));
+}
+
 /*** From path.c ***/
 
 const char *

Modified: subversion/trunk/subversion/libsvn_subr/stream.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/stream.c?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/stream.c (original)
+++ subversion/trunk/subversion/libsvn_subr/stream.c Thu Oct 22 17:08:26 2015
@@ -1793,32 +1793,19 @@ svn_stream_for_stderr(svn_stream_t **err
 
 
 svn_error_t *
-svn_string_from_stream(svn_string_t **result,
-                       svn_stream_t *stream,
-                       apr_pool_t *result_pool,
-                       apr_pool_t *scratch_pool)
+svn_string_from_stream2(svn_string_t **result,
+                        svn_stream_t *stream,
+                        apr_size_t len_hint,
+                        apr_pool_t *result_pool,
+                        apr_pool_t *scratch_pool)
 {
-  svn_stringbuf_t *work = svn_stringbuf_create_ensure(SVN__STREAM_CHUNK_SIZE,
-                                                      result_pool);
-  char *buffer = apr_palloc(scratch_pool, SVN__STREAM_CHUNK_SIZE);
+  svn_stringbuf_t *buf;
 
-  while (1)
-    {
-      apr_size_t len = SVN__STREAM_CHUNK_SIZE;
-
-      SVN_ERR(svn_stream_read_full(stream, buffer, &len));
-      svn_stringbuf_appendbytes(work, buffer, len);
-
-      if (len < SVN__STREAM_CHUNK_SIZE)
-        break;
-    }
+  SVN_ERR(svn_stringbuf_from_stream(&buf, stream, len_hint, result_pool));
+  *result = svn_stringbuf__morph_into_string(buf);
 
   SVN_ERR(svn_stream_close(stream));
 
-  *result = apr_palloc(result_pool, sizeof(**result));
-  (*result)->data = work->data;
-  (*result)->len = work->len;
-
   return SVN_NO_ERROR;
 }
 

Modified: subversion/trunk/subversion/libsvn_wc/old-and-busted.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/old-and-busted.c?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/old-and-busted.c (original)
+++ subversion/trunk/subversion/libsvn_wc/old-and-busted.c Thu Oct 22 17:08:26 2015
@@ -1203,7 +1203,8 @@ svn_wc__read_entries_old(apr_hash_t **en
   /* Open the entries file. */
   SVN_ERR(svn_wc__open_adm_stream(&stream, dir_abspath, SVN_WC__ADM_ENTRIES,
                                   scratch_pool, scratch_pool));
-  SVN_ERR(svn_string_from_stream(&buf, stream, scratch_pool, scratch_pool));
+  SVN_ERR(svn_string_from_stream2(&buf, stream, SVN__STREAM_CHUNK_SIZE,
+                                  scratch_pool, scratch_pool));
 
   /* We own the returned data; it is modifiable, so cast away... */
   curp = (char *)buf->data;

Modified: subversion/trunk/tools/dev/x509-parser.c
URL: http://svn.apache.org/viewvc/subversion/trunk/tools/dev/x509-parser.c?rev=1710065&r1=1710064&r2=1710065&view=diff
==============================================================================
--- subversion/trunk/tools/dev/x509-parser.c (original)
+++ subversion/trunk/tools/dev/x509-parser.c Thu Oct 22 17:08:26 2015
@@ -94,7 +94,8 @@ get_der_cert_from_stream(const svn_strin
                          apr_pool_t *pool)
 {
   svn_string_t *raw;
-  SVN_ERR(svn_string_from_stream(&raw, in, pool, pool));
+  SVN_ERR(svn_string_from_stream2(&raw, in, SVN__STREAM_CHUNK_SIZE,
+                                  pool, pool));
 
   *der_cert = NULL;