You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by ju...@apache.org on 2010/05/24 19:11:58 UTC

svn commit: r947718 - in /subversion/trunk/subversion/libsvn_wc: adm_files.c adm_files.h adm_ops.c diff.c workqueue.c

Author: julianfoad
Date: Mon May 24 17:11:58 2010
New Revision: 947718

URL: http://svn.apache.org/viewvc?rev=947718&view=rev
Log:
Change the svn_wc__...base_path_to_read() functions so that if the text-base
file is not present they return an error instead of returning a path to a
nonexistent file.  Most callers want to know, so this moves the disk
statting from the callers into the function.  In some cases this means an
extra disk stat will be done, but this code will all be changed to the new
pristine store soon so that doesn't matter.

* subversion/libsvn_wc/adm_files.h
  (svn_wc__text_base_path_to_read, svn_wc__text_revert_path_to_read,
   svn_wc__ultimate_base_text_path_to_read): Update the doc strings.

* subversion/libsvn_wc/adm_files.c
  (svn_wc__text_base_path_to_read, svn_wc__text_revert_path_to_read,
   svn_wc__ultimate_base_text_path_to_read): Return an error if the
    text-base file doesn't exist.
  (svn_wc__get_ultimate_base_contents, svn_wc__get_pristine_contents):
    Adjust calls to the new semantics.

* subversion/libsvn_wc/diff.c
  (get_nearest_pristine_text_as_file): Adjust calls to the new semantics.

* subversion/libsvn_wc/workqueue.c
  (verify_pristine_present, svn_wc__wq_build_file_install): Same.

* subversion/libsvn_wc/adm_ops.c
  (svn_wc_get_pristine_copy_path): Add a TODO comment to restore backward
    compatibility, because this change changes the behaviour in the case
    where the node has no pristine text.

Modified:
    subversion/trunk/subversion/libsvn_wc/adm_files.c
    subversion/trunk/subversion/libsvn_wc/adm_files.h
    subversion/trunk/subversion/libsvn_wc/adm_ops.c
    subversion/trunk/subversion/libsvn_wc/diff.c
    subversion/trunk/subversion/libsvn_wc/workqueue.c

