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 2011/03/14 13:00:21 UTC

svn commit: r1081342 - in /subversion/trunk/subversion: include/private/svn_wc_private.h libsvn_wc/node.c libsvn_wc/wc-queries.sql libsvn_wc/wc_db.c libsvn_wc/wc_db.h tests/libsvn_wc/op-depth-test.c

Author: julianfoad
Date: Mon Mar 14 12:00:20 2011
New Revision: 1081342

URL: http://svn.apache.org/viewvc?rev=1081342&view=rev
Log:
Add new variants of WC functions for listing the children of a directory.
The new variants do not include any paths that were merely children of some
base or underlying directory that existed at the same path but has been
replaced.  This works towards fixing issue #3468 "children of replaced
directories cannot be deleted post-replace".

* subversion/include/private/svn_wc_private.h
  (svn_wc__node_get_children2): New function.

* subversion/libsvn_wc/node.c
  (filter_and_make_absolute): New function, factored out of ...
  (svn_wc__node_get_children): ... here.
  (svn_wc__node_get_children2): New function.

* subversion/libsvn_wc/wc_db.h
  (svn_wc__db_read_children_info): Mention this aspect of the behaviour.
  (svn_wc__db_read_children2): New function.

* subversion/libsvn_wc/wc_db.c
  (gather_children2, svn_wc__db_read_children2): New functions.

* subversion/libsvn_wc/wc-queries.sql
  (STMT_SELECT_NODE_CHILDREN): Document this statement.
  (STMT_SELECT_WORKING_CHILDREN): New statement.

* subversion/tests/libsvn_wc/op-depth-test.c
  (check_hash_keys, CHECK_HASH, check_array_strings, CHECK_ARRAY): New
    functions and macros.
  (test_children_of_replaced_dir): New test.
  (test_funcs): Add it.

Modified:
    subversion/trunk/subversion/include/private/svn_wc_private.h
    subversion/trunk/subversion/libsvn_wc/node.c
    subversion/trunk/subversion/libsvn_wc/wc-queries.sql
    subversion/trunk/subversion/libsvn_wc/wc_db.c
    subversion/trunk/subversion/libsvn_wc/wc_db.h
    subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c

