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 2019/01/30 16:29:38 UTC

svn commit: r1852536 - in /subversion/trunk/subversion: include/svn_delta.h libsvn_delta/deprecated.c libsvn_delta/path_driver.c

Author: julianfoad
Date: Wed Jan 30 16:29:37 2019
New Revision: 1852536

URL: http://svn.apache.org/viewvc?rev=1852536&view=rev
Log:
In the updated delta editor path driver, ensure paths are relpaths.

* subversion/include/svn_delta.h
  (svn_delta_path_driver_cb_func2_t,
   svn_delta_path_driver3,
   svn_delta_path_driver_step): Declare that paths are relpaths.
  (svn_delta_path_driver2): Document that a slash prefix is allowed.

* subversion/libsvn_delta/deprecated.c
  (path_driver_2_to_3_baton_t,
   path_driver_2_to_3_func,
   svn_delta_path_driver2): Implement backward compatibility for a slash
    prefix.

* subversion/libsvn_delta/path_driver.c
  (svn_delta_path_driver3): Rename variables to 'relpath', for clarity.
  (svn_delta_path_driver_step): Assert the path is a relpath, remove support
    for a slash prefix, and rename variables.

Modified:
    subversion/trunk/subversion/include/svn_delta.h
    subversion/trunk/subversion/libsvn_delta/deprecated.c
    subversion/trunk/subversion/libsvn_delta/path_driver.c