Modified: subversion/trunk/subversion/libsvn_wc/adm_files.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_files.c?rev=947718&r1=947717&r2=947718&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_files.c (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_files.c Mon May 24 17:11:58 2010
@@ -272,6 +272,18 @@ svn_wc__text_base_path_to_read(const cha
 {
   SVN_ERR(svn_wc__text_base_path(result_abspath, db, local_abspath,
                                  result_pool));
+  /* Return an error if the file does not exist */
+  {
+    svn_node_kind_t kind;
+
+    SVN_ERR(svn_io_check_path(*result_abspath, &kind, result_pool));
+    if (kind != svn_node_file)
+      return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                               _("File '%s' has no text base"),
+                               svn_dirent_local_style(local_abspath,
+                                                      result_pool));
+  }
+
   return SVN_NO_ERROR;
 }
 
@@ -284,6 +296,18 @@ svn_wc__text_revert_path_to_read(const c
 {
   SVN_ERR(svn_wc__text_revert_path(result_abspath, db, local_abspath,
                                    result_pool));
+  /* Return an error if the file does not exist */
+  {
+    svn_node_kind_t kind;
+
+    SVN_ERR(svn_io_check_path(*result_abspath, &kind, result_pool));
+    if (kind != svn_node_file)
+      return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                               _("File '%s' has no text base"),
+                               svn_dirent_local_style(local_abspath,
+                                                      result_pool));
+  }
+
   return SVN_NO_ERROR;
 }
 
@@ -325,8 +349,21 @@ svn_wc__ultimate_base_text_path_to_read(
                                         apr_pool_t *result_pool,
                                         apr_pool_t *scratch_pool)
 {
-  return svn_wc__ultimate_base_text_path(result_abspath, db, local_abspath,
-                                         result_pool, scratch_pool);
+  SVN_ERR(svn_wc__ultimate_base_text_path(result_abspath, db, local_abspath,
+                                          result_pool, scratch_pool));
+  /* Return an error if the file does not exist */
+  {
+    svn_node_kind_t kind;
+
+    SVN_ERR(svn_io_check_path(*result_abspath, &kind, scratch_pool));
+    if (kind != svn_node_file)
+      return svn_error_createf(SVN_ERR_WC_PATH_UNEXPECTED_STATUS, NULL,
+                               _("File '%s' has no text base"),
+                               svn_dirent_local_style(local_abspath,
+                                                      scratch_pool));
+  }
+
+  return SVN_NO_ERROR;
 }
 
 
@@ -361,7 +398,6 @@ svn_wc__get_ultimate_base_contents(svn_s
   SVN_ERR_ASSERT(checksum != NULL);
   SVN_ERR(svn_wc__db_pristine_read(contents, db, local_abspath,
                                    checksum, result_pool, scratch_pool));
-  return SVN_NO_ERROR;
 #else
   const char *revert_base;
   svn_error_t *err;
@@ -369,22 +405,28 @@ svn_wc__get_ultimate_base_contents(svn_s
   SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
 
   /* If there's a WC-1 "revert base", open that. */
-  SVN_ERR(svn_wc__text_revert_path_to_read(&revert_base, db, local_abspath,
-                                           scratch_pool));
-  err = svn_stream_open_readonly(contents, revert_base,
-                                 result_pool, scratch_pool);
-  if (err)
+  err = svn_wc__text_revert_path_to_read(&revert_base, db, local_abspath,
+                                         scratch_pool);
+  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
     {
       svn_error_clear(err);
 
       /* There's no "revert base", so open the "normal base". */
-      SVN_ERR(svn_wc__text_base_path_to_read(&revert_base, db, local_abspath,
-                                             scratch_pool));
-      err = svn_stream_open_readonly(contents, revert_base,
-                                     result_pool, scratch_pool);
+      err = svn_wc__text_base_path_to_read(&revert_base, db, local_abspath,
+                                           scratch_pool);
+      if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+        {
+          svn_error_clear(err);
+          *contents = NULL;
+          return SVN_NO_ERROR;
+        }
     }
-  return err;
+  SVN_ERR(err);
+  SVN_ERR(svn_stream_open_readonly(contents, revert_base,
+                                   result_pool, scratch_pool));
 #endif
+
+  return SVN_NO_ERROR;
 }
 
 
@@ -458,22 +500,18 @@ svn_wc__get_pristine_contents(svn_stream
     const char *text_base;
     svn_error_t *err;
 
-    SVN_ERR(svn_wc__text_base_path_to_read(&text_base, db, local_abspath,
-                                           scratch_pool));
-    SVN_ERR_ASSERT(text_base != NULL);
-
+    err = svn_wc__text_base_path_to_read(&text_base, db, local_abspath,
+                                         scratch_pool);
     /* ### now for some ugly hackiness. right now, file externals will
        ### sometimes put their pristine contents into the revert base,
        ### because they think they're *replaced* nodes, rather than
        ### simple BASE nodes. watch out for this scenario, and
        ### compensate appropriately.  */
-    err = svn_stream_open_readonly(contents, text_base,
-                                   result_pool, scratch_pool);
     if (err)
       {
         svn_boolean_t file_external;
 
-        if (!APR_STATUS_IS_ENOENT(err->apr_err))
+        if (err->apr_err != SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
           return svn_error_return(err);
 
         SVN_ERR(svn_wc__internal_is_file_external(&file_external,
@@ -486,11 +524,12 @@ svn_wc__get_pristine_contents(svn_stream
 
         SVN_ERR(svn_wc__text_revert_path_to_read(&text_base, db, local_abspath,
                                                  scratch_pool));
-        return svn_stream_open_readonly(contents, text_base,
-                                   result_pool, scratch_pool);
       }
-    return SVN_NO_ERROR;
+    SVN_ERR(svn_stream_open_readonly(contents, text_base,
+                                     result_pool, scratch_pool));
   }
+
+  return SVN_NO_ERROR;
 }
 
 

Modified: subversion/trunk/subversion/libsvn_wc/adm_files.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_files.h?rev=947718&r1=947717&r2=947718&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_files.h (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_files.h Mon May 24 17:11:58 2010
@@ -153,8 +153,8 @@ svn_error_t *svn_wc__prop_path(const cha
      A path to the file in the pristine store.  This file will be removed or
      replaced the next time this or another Subversion client updates the WC.
 
-   If the node LOCAL_ABSPATH has no pristine text, the result is a path
-   where no file exists (in a directory that does exist).
+   If the node LOCAL_ABSPATH has no such pristine text, return an error of
+   type SVN_ERR_WC_PATH_UNEXPECTED_STATUS.
 
    Allocate *RESULT_PATH in RESULT_POOL.  */
 svn_error_t *
@@ -164,7 +164,10 @@ svn_wc__text_base_path_to_read(const cha
                                apr_pool_t *result_pool);
 
 /* Set *RESULT_ABSPATH to the path of the WC-1 "revert-base" text of the
-   versioned file LOCAL_ABSPATH in DB.  */
+   versioned file LOCAL_ABSPATH in DB.
+
+   If the node LOCAL_ABSPATH has no such pristine text, return an error of
+   type SVN_ERR_WC_PATH_UNEXPECTED_STATUS.  */
 svn_error_t *
 svn_wc__text_revert_path_to_read(const char **result_abspath,
                                  svn_wc__db_t *db,
@@ -185,7 +188,10 @@ svn_wc__ultimate_base_text_path(const ch
 /* Set *RESULT_ABSPATH to the path of the ultimate base text of the
    versioned file LOCAL_ABSPATH in DB.  In WC-1 terms this means the
    "normal text-base" or, if the node is replaced by a copy or move, the
-   "revert-base".  */
+   "revert-base".
+
+   If the node LOCAL_ABSPATH has no such pristine text, return an error of
+   type SVN_ERR_WC_PATH_UNEXPECTED_STATUS.  */
 svn_error_t *
 svn_wc__ultimate_base_text_path_to_read(const char **result_abspath,
                                         svn_wc__db_t *db,

Modified: subversion/trunk/subversion/libsvn_wc/adm_ops.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_ops.c?rev=947718&r1=947717&r2=947718&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_ops.c (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_ops.c Mon May 24 17:11:58 2010
@@ -2291,6 +2291,15 @@ svn_wc_get_pristine_copy_path(const char
 
   SVN_ERR(svn_wc__text_base_path_to_read(pristine_path, db, local_abspath,
                                          pool));
+  /* ### TODO for backward compatibility:
+   * if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+   *   {
+   *     svn_error_clear(err);
+   *     *pristine_path = nonexistent_path();
+   *     return SVN_NO_ERROR;
+   *   }
+   *  SVN_ERR(err);
+   */
 
   return svn_error_return(svn_wc__db_close(db));
 }

Modified: subversion/trunk/subversion/libsvn_wc/diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/diff.c?rev=947718&r1=947717&r2=947718&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/diff.c (original)
+++ subversion/trunk/subversion/libsvn_wc/diff.c Mon May 24 17:11:58 2010
@@ -154,15 +154,17 @@ get_nearest_pristine_text_as_file(const 
                                   const char *local_abspath,
                                   apr_pool_t *result_pool)
 {
-  svn_node_kind_t kind;
+  svn_error_t *err;
 
-  SVN_ERR(svn_wc__text_base_path_to_read(result_abspath, db, local_abspath,
-                                         result_pool));
+  err = svn_wc__text_base_path_to_read(result_abspath, db, local_abspath,
+                                         result_pool);
 
-  SVN_ERR(svn_io_check_path(*result_abspath, &kind, result_pool));
-  if (kind == svn_node_none)
-    SVN_ERR(svn_wc__text_revert_path_to_read(result_abspath, db, local_abspath,
-                                             result_pool));
+  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+    {
+      svn_error_clear(err);
+      err = svn_wc__text_revert_path_to_read(result_abspath, db, local_abspath,
+                                             result_pool);
+    }
 
   /* If there is no revert base to diff either, don't attempt to diff it.
      ### This is a band-aid.
@@ -172,11 +174,12 @@ get_nearest_pristine_text_as_file(const 
      ### Not sure how to properly tell apart a file added within a copied
      ### subtree from a copied file. But eventually we'll have to get the
      ### base text from the pristine store anyway and use tempfiles (or
-     ### streams, hopefully) for diffing, so all this horrible statting
-     ### the disk for text bases, and this hack, will just go away. */
-  SVN_ERR(svn_io_check_path(*result_abspath, &kind, result_pool));
-  if (kind == svn_node_none)
-    *result_abspath = NULL;
+     ### streams, hopefully) for diffing, so this hack will just go away. */
+  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+    {
+      svn_error_clear(err);
+      *result_abspath = NULL;
+    }
 
   return SVN_NO_ERROR;
 }

Modified: subversion/trunk/subversion/libsvn_wc/workqueue.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/workqueue.c?rev=947718&r1=947717&r2=947718&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/workqueue.c (original)
+++ subversion/trunk/subversion/libsvn_wc/workqueue.c Mon May 24 17:11:58 2010
@@ -488,29 +488,32 @@ verify_pristine_present(svn_wc__db_t *db
                         apr_pool_t *scratch_pool)
 {
   const char *base_abspath;
-  svn_node_kind_t check_kind;
+  svn_error_t *err;
 
   /* Verify that one of the two text bases are present.  */
-  SVN_ERR(svn_wc__text_base_path_to_read(&base_abspath, db, local_abspath,
-                                         scratch_pool));
-  SVN_ERR(svn_io_check_path(base_abspath, &check_kind, scratch_pool));
-  if (check_kind == svn_node_file)
-    return SVN_NO_ERROR;
-
-  SVN_ERR(svn_wc__text_revert_path_to_read(&base_abspath, db, local_abspath,
-                                           scratch_pool));
-  SVN_ERR(svn_io_check_path(base_abspath, &check_kind, scratch_pool));
-  if (check_kind == svn_node_file)
-    return SVN_NO_ERROR;
+  err = svn_wc__text_base_path_to_read(&base_abspath, db, local_abspath,
+                                       scratch_pool);
+  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+    {
+      svn_error_clear(err);
+      err = svn_wc__text_revert_path_to_read(&base_abspath, db, local_abspath,
+                                             scratch_pool);
+    }
 
   /* A real file must have either a regular or a revert text-base.
      If it has neither, we could be looking at the situation described
      in issue #2101, in which case all we can do is deliver the expected
      error.  */
-  return svn_error_createf(APR_ENOENT, NULL,
-                           _("Error restoring text for '%s'"),
-                           svn_dirent_local_style(local_abspath,
-                                                  scratch_pool));
+  if (err && err->apr_err == SVN_ERR_WC_PATH_UNEXPECTED_STATUS)
+    {
+      svn_error_clear(err);
+      return svn_error_createf(APR_ENOENT, NULL,
+                               _("Error restoring text for '%s'"),
+                               svn_dirent_local_style(local_abspath,
+                                                      scratch_pool));
+    }
+
+  return SVN_NO_ERROR;
 }