You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ko...@apache.org on 2022/12/05 19:03:27 UTC

svn commit: r1905777 - in /subversion/branches/pristines-on-demand-on-mwf/subversion: libsvn_wc/adm_ops.c tests/libsvn_wc/wc-test.c

Author: kotkov
Date: Mon Dec  5 19:03:27 2022
New Revision: 1905777

URL: http://svn.apache.org/viewvc?rev=1905777&view=rev
Log:
On the 'pristines-on-demand-on-mwf' branch: Provide a custom implementation
for the deprecated svn_wc_get_pristine_copy_path() to ensure that we keep
its existing behavior, instead of emulating it with the new textbase layer
functions.

* subversion/libsvn_wc/adm_ops.c
  (get_pristine_copy_path): New function with a custom implementation that
   keeps the original behavior of svn_wc_get_pristine_copy_path().
  (svn_wc_get_pristine_copy_path): Call the new function.
  (nonexistent_path): Remove, was inlined into get_pristine_copy_path().

* subversion/tests/libsvn_wc/wc-test.c
  (test_get_pristine_copy_path): New test.
  (test_funcs): Run the new test.

Modified:
    subversion/branches/pristines-on-demand-on-mwf/subversion/libsvn_wc/adm_ops.c
    subversion/branches/pristines-on-demand-on-mwf/subversion/tests/libsvn_wc/wc-test.c

Modified: subversion/branches/pristines-on-demand-on-mwf/subversion/libsvn_wc/adm_ops.c
URL: http://svn.apache.org/viewvc/subversion/branches/pristines-on-demand-on-mwf/subversion/libsvn_wc/adm_ops.c?rev=1905777&r1=1905776&r2=1905777&view=diff
==============================================================================
--- subversion/branches/pristines-on-demand-on-mwf/subversion/libsvn_wc/adm_ops.c (original)
+++ subversion/branches/pristines-on-demand-on-mwf/subversion/libsvn_wc/adm_ops.c Mon Dec  5 19:03:27 2022
@@ -754,13 +754,86 @@ svn_wc_add_from_disk3(svn_wc_context_t *
   return SVN_NO_ERROR;
 }
 
-/* Return a path where nothing exists on disk, within the admin directory
-   belonging to the WCROOT_ABSPATH directory.  */
-static const char *
-nonexistent_path(const char *wcroot_abspath, apr_pool_t *scratch_pool)
+
+static svn_error_t *
+get_pristine_copy_path(const char **pristine_path_p,
+                       const char *local_abspath,
+                       svn_wc__db_t *db,
+                       apr_pool_t *result_pool,
+                       apr_pool_t *scratch_pool)
 {
-  return svn_wc__adm_child(wcroot_abspath, SVN_WC__ADM_NONEXISTENT_PATH,
-                           scratch_pool);
+  svn_boolean_t store_pristine;
+  svn_wc__db_status_t status;
+  svn_node_kind_t kind;
+  const svn_checksum_t *checksum;
+  const char *wcroot_abspath;
+
+  SVN_ERR(svn_wc__db_get_settings(NULL, &store_pristine, db,
+                                  local_abspath, scratch_pool));
+  if (!store_pristine)
+    return svn_error_create(SVN_ERR_WC_DEPRECATED_API_STORE_PRISTINE,
+                            NULL, NULL);
+
+  SVN_ERR(svn_wc__db_read_pristine_info(&status, &kind, NULL, NULL, NULL, NULL,
+                                        &checksum, NULL, NULL, NULL,
+                                        db, local_abspath,
+                                        scratch_pool, scratch_pool));
+
+  /* Sanity */
+  if (kind != svn_node_file)
+    return svn_error_createf(SVN_ERR_NODE_UNEXPECTED_KIND, NULL,
+                             _("Can only get the pristine contents of files; "
+                               "'%s' is not a file"),
+                             svn_dirent_local_style(local_abspath,
+                                                    scratch_pool));
+
+  if (status == svn_wc__db_status_not_present)
+    /* We know that the delete of this node has been committed.
+       This should be the same as if called on an unknown path. */
+    return svn_error_createf(SVN_ERR_WC_PATH_NOT_FOUND, NULL,
+                             _("Cannot get the pristine contents of '%s' "
+                               "because its delete is already committed"),
+                             svn_dirent_local_style(local_abspath,
+                                                    scratch_pool));
+  else if (status == svn_wc__db_status_server_excluded
+      || status == svn_wc__db_status_excluded
+      || status == svn_wc__db_status_incomplete)
+    return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                             _("Cannot get the pristine contents of '%s' "
+                               "because it has an unexpected status"),
+                             svn_dirent_local_style(local_abspath,
+                                                    scratch_pool));
+
+  SVN_ERR(svn_wc__db_get_wcroot(&wcroot_abspath, db, local_abspath,
+                                scratch_pool, scratch_pool));
+
+  if (checksum == NULL)
+    {
+      /* Return a path where nothing exists on disk, within the admin directory
+         belonging to the WCROOT_ABSPATH directory.  */
+      *pristine_path_p = svn_wc__adm_child(wcroot_abspath,
+                                           SVN_WC__ADM_NONEXISTENT_PATH,
+                                           result_pool);
+    }
+  else
+    {
+      svn_boolean_t present;
+
+      SVN_ERR(svn_wc__db_pristine_check(&present, NULL, db, local_abspath,
+                                        checksum, scratch_pool));
+      if (!present)
+        return svn_error_createf(SVN_ERR_WC_DB_ERROR, NULL,
+                                 _("The pristine text with checksum '%s' was "
+                                   "not found"),
+                                 svn_checksum_to_cstring_display(checksum,
+                                                                 scratch_pool));
+
+      SVN_ERR(svn_wc__db_pristine_get_future_path(pristine_path_p,
+                                                  wcroot_abspath, checksum,
+                                                  result_pool, scratch_pool));
+    }
+
+  return SVN_NO_ERROR;
 }
 
 