Modified: subversion/trunk/subversion/include/private/svn_wc_private.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_wc_private.h?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_wc_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_wc_private.h Mon Mar 14 12:00:20 2011
@@ -195,9 +195,35 @@ svn_wc__status2_from_3(svn_wc_status2_t 
 
 
 /**
- * Fetch the absolute paths of all the working children of @a dir_abspath
- * into @a *children, allocated in @a result_pool.  Use @a wc_ctx to access
- * the working copy, and @a scratch_pool for all temporary allocations.
+ * Set @a *children to a new array of the immediate children of the working
+ * node at @a dir_abspath.  The elements of @a *children are (const char *)
+ * absolute paths.
+ *
+ * Include children that are scheduled for deletion.  Iff @a show_hidden
+ * is true, also include children that are 'excluded' or 'absent' or
+ * 'not-present'.
+ *
+ * Return every path that refers to a child of the working node at
+ * @a dir_abspath.  Do not include a path just because it was a child of a
+ * deleted directory that existed at @a dir_abspath if that directory is now
+ * sheduled to be replaced by the working node at @a dir_abspath.
+ *
+ * Allocate @a *children in @a result_pool.  Use @a wc_ctx to access the
+ * working copy, and @a scratch_pool for all temporary allocations.
+ */
+svn_error_t *
+svn_wc__node_get_children2(const apr_array_header_t **children,
+                           svn_wc_context_t *wc_ctx,
+                           const char *dir_abspath,
+                           svn_boolean_t show_hidden,
+                           apr_pool_t *result_pool,
+                           apr_pool_t *scratch_pool);
+
+/**
+ * Like svn_wc__node_get_children2(), except also include any path that was
+ * a child of a deleted directory that existed at @a dir_abspath, even if
+ * that directory is now scheduled to be replaced by the working node at
+ * @a dir_abspath.
  */
 svn_error_t *
 svn_wc__node_get_children(const apr_array_header_t **children,

Modified: subversion/trunk/subversion/libsvn_wc/node.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/node.c?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/node.c (original)
+++ subversion/trunk/subversion/libsvn_wc/node.c Mon Mar 14 12:00:20 2011
@@ -53,23 +53,25 @@
 #include "private/svn_wc_private.h"
 
 
-svn_error_t *
-svn_wc__node_get_children(const apr_array_header_t **children,
-                          svn_wc_context_t *wc_ctx,
-                          const char *dir_abspath,
-                          svn_boolean_t show_hidden,
-                          apr_pool_t *result_pool,
-                          apr_pool_t *scratch_pool)
+/* Set *CHILDREN_ABSPATHS to a new array of the full paths formed by joining
+ * each name in REL_CHILDREN onto DIR_ABSPATH.  If SHOW_HIDDEN is false then
+ * omit any paths that are reported as 'hidden' by svn_wc__db_node_hidden().
+ *
+ * Allocate the output array and its elements in RESULT_POOL. */
+static svn_error_t *
+filter_and_make_absolute(const apr_array_header_t **children_abspaths,
+                         svn_wc_context_t *wc_ctx,
+                         const char *dir_abspath,
+                         const apr_array_header_t *rel_children,
+                         svn_boolean_t show_hidden,
+                         apr_pool_t *result_pool,
+                         apr_pool_t *scratch_pool)
 {
-  const apr_array_header_t *rel_children;
-  apr_array_header_t *childs;
+  apr_array_header_t *children;
   int i;
 
-  SVN_ERR(svn_wc__db_read_children(&rel_children, wc_ctx->db, dir_abspath,
-                                   scratch_pool, scratch_pool));
-
-  childs = apr_array_make(result_pool, rel_children->nelts,
-                             sizeof(const char *));
+  children = apr_array_make(result_pool, rel_children->nelts,
+                            sizeof(const char *));
   for (i = 0; i < rel_children->nelts; i++)
     {
       const char *child_abspath = svn_dirent_join(dir_abspath,
@@ -89,11 +91,48 @@ svn_wc__node_get_children(const apr_arra
             continue;
         }
 
-      APR_ARRAY_PUSH(childs, const char *) = child_abspath;
+      APR_ARRAY_PUSH(children, const char *) = child_abspath;
     }
 
-  *children = childs;
+  *children_abspaths = children;
+
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_wc__node_get_children2(const apr_array_header_t **children,
+                           svn_wc_context_t *wc_ctx,
+                           const char *dir_abspath,
+                           svn_boolean_t show_hidden,
+                           apr_pool_t *result_pool,
+                           apr_pool_t *scratch_pool)
+{
+  const apr_array_header_t *rel_children;
+
+  SVN_ERR(svn_wc__db_read_children2(&rel_children, wc_ctx->db, dir_abspath,
+                                    scratch_pool, scratch_pool));
+  SVN_ERR(filter_and_make_absolute(children, wc_ctx, dir_abspath,
+                                   rel_children, show_hidden,
+                                   result_pool, scratch_pool));
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_wc__node_get_children(const apr_array_header_t **children,
+                          svn_wc_context_t *wc_ctx,
+                          const char *dir_abspath,
+                          svn_boolean_t show_hidden,
+                          apr_pool_t *result_pool,
+                          apr_pool_t *scratch_pool)
+{
+  const apr_array_header_t *rel_children;
 
+  SVN_ERR(svn_wc__db_read_children(&rel_children, wc_ctx->db, dir_abspath,
+                                   scratch_pool, scratch_pool));
+  SVN_ERR(filter_and_make_absolute(children, wc_ctx, dir_abspath,
+                                   rel_children, show_hidden,
+                                   result_pool, scratch_pool));
   return SVN_NO_ERROR;
 }
 

Modified: subversion/trunk/subversion/libsvn_wc/wc-queries.sql
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc-queries.sql?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc-queries.sql (original)
+++ subversion/trunk/subversion/libsvn_wc/wc-queries.sql Mon Mar 14 12:00:20 2011
@@ -154,9 +154,25 @@ SELECT 1 FROM ACTUAL_NODE
 WHERE wc_id = ?1 AND parent_relpath = ?2;
 
 -- STMT_SELECT_NODE_CHILDREN
+/* Return all paths that are children of the directory (?1, ?2) in any
+   op-depth, including children of any underlying, replaced directories. */
 SELECT local_relpath FROM nodes
 WHERE wc_id = ?1 AND parent_relpath = ?2;
 
+-- STMT_SELECT_WORKING_CHILDREN
+/* Return all paths that are children of the working version of the
+   directory (?1, ?2).  A given path is not included just because it is a
+   child of an underlying (replaced) directory, it has to be in the
+   working version of the directory. */
+SELECT local_relpath FROM nodes_current
+WHERE wc_id = ?1 AND parent_relpath = ?2
+  AND (op_depth > (SELECT op_depth FROM nodes_current
+                   WHERE wc_id = ?1 AND local_relpath = ?2)
+       OR
+       (op_depth = (SELECT op_depth FROM nodes_current
+                    WHERE wc_id = ?1 AND local_relpath = ?2)
+        AND presence != 'base-deleted'));
+
 -- STMT_SELECT_BASE_PROPS
 SELECT properties FROM nodes
 WHERE wc_id = ?1 AND local_relpath = ?2 AND op_depth = 0;

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.c?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.c (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.c Mon Mar 14 12:00:20 2011
@@ -1037,6 +1037,31 @@ add_children_to_hash(apr_hash_t *childre
 }
 
 
+/* Set *CHILDREN to a new array of the (const char *) basenames of the
+   immediate children, whatever their status, of the working node at
+   LOCAL_RELPATH. */
+static svn_error_t *
+gather_children2(const apr_array_header_t **children,
+                 svn_wc__db_wcroot_t *wcroot,
+                 const char *local_relpath,
+                 apr_pool_t *result_pool,
+                 apr_pool_t *scratch_pool)
+{
+  apr_hash_t *names_hash = apr_hash_make(scratch_pool);
+  apr_array_header_t *names_array;
+
+  /* All of the names get allocated in RESULT_POOL.  It
+     appears to be faster to use the hash to remove duplicates than to
+     use DISTINCT in the SQL query. */
+  SVN_ERR(add_children_to_hash(names_hash, STMT_SELECT_WORKING_CHILDREN,
+                               wcroot->sdb, wcroot->wc_id,
+                               local_relpath, result_pool));
+
+  SVN_ERR(svn_hash_keys(&names_array, names_hash, result_pool));
+  *children = names_array;
+  return SVN_NO_ERROR;
+}
+
 /* Return in *CHILDREN all of the children of the directory LOCAL_RELPATH,
    of any status, in all op-depths in the NODES table. */
 static svn_error_t *
@@ -1062,9 +1087,10 @@ gather_children(const apr_array_header_t
 }
 
 
-/* Set *CHILDREN to a new array of (const char *) names of the repository
-   children of the directory WCROOT:LOCAL_RELPATH - that is, the children at
-   the same op-depth. */
+/* Set *CHILDREN to a new array of (const char *) names of the children of
+   the repository directory corresponding to the (working) path
+   WCROOT:LOCAL_RELPATH - that is, only the children that are at the same
+   op-depth as their parent. */
 static svn_error_t *
 gather_repo_children(const apr_array_header_t **children,
                      svn_wc__db_wcroot_t *wcroot,
@@ -5596,6 +5622,29 @@ svn_wc__db_read_pristine_props(apr_hash_
 
 
 svn_error_t *
+svn_wc__db_read_children2(const apr_array_header_t **children,
+                         svn_wc__db_t *db,
+                         const char *local_abspath,
+                         apr_pool_t *result_pool,
+                         apr_pool_t *scratch_pool)
+{
+  svn_wc__db_wcroot_t *wcroot;
+  const char *local_relpath;
+
+  SVN_ERR_ASSERT(svn_dirent_is_absolute(local_abspath));
+
+  SVN_ERR(svn_wc__db_wcroot_parse_local_abspath(&wcroot, &local_relpath, db,
+                                             local_abspath,
+                                             svn_sqlite__mode_readonly,
+                                             scratch_pool, scratch_pool));
+  VERIFY_USABLE_WCROOT(wcroot);
+
+  return gather_children2(children, wcroot, local_relpath,
+                          result_pool, scratch_pool);
+}
+
+
+svn_error_t *
 svn_wc__db_read_children(const apr_array_header_t **children,
                          svn_wc__db_t *db,
                          const char *local_abspath,

Modified: subversion/trunk/subversion/libsvn_wc/wc_db.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/wc_db.h?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/wc_db.h (original)
+++ subversion/trunk/subversion/libsvn_wc/wc_db.h Mon Mar 14 12:00:20 2011
@@ -1511,7 +1511,12 @@ struct svn_wc__db_info_t {
 
 /* Return in *NODES a hash mapping name->struct svn_wc__db_info_t for
    the children of DIR_ABSPATH, and in *CONFLICTS a hash of names in
-   conflict.  */
+   conflict.
+
+   The results include any path that was a child of a deleted directory that
+   existed at LOCAL_ABSPATH, even if that directory is now scheduled to be
+   replaced by the working node at LOCAL_ABSPATH.
+ */
 svn_error_t *
 svn_wc__db_read_children_info(apr_hash_t **nodes,
                               apr_hash_t **conflicts,
@@ -1637,8 +1642,13 @@ svn_wc__db_read_pristine_props(apr_hash_
                                apr_pool_t *result_pool,
                                apr_pool_t *scratch_pool);
 
-/* Read into CHILDREN the basenames of the immediate children of
-   LOCAL_ABSPATH in DB.
+/* Set *CHILDREN to a new array of the (const char *) basenames of the
+   immediate children of the working node at LOCAL_ABSPATH in DB.
+
+   Return every path that refers to a child of the working node at
+   LOCAL_ABSPATH.  Do not include a path just because it was a child of a
+   deleted directory that existed at LOCAL_ABSPATH if that directory is now
+   sheduled to be replaced by the working node at LOCAL_ABSPATH.
 
    Allocate *CHILDREN in RESULT_POOL and do temporary allocations in
    SCRATCH_POOL.
@@ -1651,6 +1661,18 @@ svn_wc__db_read_pristine_props(apr_hash_
    ###   computing all info.
 */
 svn_error_t *
+svn_wc__db_read_children2(const apr_array_header_t **children,
+                          svn_wc__db_t *db,
+                          const char *local_abspath,
+                          apr_pool_t *result_pool,
+                          apr_pool_t *scratch_pool);
+
+/* Like svn_wc__db_read_children2(), except also include any path that was
+   a child of a deleted directory that existed at LOCAL_ABSPATH, even if
+   that directory is now scheduled to be replaced by the working node at
+   LOCAL_ABSPATH.
+*/
+svn_error_t *
 svn_wc__db_read_children(const apr_array_header_t **children,
                          svn_wc__db_t *db,
                          const char *local_abspath,

Modified: subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c?rev=1081342&r1=1081341&r2=1081342&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_wc/op-depth-test.c Mon Mar 14 12:00:20 2011
@@ -2559,6 +2559,160 @@ test_op_revert_changelist(const svn_test
   return SVN_NO_ERROR;
 }
 
+/* Check that the (const char *) keys of HASH are exactly the
+ * EXPECTED_NUM strings in EXPECTED_STRINGS.  Return an error if not. */
+static svn_error_t *
+check_hash_keys(apr_hash_t *hash,
+                int expected_num,
+                const char **expected_strings,
+                apr_pool_t *scratch_pool)
+{
+  svn_error_t *err = SVN_NO_ERROR;
+  int i;
+  apr_hash_index_t *hi;
+
+  for (i = 0; i < expected_num; i++)
+    {
+      const char *name = expected_strings[i];
+
+      if (apr_hash_get(hash, name, APR_HASH_KEY_STRING))
+        apr_hash_set(hash, name, APR_HASH_KEY_STRING, NULL);
+      else
+        err = svn_error_compose_create(
+                err, svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+                                       _("Expected, not found: '%s'"), name));
+    }
+  for (hi = apr_hash_first(scratch_pool, hash); hi;
+       hi = apr_hash_next(hi))
+    {
+      const char *name = svn__apr_hash_index_key(hi);
+      err = svn_error_compose_create(
+              err, svn_error_createf(SVN_ERR_TEST_FAILED, NULL,
+                                     _("Found, not expected: '%s'"), name));
+    }
+  return err;
+}
+
+/* Check that the (const char *) keys of APR_HASH are exactly the
+ * strings in (const char *[]) C_ARRAY.  Return an error if not. */
+#define CHECK_HASH(apr_hash, c_array, scratch_pool) \
+  check_hash_keys(apr_hash, sizeof(c_array) / sizeof(c_array[0]), \
+                  c_array, scratch_pool)
+
+/* Check that the basenames of the (const char *) paths in ARRAY are exactly
+ * the EXPECTED_NUM strings in EXPECTED_STRINGS.  Return an error if not. */
+static svn_error_t *
+check_array_strings(const apr_array_header_t *array,
+                    int expected_num,
+                    const char **expected_strings,
+                    apr_pool_t *scratch_pool)
+{
+  int i;
+  apr_hash_t *hash = apr_hash_make(scratch_pool);
+
+  for (i = 0; i < array->nelts; i++)
+    {
+      const char *path = APR_ARRAY_IDX(array, i, const char *);
+
+      apr_hash_set(hash, svn_path_basename(path, scratch_pool),
+                   APR_HASH_KEY_STRING, "");
+    }
+
+  return check_hash_keys(hash, expected_num, expected_strings, scratch_pool);
+}
+
+/* Check that the basenames of the (const char *) paths in APR_ARRAY are
+ * exactly the strings in (const char *[]) C_ARRAY. Return an error if not. */
+#define CHECK_ARRAY(apr_array, c_array, scratch_pool) \
+  check_array_strings(apr_array, sizeof(c_array) / sizeof(c_array[0]), \
+                      c_array, scratch_pool)
+
+
+/* The purpose of this test is to check whether a child of a deleted-and-
+ * replaced directory is reported by various "list the children" APIs. */
+static svn_error_t *
+test_children_of_replaced_dir(const svn_test_opts_t *opts, apr_pool_t *pool)
+{
+  svn_test__sandbox_t b;
+  const apr_array_header_t *children_array;
+  apr_hash_t *children_hash, *conflicts_hash;
+  const char *A_abspath;
+  const char *working_children_exc_hidden[] = { "G", "H", "I", "J", "K", "L" };
+  const char *working_children_inc_hidden[] = { "G", "H", "I", "J", "K", "L" };
+  const char *all_children_inc_hidden[] = { "F", "G", "H", "I", "J", "K", "L" };
+
+  /*
+   * F - base only
+   * G - base, working (from copy of X; schedule-delete)
+   * H - base, working (from copy of X)
+   * I - working only (from copy of X)
+   * J - working only (schedule-add)
+   * K - working only (from copy of X; schedule-delete)
+   * L - base, working (not in copy; schedule-add)
+   */
+
+  SVN_ERR(svn_test__sandbox_create(&b, "children_of_replaced_dir", opts, pool));
+  A_abspath = svn_dirent_join(b.wc_abspath, "A", pool);
+
+  /* Set up the base state as revision 1. */
+  SVN_ERR(wc_mkdir(&b, "A"));
+  SVN_ERR(wc_mkdir(&b, "A/F"));
+  SVN_ERR(wc_mkdir(&b, "A/G"));
+  SVN_ERR(wc_mkdir(&b, "A/H"));
+  SVN_ERR(wc_mkdir(&b, "A/L"));
+  SVN_ERR(wc_mkdir(&b, "X"));
+  SVN_ERR(wc_mkdir(&b, "X/G"));
+  SVN_ERR(wc_mkdir(&b, "X/H"));
+  SVN_ERR(wc_mkdir(&b, "X/I"));
+  SVN_ERR(wc_mkdir(&b, "X/K"));
+  SVN_ERR(wc_commit(&b, ""));
+  SVN_ERR(wc_update(&b, "", 1));
+
+  /* Replace A with a copy of X. */
+  SVN_ERR(wc_delete(&b, "A"));
+  SVN_ERR(wc_copy(&b, "X", "A"));
+
+  /* Make other local mods. */
+  SVN_ERR(wc_delete(&b, "A/G"));
+  SVN_ERR(wc_mkdir(&b, "A/J"));
+  SVN_ERR(wc_mkdir(&b, "A/L"));
+
+  /* Test several variants of "list the children of 'A'". */
+
+  SVN_ERR(svn_wc__db_read_children(&children_array, b.wc_ctx->db, A_abspath,
+                                   pool, pool));
+  SVN_ERR(CHECK_ARRAY(children_array, all_children_inc_hidden, pool));
+
+  SVN_ERR(svn_wc__db_read_children2(&children_array, b.wc_ctx->db, A_abspath,
+                                    pool, pool));
+  SVN_ERR(CHECK_ARRAY(children_array, working_children_inc_hidden, pool));
+
+  SVN_ERR(svn_wc__node_get_children(&children_array, b.wc_ctx, A_abspath,
+                                    TRUE /* show_hidden */, pool, pool));
+  SVN_ERR(CHECK_ARRAY(children_array, all_children_inc_hidden, pool));
+
+  /* I am not testing svn_wc__node_get_children(show_hidden=FALSE) because
+   * I'm not sure what result we should expect if a certain child path is a
+   * child of a deleted-and-replaced dir (so should be included) and is also
+   * a 'hidden' child of the working dir (so should be excluded). */
+
+  SVN_ERR(svn_wc__node_get_children2(&children_array, b.wc_ctx, A_abspath,
+                                     TRUE /* show_hidden */, pool, pool));
+  SVN_ERR(CHECK_ARRAY(children_array, working_children_inc_hidden, pool));
+
+  SVN_ERR(svn_wc__node_get_children2(&children_array, b.wc_ctx, A_abspath,
+                                     FALSE /* show_hidden */, pool, pool));
+  SVN_ERR(CHECK_ARRAY(children_array, working_children_exc_hidden, pool));
+
+  SVN_ERR(svn_wc__db_read_children_info(&children_hash, &conflicts_hash,
+                                        b.wc_ctx->db, A_abspath, pool, pool));
+  SVN_ERR(CHECK_HASH(children_hash, all_children_inc_hidden, pool));
+
+  /* We don't yet have a svn_wc__db_read_children_info2() to test. */
+
+  return SVN_NO_ERROR;
+}
+
 /* ---------------------------------------------------------------------- */
 /* The list of test functions */
 
@@ -2599,5 +2753,7 @@ struct svn_test_descriptor_t test_funcs[
                        "test_op_revert"),
     SVN_TEST_OPTS_PASS(test_op_revert_changelist,
                        "test_op_revert_changelist"),
+    SVN_TEST_OPTS_PASS(test_children_of_replaced_dir,
+                       "test_children_of_replaced_dir"),
     SVN_TEST_NULL
   };