subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1509090 - in /subversion/trunk/subversion: include/private/svn_subr_private.h libsvn_subr/spillbuf.c tests/libsvn_subr/spillbuf-test.c
Date Thu, 01 Aug 2013 06:24:38 GMT
Author: brane
Date: Thu Aug  1 06:24:37 2013
New Revision: 1509090

URL: http://svn.apache.org/r1509090
Log:
Add spill-all-data functionality to spillbufs.

* subversion/include/private/svn_subr_private.h
  (svn_spillbuf__create_extended): New spillbuf constructor.
* subversion/libsvn_subr/spillbuf.c
  (init_spillbuf_extended, init_spillbuf): Fix thinko: the temp_path field is
   set in in svn_spillbuf__write and should not be initialized.
  (svn_spillbuf__create_extended): Implement.
  (svn_spillbuf__write): Optionally write the in-memory contents to the
   newly created spill file.

* subversion/tests/libsvn_subr/spillbuf-test.c
  (test_spillbuf__basic, test_spillbuf_basic_spill_all,
   test_spillbuf__callback, test_spillbuf_callback_spill_all,
   test_spillbuf__file, test_spillbuf_file_spill_all,
   test_spillbuf__interleaving, test_spillbuf_interleaving_spill_all,
   test_spillbuf__rwfile, test_spillbuf_rwfile_spill_all,
   test_spillbuf__eof, test_spillbuf_eof_spill_all): New tests and helpers.
  (test_funcs): Add new tests.

Modified:
    subversion/trunk/subversion/include/private/svn_subr_private.h
    subversion/trunk/subversion/libsvn_subr/spillbuf.c
    subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c

Modified: subversion/trunk/subversion/include/private/svn_subr_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_subr_private.h?rev=1509090&r1=1509089&r2=1509090&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_subr_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_subr_private.h Thu Aug  1 06:24:37 2013
@@ -94,6 +94,14 @@ svn_spillbuf__create(apr_size_t blocksiz
                      apr_size_t maxsize,
                      apr_pool_t *result_pool);
 
+/* Create a spill buffer, with extra parameters.  */
+svn_spillbuf_t *
+svn_spillbuf__create_extended(apr_size_t blocksize,
+                              apr_size_t maxsize,
+                              svn_boolean_t delete_on_close,
+                              svn_boolean_t spill_all_contents,
+                              const char* dirpath,
+                              apr_pool_t *result_pool);
 
 /* Determine how much content is stored in the spill buffer.  */
 svn_filesize_t

Modified: subversion/trunk/subversion/libsvn_subr/spillbuf.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/spillbuf.c?rev=1509090&r1=1509089&r2=1509090&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/spillbuf.c (original)
+++ subversion/trunk/subversion/libsvn_subr/spillbuf.c Thu Aug  1 06:24:37 2013
@@ -121,7 +121,6 @@ init_spillbuf_extended(svn_spillbuf_t *b
                        svn_boolean_t delete_on_close,
                        svn_boolean_t spill_all_contents,
                        const char* dirpath,
-                       const char* temp_path,
                        apr_pool_t *result_pool)
 {
   buf->pool = result_pool;
@@ -130,7 +129,6 @@ init_spillbuf_extended(svn_spillbuf_t *b
   buf->delete_on_close = delete_on_close;
   buf->spill_all_contents = spill_all_contents;
   buf->dirpath = dirpath;
-  buf->temp_path = temp_path;
 }
 
 /* Common constructor for initializing spillbufs.
@@ -142,7 +140,7 @@ init_spillbuf(svn_spillbuf_t *buf,
               apr_pool_t *result_pool)
 {
   init_spillbuf_extended(buf, blocksize, maxsize,
-                         TRUE, FALSE, NULL, NULL,
+                         TRUE, FALSE, NULL,
                          result_pool);
 }
 
@@ -157,6 +155,21 @@ svn_spillbuf__create(apr_size_t blocksiz
 }
 
 
+svn_spillbuf_t *
+svn_spillbuf__create_extended(apr_size_t blocksize,
+                              apr_size_t maxsize,
+                              svn_boolean_t delete_on_close,
+                              svn_boolean_t spill_all_contents,
+                              const char* dirpath,
+                              apr_pool_t *result_pool)
+{
+  svn_spillbuf_t *buf = apr_pcalloc(result_pool, sizeof(*buf));
+  init_spillbuf_extended(buf, blocksize, maxsize,
+                         delete_on_close, spill_all_contents, dirpath,
+                         result_pool);
+  return buf;
+}
+
 svn_filesize_t
 svn_spillbuf__get_size(const svn_spillbuf_t *buf)
 {
@@ -221,6 +234,19 @@ svn_spillbuf__write(svn_spillbuf_t *buf,
                                         ? svn_io_file_del_on_close
                                         : svn_io_file_del_none),
                                        buf->pool, scratch_pool));
+
+      /* Optionally write the memory contents into the file. */
+      if (buf->spill_all_contents && buf->head != NULL)
+        {
+          mem = buf->head;
+          while (mem != NULL)
+            {
+              SVN_ERR(svn_io_file_write_full(buf->spill, mem->data, mem->size,
+                                             NULL, scratch_pool));
+              mem = mem->next;
+            }
+          buf->spill_start = buf->memory_size;
+        }
     }
 
   /* Once a spill file has been constructed, then we need to put all

Modified: subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c?rev=1509090&r1=1509089&r2=1509090&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/spillbuf-test.c Thu Aug  1 06:24:37 2013
@@ -57,10 +57,8 @@ check_read(svn_spillbuf_t *buf,
 
 
 static svn_error_t *
-test_spillbuf_basic(apr_pool_t *pool)
+test_spillbuf__basic(apr_pool_t *pool, apr_size_t len, svn_spillbuf_t *buf)
 {
-  apr_size_t len = strlen(basic_data);  /* Don't include basic_data's NUL  */
-  svn_spillbuf_t *buf = svn_spillbuf__create(len, 10 * len, pool);
   int i;
   const char *readptr;
   apr_size_t readlen;