@@ -772,7 +845,6 @@ svn_wc_get_pristine_copy_path(const char
   svn_wc__db_t *db;
   const char *local_abspath;
   svn_error_t *err;
-  svn_boolean_t store_pristine;
 
   SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
 
@@ -780,36 +852,9 @@ svn_wc_get_pristine_copy_path(const char
   /* DB is now open. This is seemingly a "light" function that a caller
      may use repeatedly despite error return values. The rest of this
      function should aggressively close DB, even in the error case.  */
+  err = get_pristine_copy_path(pristine_path, local_abspath, db, pool, pool);
 
-  err = svn_wc__db_get_settings(NULL, &store_pristine, db, local_abspath, pool);
-  if (err)
-    return svn_error_compose_create(err, svn_wc__db_close(db));
-
-  if (!store_pristine)
-    {
-      err = svn_error_create(SVN_ERR_WC_DEPRECATED_API_STORE_PRISTINE,
-                             NULL, NULL);
-
-      return svn_error_compose_create(err, svn_wc__db_close(db));
-    }
-
-  err = svn_wc__textbase_setaside(pristine_path, db, local_abspath,
-                                  NULL, NULL, NULL, pool, pool);
-  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
-    {
-      /* The node doesn't exist, so return a non-existent path located
-         in WCROOT/.svn/  */
-      const char *wcroot_abspath;
-
-      svn_error_clear(err);
-
-      err = svn_wc__db_get_wcroot(&wcroot_abspath, db, local_abspath,
-                                  pool, pool);
-      if (err == NULL)
-        *pristine_path = nonexistent_path(wcroot_abspath, pool);
-    }
-
-   return svn_error_compose_create(err, svn_wc__db_close(db));
+  return svn_error_compose_create(err, svn_wc__db_close(db));
 }
 
 

Modified: subversion/branches/pristines-on-demand-on-mwf/subversion/tests/libsvn_wc/wc-test.c
URL: http://svn.apache.org/viewvc/subversion/branches/pristines-on-demand-on-mwf/subversion/tests/libsvn_wc/wc-test.c?rev=1905777&r1=1905776&r2=1905777&view=diff
==============================================================================
--- subversion/branches/pristines-on-demand-on-mwf/subversion/tests/libsvn_wc/wc-test.c (original)
+++ subversion/branches/pristines-on-demand-on-mwf/subversion/tests/libsvn_wc/wc-test.c Mon Dec  5 19:03:27 2022
@@ -771,6 +771,52 @@ test_internal_file_modified_eol_style(co
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+test_get_pristine_copy_path(const svn_test_opts_t *opts, apr_pool_t *pool)
+{
+  svn_test__sandbox_t b;
+  svn_boolean_t store_pristine;
+  const char *pristine_path;
+  svn_node_kind_t kind;
+  svn_stringbuf_t *actual_content;
+
+  SVN_ERR(svn_test__sandbox_create(&b, "get_pristine_copy_path", opts, pool));
+
+  SVN_ERR(svn_wc__db_get_settings(NULL, &store_pristine,
+                                  b.wc_ctx->db, b.wc_abspath, pool));
+  if (!store_pristine)
+    return svn_error_create(SVN_ERR_TEST_SKIPPED, NULL,
+                            "Test assumes a working copy with pristine");
+
+  SVN_ERR(sbox_file_write(&b, "file", "content"));
+  SVN_ERR(sbox_wc_add(&b, "file"));
+
+  SVN_ERR(svn_wc_get_pristine_copy_path(sbox_wc_path(&b, "file"),
+                                        &pristine_path, pool));
+  SVN_ERR(svn_io_check_path(pristine_path, &kind, pool));
+  SVN_TEST_INT_ASSERT(kind, svn_node_none);
+
+  SVN_ERR(sbox_wc_commit(&b, ""));
+
+  SVN_ERR(svn_wc_get_pristine_copy_path(sbox_wc_path(&b, "file"),
+                                        &pristine_path, pool));
+  SVN_ERR(svn_io_check_path(pristine_path, &kind, pool));
+  SVN_TEST_INT_ASSERT(kind, svn_node_file);
+  SVN_ERR(svn_stringbuf_from_file2(&actual_content, pristine_path, pool));
+  SVN_TEST_STRING_ASSERT(actual_content->data, "content");
+
+  SVN_ERR(sbox_wc_copy(&b, "file", "file2"));
+
+  SVN_ERR(svn_wc_get_pristine_copy_path(sbox_wc_path(&b, "file2"),
+                                        &pristine_path, pool));
+  SVN_ERR(svn_io_check_path(pristine_path, &kind, pool));
+  SVN_TEST_INT_ASSERT(kind, svn_node_file);
+  SVN_ERR(svn_stringbuf_from_file2(&actual_content, pristine_path, pool));
+  SVN_TEST_STRING_ASSERT(actual_content->data, "content");
+
+  return SVN_NO_ERROR;
+}
+
 /* ---------------------------------------------------------------------- */
 /* The list of test functions */
 
@@ -803,6 +849,8 @@ static struct svn_test_descriptor_t test
                        "test internal_file_modified with keywords"),
     SVN_TEST_OPTS_PASS(test_internal_file_modified_eol_style,
                        "test internal_file_modified with eol-style"),
+    SVN_TEST_OPTS_PASS(test_get_pristine_copy_path,
+                       "test svn_wc_get_pristine_copy_path"),
     SVN_TEST_NULL
   };