You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2014/03/13 16:55:14 UTC

svn commit: r1577215 - in /subversion/trunk/subversion: libsvn_wc/merge.c libsvn_wc/wc_db.h libsvn_wc/wc_db_pristine.c tests/libsvn_wc/pristine-store-test.c

Author: rhuijben
Date: Thu Mar 13 15:55:14 2014
New Revision: 1577215

URL: http://svn.apache.org/r1577215
Log:
Make the few remaining places that prepare files for installing use
svn_wc__db_pristine_prepare_install() to allow further refactoring the
pristine install work.

* subversion/libsvn_wc/merge.c
  (merge_file_trivial): Use the same api to obtain a tempdir as the rest
    of the merge code.

* subversion/libsvn_wc/wc_db.h
  (svn_wc__db_pristine_get_tempdir): Remove function.

* subversion/libsvn_wc/wc_db_pristine.c
  (svn_wc__db_pristine_get_tempdir): Remove function.
  (pristine_get_tempdir): Integrate svn_wc__db_pristine_get_tempdir.

* subversion/tests/libsvn_wc/pristine-store-test.c
  (write_and_checksum_temp_file): Remove function.
  (pristine_write_read,
   pristine_delete_while_open,
   reject_mismatching_text): Use svn_wc__db_pristine_prepare_install.

Modified:
    subversion/trunk/subversion/libsvn_wc/merge.c
    subversion/trunk/subversion/libsvn_wc/wc_db.h
    subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c
    subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c

Modified: subversion/trunk/subversion/libsvn_wc/merge.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/merge.c?rev=1577215&r1=1577214&r2=1577215&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/merge.c (original)
+++ subversion/trunk/subversion/libsvn_wc/merge.c Thu Mar 13 15:55:14 2014
@@ -732,10 +732,10 @@ merge_file_trivial(svn_skel_t **work_ite
                                                    scratch_pool,
                                                    scratch_pool));
 