@@ -87,6 +85,22 @@ test_spillbuf_basic(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_spillbuf_basic(apr_pool_t *pool)
+{
+  apr_size_t len = strlen(basic_data);  /* Don't include basic_data's NUL  */
+  svn_spillbuf_t *buf = svn_spillbuf__create(len, 10 * len, pool);
+  return test_spillbuf__basic(pool, len, buf);
+}
+
+static svn_error_t *
+test_spillbuf_basic_spill_all(apr_pool_t *pool)
+{
+  apr_size_t len = strlen(basic_data);  /* Don't include basic_data's NUL  */
+  svn_spillbuf_t *buf =
+    svn_spillbuf__create_extended(len, 10 * len, TRUE, TRUE, NULL, pool);
+  return test_spillbuf__basic(pool, len, buf);
+}
 
 static svn_error_t *
 read_callback(svn_boolean_t *stop,
@@ -107,12 +121,8 @@ read_callback(svn_boolean_t *stop,
 
 
 static svn_error_t *
-test_spillbuf_callback(apr_pool_t *pool)
+test_spillbuf__callback(apr_pool_t *pool, svn_spillbuf_t *buf)
 {
-  svn_spillbuf_t *buf = svn_spillbuf__create(
-                          sizeof(basic_data) /* blocksize */,
-                          10 * sizeof(basic_data) /* maxsize */,
-                          pool);
   int i;
   int counter;
   svn_boolean_t exhausted;
@@ -133,15 +143,31 @@ test_spillbuf_callback(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
-
 static svn_error_t *
-test_spillbuf_file(apr_pool_t *pool)
+test_spillbuf_callback(apr_pool_t *pool)
 {
-  apr_size_t altsize = sizeof(basic_data) + 2;
   svn_spillbuf_t *buf = svn_spillbuf__create(
-                          altsize /* blocksize */,
-                          2 * sizeof(basic_data) /* maxsize */,
+                          sizeof(basic_data) /* blocksize */,
+                          10 * sizeof(basic_data) /* maxsize */,
                           pool);
+  return test_spillbuf__callback(pool, buf);
+}
+
+static svn_error_t *
+test_spillbuf_callback_spill_all(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create_extended(
+                          sizeof(basic_data) /* blocksize */,
+                          10 * sizeof(basic_data) /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__callback(pool, buf);
+}
+
+static svn_error_t *
+test_spillbuf__file(apr_pool_t *pool, apr_size_t altsize, svn_spillbuf_t *buf)
+{
   int i;
   const char *readptr;
   apr_size_t readlen;
@@ -203,14 +229,33 @@ test_spillbuf_file(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_spillbuf_file(apr_pool_t *pool)
+{
+  apr_size_t altsize = sizeof(basic_data) + 2;
+  svn_spillbuf_t *buf = svn_spillbuf__create(
+                          altsize /* blocksize */,
+                          2 * sizeof(basic_data) /* maxsize */,
+                          pool);
+  return test_spillbuf__file(pool, altsize, buf);
+}
 
 static svn_error_t *
-test_spillbuf_interleaving(apr_pool_t *pool)
+test_spillbuf_file_spill_all(apr_pool_t *pool)
 {
-  svn_spillbuf_t *buf = svn_spillbuf__create(8 /* blocksize */,
-                                             15 /* maxsize */,
-                                             pool);
+  apr_size_t altsize = sizeof(basic_data) + 2;
+  svn_spillbuf_t *buf = svn_spillbuf__create_extended(
+                          altsize /* blocksize */,
+                          2 * sizeof(basic_data)  /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__file(pool, altsize, buf);
+}
 
+static svn_error_t *
+test_spillbuf__interleaving(apr_pool_t *pool, svn_spillbuf_t* buf)
+{
   SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
   SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
   /* now: two blocks: 8 and 4 bytes  */
@@ -238,6 +283,26 @@ test_spillbuf_interleaving(apr_pool_t *p
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_spillbuf_interleaving(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create(8 /* blocksize */,
+                                             15 /* maxsize */,
+                                             pool);
+  return test_spillbuf__interleaving(pool, buf);
+}
+
+static svn_error_t *
+test_spillbuf_interleaving_spill_all(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create_extended(
+                          8 /* blocksize */,
+                          15 /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__interleaving(pool, buf);
+}
 
 static svn_error_t *
 test_spillbuf_reader(apr_pool_t *pool)
@@ -319,14 +384,9 @@ test_spillbuf_stream(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
-
 static svn_error_t *
-test_spillbuf_rwfile(apr_pool_t *pool)
+test_spillbuf__rwfile(apr_pool_t *pool, svn_spillbuf_t *buf)
 {
-  svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */,
-                                             10 /* maxsize */,
-                                             pool);
-
   SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
   SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
   SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool));
@@ -360,14 +420,30 @@ test_spillbuf_rwfile(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
-
 static svn_error_t *
-test_spillbuf_eof(apr_pool_t *pool)
+test_spillbuf_rwfile(apr_pool_t *pool)
 {
   svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */,
                                              10 /* maxsize */,
                                              pool);
+  return test_spillbuf__rwfile(pool, buf);
+}
 
+static svn_error_t *
+test_spillbuf_rwfile_spill_all(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create_extended(
+                          4 /* blocksize */,
+                          10 /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__rwfile(pool, buf);
+}
+
+static svn_error_t *
+test_spillbuf__eof(apr_pool_t *pool, svn_spillbuf_t *buf)
+{
   SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
   SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
   /* now: two blocks: 4 and 2 bytes, and 6 bytes in spill file.  */
@@ -415,19 +491,51 @@ test_spillbuf_eof(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_spillbuf_eof(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */,
+                                             10 /* maxsize */,
+                                             pool);
+  return test_spillbuf__eof(pool, buf);
+}
+
+static svn_error_t *
+test_spillbuf_eof_spill_all(apr_pool_t *pool)
+{
+  svn_spillbuf_t *buf = svn_spillbuf__create_extended(
+                          4 /* blocksize */,
+                          10 /* maxsize */,
+                          TRUE /* delte on close */,
+                          TRUE /* spill all data */,
+                          NULL, pool);
+  return test_spillbuf__eof(pool, buf);
+}
 
 /* The test table.  */
 struct svn_test_descriptor_t test_funcs[] =
   {
     SVN_TEST_NULL,
     SVN_TEST_PASS2(test_spillbuf_basic, "basic spill buffer test"),
+    SVN_TEST_PASS2(test_spillbuf_basic_spill_all,
+                   "basic spill buffer test (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_callback, "spill buffer read callback"),
+    SVN_TEST_PASS2(test_spillbuf_callback_spill_all,
+                   "spill buffer read callback (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_file, "spill buffer file test"),
+    SVN_TEST_PASS2(test_spillbuf_file_spill_all,
+                   "spill buffer file test (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_interleaving,
                    "interleaving reads and writes"),
+    SVN_TEST_PASS2(test_spillbuf_interleaving_spill_all,
+                   "interleaving reads and writes (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_reader, "spill buffer reader test"),
     SVN_TEST_PASS2(test_spillbuf_stream, "spill buffer stream test"),
     SVN_TEST_PASS2(test_spillbuf_rwfile, "read/write spill file"),
+    SVN_TEST_PASS2(test_spillbuf_rwfile_spill_all,
+                   "read/write spill file (spill-all-data)"),
     SVN_TEST_PASS2(test_spillbuf_eof, "validate reaching EOF of spill file"),
+    SVN_TEST_PASS2(test_spillbuf_eof_spill_all,
+                   "validate reaching EOF (spill-all-data)"),
     SVN_TEST_NULL
   };



Mime
View raw message