Modified: subversion/trunk/subversion/include/svn_delta.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_delta.h?rev=1852536&r1=1852535&r2=1852536&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_delta.h (original)
+++ subversion/trunk/subversion/include/svn_delta.h Wed Jan 30 16:29:37 2019
@@ -1290,19 +1290,19 @@ svn_delta_depth_filter_editor(const svn_
  *
  * The handler of this callback is given the callback baton @a
  * callback_baton, @a editor and @a edit_baton which represent the
- * editor being driven, @a path which is a relpath relative to the
+ * editor being driven, @a relpath which is a relpath relative to the
  * root of the edit, and the @a parent_baton which represents
- * path's parent directory as created by the editor.
+ * @a relpath's parent directory as created by the editor.
  *
- * If the handler deletes the node at @a path (and does not replace it
+ * If the handler deletes the node at @a relpath (and does not replace it
  * with an added directory) it must set @a *dir_baton to null or leave
  * it unchanged.
  *
- * If the handler opens (or adds) a directory at @a path, it must set
- * @a *dir_baton to the directory baton for @a path, generated from
+ * If the handler opens (or adds) a directory at @a relpath, it must set
+ * @a *dir_baton to the directory baton for @a relpath, generated from
  * the same editor. The driver will close the directory later.
  *
- * If the handler opens (or adds) a file at @a path, the handler must
+ * If the handler opens (or adds) a file at @a relpath, the handler must
  * set @a *dir_baton to null or leave it unchanged.  The handler must
  * either close the file immediately, or delay that close until the end
  * of the edit when svn_delta_path_driver() returns.
@@ -1320,12 +1320,14 @@ typedef svn_error_t *(*svn_delta_path_dr
   void *edit_baton,
   void *parent_baton,
   void *callback_baton,
-  const char *path,
+  const char *relpath,
   apr_pool_t *pool);
 
-/* Like #svn_delta_path_driver_cb_func2_t but without the @a editor and
+/** Like #svn_delta_path_driver_cb_func2_t but without the @a editor and
  * @a edit_baton parameters. The user must arrange for the editor to be
  * passed through @a callback_baton (if required, which it usually is).
+ * And @a path could possibly have a '/' prefix instead of being a relpath;
+ * see the note on svn_delta_path_driver2().
  *
  * @deprecated Provided for backward compatibility with the 1.11 API.
  */
@@ -1337,15 +1339,15 @@ typedef svn_error_t *(*svn_delta_path_dr
   apr_pool_t *pool);
 
 
-/** Drive @a editor (with its @a edit_baton) to visit each path in @a paths.
+/** Drive @a editor (with its @a edit_baton) to visit each path in @a relpaths.
  *
  * As each path is hit as part of the editor drive, use
  * @a callback_func and @a callback_baton to allow the caller to handle
  * the portion of the editor drive related to that path.
  *
- * Each path in @a paths is a (const char *) relpath, relative
+ * Each path in @a relpaths is a (const char *) relpath, relative
  * to the root path of the edit. The editor drive will be
- * performed in the same order as @a paths. The paths should be sorted
+ * performed in the same order as @a relpaths. The paths should be sorted
  * using something like svn_sort_compare_paths() to ensure that each
  * directory in the depth-first walk is visited only once. If @a sort_paths
  * is set, the function will sort the paths for you. Some callers may need
@@ -1363,15 +1365,19 @@ typedef svn_error_t *(*svn_delta_path_dr
 svn_error_t *
 svn_delta_path_driver3(const svn_delta_editor_t *editor,
                        void *edit_baton,
-                       const apr_array_header_t *paths,
+                       const apr_array_header_t *relpaths,
                        svn_boolean_t sort_paths,
                        svn_delta_path_driver_cb_func2_t callback_func,
                        void *callback_baton,
                        apr_pool_t *pool);
 
-/* Like svn_delta_path_driver3() but with a different callback function
+/** Like svn_delta_path_driver3() but with a different callback function
  * signature.
  *
+ * Optionally, all the paths in @a paths could have a '/' prefix instead of
+ * being relpaths. In that case, all paths sent to the callback will have
+ * a '/' prefix.
+ *
  * @deprecated Provided for backward compatibility with the 1.11 API.
  * @since New in 1.8.
  */
@@ -1433,11 +1439,11 @@ svn_delta_path_driver_start(svn_delta_pa
                             void *callback_baton,
                             apr_pool_t *result_pool);
 
-/** Visit @a path.
+/** Visit @a relpath.
  *
  * @a state is the object returned by svn_delta_path_driver_start().
  *
- * @a path is a relpath relative to the root path of the edit.
+ * @a relpath is a relpath relative to the root path of the edit.
  *
  * This function uses the editor and the callback that were originally
  * supplied to svn_delta_path_driver_start().
@@ -1462,7 +1468,7 @@ svn_delta_path_driver_start(svn_delta_pa
  */
 svn_error_t *
 svn_delta_path_driver_step(svn_delta_path_driver_state_t *state,
-                           const char *path,
+                           const char *relpath,
                            apr_pool_t *scratch_pool);
 
 /** Finish driving the editor.

Modified: subversion/trunk/subversion/libsvn_delta/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_delta/deprecated.c?rev=1852536&r1=1852535&r2=1852536&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_delta/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_delta/deprecated.c Wed Jan 30 16:29:37 2019
@@ -34,6 +34,7 @@ struct path_driver_2_to_3_baton_t
 {
   svn_delta_path_driver_cb_func_t callback_func;
   void *callback_baton;
+  svn_boolean_t slash_prefix;
 };
 
 /* Convert from a newer to older callback
@@ -49,6 +50,9 @@ path_driver_2_to_3_func(void **dir_baton
 {
   struct path_driver_2_to_3_baton_t *b = callback_baton;
 
+  if (b->slash_prefix)
+    path = apr_pstrcat(pool, "/", path, SVN_VA_NULL);
+
   /* Just drop the 'editor' parameters */
   SVN_ERR(b->callback_func(dir_baton, parent_baton,
                            b->callback_baton,
@@ -69,6 +73,29 @@ svn_delta_path_driver2(const svn_delta_e
 
   b.callback_func = callback_func;
   b.callback_baton = callback_baton;
+
+  /* Remove any '/' prefix from incoming paths and arrange to add it back
+     when calling the callback. We assume the first path is representative
+     of all paths. */
+  if (paths->nelts >= 1
+      && APR_ARRAY_IDX(paths, 0, const char *)[0] == '/')
+    {
+      int i;
+
+      for (i = 0; i < paths->nelts; i++)
+        {
+          const char *path = APR_ARRAY_IDX(paths, i, const char *);
+
+          if (path[0] == '/')
+            APR_ARRAY_IDX(paths, i, const char *) = path + 1;
+        }
+      b.slash_prefix = TRUE;
+    }
+  else
+    {
+      b.slash_prefix = FALSE;
+    }
+
   SVN_ERR(svn_delta_path_driver3(editor, edit_baton,
                                  paths, sort_paths,
                                  path_driver_2_to_3_func, &b,

Modified: subversion/trunk/subversion/libsvn_delta/path_driver.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_delta/path_driver.c?rev=1852536&r1=1852535&r2=1852536&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_delta/path_driver.c (original)
+++ subversion/trunk/subversion/libsvn_delta/path_driver.c Wed Jan 30 16:29:37 2019
@@ -31,7 +31,6 @@
 #include "svn_dirent_uri.h"
 #include "svn_path.h"
 #include "svn_sorts.h"
-#include "private/svn_fspath.h"
 #include "private/svn_sorts_private.h"
 
 
@@ -146,30 +145,29 @@ count_components(const char *path)
 svn_error_t *
 svn_delta_path_driver3(const svn_delta_editor_t *editor,
                        void *edit_baton,
-                       const apr_array_header_t *paths,
+                       const apr_array_header_t *relpaths,
                        svn_boolean_t sort_paths,
                        svn_delta_path_driver_cb_func2_t callback_func,
                        void *callback_baton,
                        apr_pool_t *pool)
 {
   svn_delta_path_driver_state_t *state;
-  int i = 0;
-  const char *path;
+  int i;
   apr_pool_t *subpool, *iterpool;
 
   /* Do nothing if there are no paths. */
-  if (! paths->nelts)
+  if (! relpaths->nelts)
     return SVN_NO_ERROR;
 
   subpool = svn_pool_create(pool);
   iterpool = svn_pool_create(pool);
 
   /* sort paths if necessary */
-  if (sort_paths && paths->nelts > 1)
+  if (sort_paths && relpaths->nelts > 1)
     {
-      apr_array_header_t *sorted = apr_array_copy(subpool, paths);
+      apr_array_header_t *sorted = apr_array_copy(subpool, relpaths);
       svn_sort__array(sorted, svn_sort_compare_paths);
-      paths = sorted;
+      relpaths = sorted;
     }
 
   SVN_ERR(svn_delta_path_driver_start(&state,
@@ -179,15 +177,17 @@ svn_delta_path_driver3(const svn_delta_e
 
   /* Now, loop over the commit items, traversing the URL tree and
      driving the editor. */
-  for (; i < paths->nelts; i++)
+  for (i = 0; i < relpaths->nelts; i++)
     {
+      const char *relpath;
+
       /* Clear the iteration pool. */
       svn_pool_clear(iterpool);
 
       /* Get the next path. */
-      path = APR_ARRAY_IDX(paths, i, const char *);
+      relpath = APR_ARRAY_IDX(relpaths, i, const char *);
 
-      SVN_ERR(svn_delta_path_driver_step(state, path, iterpool));
+      SVN_ERR(svn_delta_path_driver_step(state, relpath, iterpool));
     }
 
   /* Destroy the iteration subpool. */
@@ -233,7 +233,7 @@ svn_delta_path_driver_start(svn_delta_pa
 
 svn_error_t *
 svn_delta_path_driver_step(svn_delta_path_driver_state_t *state,
-                           const char *path,
+                           const char *relpath,
                            apr_pool_t *scratch_pool)
 {
   const char *pdir;
@@ -243,10 +243,12 @@ svn_delta_path_driver_step(svn_delta_pat
   dir_stack_t *item;
   void *parent_db, *db;
 
+  SVN_ERR_ASSERT(svn_relpath_is_canonical(relpath));
+
   /* If the first target path is not the root of the edit, we must first
      call open_root() ourselves. (If the first target path is the root of
      the edit, then we expect the user's callback to do so.) */
-  if (!state->last_path && !svn_path_is_empty(path))
+  if (!state->last_path && !svn_path_is_empty(relpath))
     {
       subpool = svn_pool_create(state->pool);
       SVN_ERR(state->editor->open_root(state->edit_baton, SVN_INVALID_REVNUM,
@@ -258,9 +260,8 @@ svn_delta_path_driver_step(svn_delta_pat
        current one.  For the first iteration, this is just the
        empty string. ***/
   if (state->last_path)
-    common = (state->last_path[0] == '/')
-    ? svn_fspath__get_longest_ancestor(state->last_path, path, scratch_pool)
-    : svn_relpath_get_longest_ancestor(state->last_path, path, scratch_pool);
+    common = svn_relpath_get_longest_ancestor(state->last_path, relpath,
+                                              scratch_pool);
   common_len = strlen(common);
 
   /*** Step B - Close any directories between the last path and
@@ -280,10 +281,7 @@ svn_delta_path_driver_step(svn_delta_pat
 
   /*** Step C - Open any directories between the common ancestor
        and the parent of the current path. ***/
-  if (*path == '/')
-    pdir = svn_fspath__dirname(path, scratch_pool);
-  else
-    pdir = svn_relpath_dirname(path, scratch_pool);
+  pdir = svn_relpath_dirname(relpath, scratch_pool);
 
   if (strlen(pdir) > common_len)
     {
@@ -327,7 +325,7 @@ svn_delta_path_driver_step(svn_delta_pat
   SVN_ERR(state->callback_func(&db,
                                state->editor, state->edit_baton, parent_db,
                                state->callback_baton,
-                               path, subpool));
+                               relpath, subpool));
   if (db)
     {
       push_dir_stack_item(state->db_stack, db, subpool);
@@ -341,7 +339,7 @@ svn_delta_path_driver_step(svn_delta_pat
        caller opened or added PATH as a directory, that becomes
        our LAST_PATH.  Otherwise, we use PATH's parent
        directory. ***/
-  state->last_path = apr_pstrdup(state->pool, db ? path : pdir);
+  state->last_path = apr_pstrdup(state->pool, db ? relpath : pdir);
 
   return SVN_NO_ERROR;
 }