-                  SVN_ERR(svn_wc__db_pristine_get_tempdir(&tmp_dir, db,
-                                                          target_abspath,
-                                                          scratch_pool,
-                                                          scratch_pool));
+                  SVN_ERR(svn_wc__db_temp_wcroot_tempdir(&tmp_dir, db,
+                                                         target_abspath,
+                                                         scratch_pool,
+                                                         scratch_pool));
 
                   SVN_ERR(svn_stream_open_unique(&tmp_dst, &right_abspath,
                                                  tmp_dir, svn_io_file_del_none,

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.h?rev=1577215&r1=1577214&r2=1577215&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.h (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.h Thu Mar 13 15:55:14 2014
@@ -953,21 +953,6 @@ svn_wc__db_pristine_read(svn_stream_t **
                          apr_pool_t *result_pool,
                          apr_pool_t *scratch_pool);
 
-
-/* Set *TEMP_DIR_ABSPATH to a directory in which the caller should create
-   a uniquely named file for later installation as a pristine text file.
-
-   The directory is guaranteed to be one that svn_wc__db_pristine_install()
-   can use: specifically, one from which it can atomically move the file.
-
-   Allocate *TEMP_DIR_ABSPATH in RESULT_POOL. */
-svn_error_t *
-svn_wc__db_pristine_get_tempdir(const char **temp_dir_abspath,
-                                svn_wc__db_t *db,
-                                const char *wri_abspath,
-                                apr_pool_t *result_pool,
-                                apr_pool_t *scratch_pool);
-
 /* Open a writable stream to a temporary text base, ready for installing
    into the pristine store.  Set *STREAM to the opened stream and
    *TEMP_BASE_ABSPATH to the path to the temporary file.  The temporary

Modified: subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c?rev=1577215&r1=1577214&r2=1577215&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db_pristine.c Thu Mar 13 15:55:14 2014
@@ -256,28 +256,6 @@ pristine_get_tempdir(svn_wc__db_wcroot_t
                               PRISTINE_TEMPDIR_RELPATH, SVN_VA_NULL);
 }
 
-svn_error_t *
-svn_wc__db_pristine_get_tempdir(const char **temp_dir_abspath,
-                                svn_wc__db_t *db,
-                                const char *wri_abspath,
-                                apr_pool_t *result_pool,
-                                apr_pool_t *scratch_pool)
-{
-  svn_wc__db_wcroot_t *wcroot;
-  const char *local_relpath;
-
-  SVN_ERR_ASSERT(temp_dir_abspath != NULL);
-  SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
-
-  SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
-                              wri_abspath, scratch_pool, scratch_pool));
-  VERIFY_USABLE_WCROOT(wcroot);
-
-  *temp_dir_abspath = pristine_get_tempdir(wcroot, result_pool, scratch_pool);
-  return SVN_NO_ERROR;
-}
-
-
 /* Install the pristine text described by BATON into the pristine store of
  * SDB.  If it is already stored then just delete the new file
  * BATON->tempfile_abspath.
@@ -388,11 +366,18 @@ svn_wc__db_pristine_prepare_install(svn_
                                     apr_pool_t *result_pool,
                                     apr_pool_t *scratch_pool)
 {
+  svn_wc__db_wcroot_t *wcroot;
+  const char *local_relpath;
   const char *temp_dir_abspath;
+
   SVN_ERR_ASSERT(svn_dirent_is_absolute(wri_abspath));
 
-  SVN_ERR(svn_wc__db_pristine_get_tempdir(&temp_dir_abspath, db, wri_abspath,
-                                          scratch_pool, scratch_pool));
+  SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
+                              wri_abspath, scratch_pool, scratch_pool));
+  VERIFY_USABLE_WCROOT(wcroot);
+
+  temp_dir_abspath = pristine_get_tempdir(wcroot, scratch_pool, scratch_pool);
+
   SVN_ERR(svn_stream_open_unique(stream,
                                  temp_base_abspath,
                                  temp_dir_abspath,

Modified: subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c?rev=1577215&r1=1577214&r2=1577215&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/pristine-store-test.c Thu Mar 13 15:55:14 2014
@@ -70,40 +70,6 @@ create_repos_and_wc(const char **wc_absp
   return SVN_NO_ERROR;
 }
 
-
-/* Write the string DATA into a new unique-named file in the directory
- * DIR_ABSPATH.  Set *FILE_ABSPATH to its absolute path and *CHECKSUM_SHA1
- * and *CHECKSUM_MD5 to its SHA-1 and MD-5 checksums.
- *
- * CHECKSUM_SHA1 and/or CHECKSUM_MD5 may be null if not required. */
-static svn_error_t *
-write_and_checksum_temp_file(const char **file_abspath,
-                             svn_checksum_t **sha1_checksum,
-                             svn_checksum_t **md5_checksum,
-                             const char *data,
-                             const char *dir_abspath,
-                             apr_pool_t *pool)
-{
-  apr_file_t *file;
-
-  SVN_ERR(svn_io_open_unique_file3(&file, file_abspath,
-                                   dir_abspath, svn_io_file_del_none,
-                                   pool, pool));
-
-  SVN_ERR(svn_io_file_write_full(file, data, strlen(data), NULL, pool));
-  SVN_ERR(svn_io_file_close(file, pool));
-
-  if (sha1_checksum)
-    SVN_ERR(svn_io_file_checksum2(sha1_checksum, *file_abspath,
-                                  svn_checksum_sha1, pool));
-  if (md5_checksum)
-    SVN_ERR(svn_io_file_checksum2(md5_checksum, *file_abspath,
-                                  svn_checksum_md5, pool));
-
-  return SVN_NO_ERROR;
-}
-
-
 /* Exercise the pristine text API with a simple write and read. */
 static svn_error_t *
 pristine_write_read(const svn_test_opts_t *opts,
@@ -113,6 +79,8 @@ pristine_write_read(const svn_test_opts_
   const char *wc_abspath;
 
   const char *pristine_tmp_abspath;
+  svn_stream_t *pristine_stream;
+  apr_size_t sz;
 
   const char data[] = "Blah";
   svn_string_t *data_string = svn_string_create(data, pool);
@@ -123,15 +91,15 @@ pristine_write_read(const svn_test_opts_
 
   /* Write DATA into a new temporary pristine file, set PRISTINE_TMP_ABSPATH
    * to its path and set DATA_SHA1 and DATA_MD5 to its checksums. */
-  {
-    const char *pristine_tmp_dir;
-
-    SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
-                                            wc_abspath, pool, pool));
-    SVN_ERR(write_and_checksum_temp_file(&pristine_tmp_abspath,
-                                         &data_sha1, &data_md5,
-                                         data, pristine_tmp_dir, pool));
-  }
+  SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream,
+                                              &pristine_tmp_abspath,
+                                              &data_md5, &data_sha1,
+                                              db, wc_abspath,
+                                              pool, pool));
+
+  sz = strlen(data);
+  SVN_ERR(svn_stream_write(pristine_stream, data, &sz));
+  SVN_ERR(svn_stream_close(pristine_stream));
 
   /* Ensure it's not already in the store. */
   {
@@ -209,8 +177,10 @@ pristine_delete_while_open(const svn_tes
 {
   svn_wc__db_t *db;
   const char *wc_abspath;
-  const char *pristine_tmp_dir;
+  const char *pristine_tmp_abspath;
+  svn_stream_t *pristine_stream;
   svn_stream_t *contents;
+  apr_size_t sz;
 
   const char data[] = "Blah";
   svn_checksum_t *data_sha1, *data_md5;
@@ -218,17 +188,17 @@ pristine_delete_while_open(const svn_tes
   SVN_ERR(create_repos_and_wc(&wc_abspath, &db,
                               "pristine_delete_while_open", opts, pool));
 
-  SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
-                                          wc_abspath, pool, pool));
-
-  /* Install a pristine text. */
-  {
-    const char *path;
-
-    SVN_ERR(write_and_checksum_temp_file(&path, &data_sha1, &data_md5,
-                                         data, pristine_tmp_dir, pool));
-    SVN_ERR(svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool));
-  }
+  SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream,
+                                              &pristine_tmp_abspath,
+                                              &data_md5, &data_sha1,
+                                              db, wc_abspath,
+                                              pool, pool));
+
+  sz = strlen(data);
+  SVN_ERR(svn_stream_write(pristine_stream, data, &sz));
+  SVN_ERR(svn_stream_close(pristine_stream));
+  SVN_ERR(svn_wc__db_pristine_install(db, pristine_tmp_abspath,
+                                      data_sha1, data_md5, pool));
 
   /* Open it for reading */
   SVN_ERR(svn_wc__db_pristine_read(&contents, NULL, db, wc_abspath, data_sha1,
@@ -276,7 +246,6 @@ reject_mismatching_text(const svn_test_o
 #ifdef SVN_DEBUG  /* The pristine store only checks this in debug mode. */
   svn_wc__db_t *db;
   const char *wc_abspath;
-  const char *pristine_tmp_dir;
 
   const char data[] = "Blah";
   svn_checksum_t *data_sha1, *data_md5;
@@ -286,28 +255,47 @@ reject_mismatching_text(const svn_test_o
   SVN_ERR(create_repos_and_wc(&wc_abspath, &db,
                               "reject_mismatching_text", opts, pool));
 
-  SVN_ERR(svn_wc__db_pristine_get_tempdir(&pristine_tmp_dir, db,
-                                          wc_abspath, pool, pool));
-
   /* Install a pristine text. */
   {
-    const char *path;
-
-    SVN_ERR(write_and_checksum_temp_file(&path, &data_sha1, &data_md5,
-                                         data, pristine_tmp_dir, pool));
-    SVN_ERR(svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool));
+    const char *pristine_abspath;
+    svn_stream_t *pristine_stream;
+    apr_size_t sz;
+
+    SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream,
+                                                &pristine_abspath,
+                                                &data_md5, &data_sha1,
+                                                db, wc_abspath,
+                                                pool, pool));
+
+    sz = strlen(data);
+    SVN_ERR(svn_stream_write(pristine_stream, data, &sz));
+    SVN_ERR(svn_stream_close(pristine_stream));
+
+    SVN_ERR(svn_wc__db_pristine_install(db, pristine_abspath,
+                                        data_sha1, data_md5,
+                                        pool));
   }
 
   /* Try to install the wrong pristine text against the same checksum.
    * Should fail. */
   {
-    svn_error_t *err;
-    const char *path;
-
-    SVN_ERR(write_and_checksum_temp_file(&path, NULL, NULL,
-                                         data2, pristine_tmp_dir, pool));
-    err = svn_wc__db_pristine_install(db, path, data_sha1, data_md5, pool);
-    SVN_TEST_ASSERT_ERROR(err, SVN_ERR_WC_CORRUPT_TEXT_BASE);
+    const char *pristine_abspath;
+    svn_stream_t *pristine_stream;
+    apr_size_t sz;
+
+    SVN_ERR(svn_wc__db_pristine_prepare_install(&pristine_stream,
+                                                &pristine_abspath,
+                                                &data_md5, &data_sha1,
+                                                db, wc_abspath,
+                                                pool, pool));
+
+    sz = strlen(data2);
+    SVN_ERR(svn_stream_write(pristine_stream, data2, &sz));
+    SVN_ERR(svn_stream_close(pristine_stream));
+
+    SVN_ERR(svn_wc__db_pristine_install(db, pristine_abspath,
+                                        data_sha1, data_md5,
+                                        pool));
   }
 
   return SVN_NO_ERROR;