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 2010/07/14 18:08:07 UTC
svn commit: r964090 - in /subversion/trunk/subversion: libsvn_client/add.c
libsvn_wc/adm_ops.c
Author: rhuijben
Date: Wed Jul 14 16:08:07 2010
New Revision: 964090
URL: http://svn.apache.org/viewvc?rev=964090&view=rev
Log:
Fix the lock handling in svn add --parents and switch some code to
more modern pool and dirent logic there. This to allow adding a write
lock test to svn_wc_add4() without breaking the tests.
* subversion/libsvn_client/add.c
(add_dir_recursive): Retrieve all dirents at once instead of opening the
dir to avoid some errors we noticed in different places. (Race conditions
on some BSD and network filesystems). Simplifying the code.
(add_parent_dirs): Obtain a lock if needed. Add note about how this code should
be improved.
* subversion/libsvn_wc/adm_ops.c
(svn_wc_add4): Add write check.
Modified:
subversion/trunk/subversion/libsvn_client/add.c
subversion/trunk/subversion/libsvn_wc/adm_ops.c
Modified: subversion/trunk/subversion/libsvn_client/add.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/add.c?rev=964090&r1=964089&r2=964090&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/add.c (original)
+++ subversion/trunk/subversion/libsvn_client/add.c Wed Jul 14 16:08:07 2010
@@ -369,78 +369,47 @@ add_dir_recursive(const char *dir_abspat
svn_boolean_t force,
svn_boolean_t no_ignore,
svn_client_ctx_t *ctx,
- apr_pool_t *pool)
+ apr_pool_t *scratch_pool)
{
- apr_dir_t *dir;
- apr_finfo_t this_entry;
svn_error_t *err;
- apr_pool_t *subpool;
- apr_int32_t flags = APR_FINFO_TYPE | APR_FINFO_NAME;
+ apr_pool_t *iterpool;
apr_array_header_t *ignores;
+ apr_hash_t *dirents;
+ apr_hash_index_t *hi;
/* Check cancellation; note that this catches recursive calls too. */
if (ctx->cancel_func)
SVN_ERR(ctx->cancel_func(ctx->cancel_baton));
+ iterpool = svn_pool_create(scratch_pool);
+
/* Add this directory to revision control. */
err = svn_wc_add4(ctx->wc_ctx, dir_abspath, svn_depth_infinity, NULL,
SVN_INVALID_REVNUM, ctx->cancel_func, ctx->cancel_baton,
- ctx->notify_func2, ctx->notify_baton2, pool);
+ ctx->notify_func2, ctx->notify_baton2, iterpool);
if (err && err->apr_err == SVN_ERR_ENTRY_EXISTS && force)
svn_error_clear(err);
else if (err)
return svn_error_return(err);
- subpool = svn_pool_create(pool);
-
if (!no_ignore)
{
SVN_ERR(svn_wc_get_ignores2(&ignores, ctx->wc_ctx, dir_abspath,
- ctx->config, pool, subpool));
+ ctx->config, scratch_pool, iterpool));
}
- SVN_ERR(svn_io_dir_open(&dir, dir_abspath, pool));
+ SVN_ERR(svn_io_get_dirents3(&dirents, dir_abspath, TRUE, scratch_pool,
+ iterpool));
/* Read the directory entries one by one and add those things to
version control. */
- while (1)
+ for (hi = apr_hash_first(scratch_pool, dirents); hi; hi = apr_hash_next(hi))
{
+ const char *name = svn__apr_hash_index_key(hi);
+ svn_io_dirent2_t *dirent = svn__apr_hash_index_val(hi);
const char *abspath;
- svn_pool_clear(subpool);
-
- err = svn_io_dir_read(&this_entry, flags, dir, subpool);
-
- if (err)
- {
- /* Check if we're done reading the dir's entries. */
- if (APR_STATUS_IS_ENOENT(err->apr_err))
- {
- apr_status_t apr_err;
-
- svn_error_clear(err);
- apr_err = apr_dir_close(dir);
- if (apr_err)
- return svn_error_wrap_apr(apr_err,
- _("Can't close directory '%s'"),
- svn_dirent_local_style(dir_abspath,
- subpool));
- break;
- }
- else
- {
- return svn_error_createf(err->apr_err, err,
- _("Error during add of '%s'"),
- svn_dirent_local_style(dir_abspath,
- subpool));
- }
- }
-
- /* Skip entries for this dir and its parent. */
- if (this_entry.name[0] == '.'
- && (this_entry.name[1] == '\0'
- || (this_entry.name[1] == '.' && this_entry.name[2] == '\0')))
- continue;
+ svn_pool_clear(iterpool);
/* Check cancellation so you can cancel during an
* add of a directory with lots of files. */
@@ -448,40 +417,38 @@ add_dir_recursive(const char *dir_abspat
SVN_ERR(ctx->cancel_func(ctx->cancel_baton));
/* Skip over SVN admin directories. */
- if (svn_wc_is_adm_dir(this_entry.name, subpool))
+ if (svn_wc_is_adm_dir(name, iterpool))
continue;
- if ((!no_ignore) && svn_wc_match_ignore_list(this_entry.name,
- ignores, subpool))
+ if ((!no_ignore) && svn_wc_match_ignore_list(name, ignores, iterpool))
continue;
/* Construct the full path of the entry. */
- abspath = svn_dirent_join(dir_abspath, this_entry.name, subpool);
+ abspath = svn_dirent_join(dir_abspath, name, iterpool);
/* Recurse on directories; add files; ignore the rest. */
- if (this_entry.filetype == APR_DIR && depth >= svn_depth_immediates)
+ if (dirent->kind == svn_node_dir && depth >= svn_depth_immediates)
{
svn_depth_t depth_below_here = depth;
if (depth == svn_depth_immediates)
depth_below_here = svn_depth_empty;
SVN_ERR(add_dir_recursive(abspath, depth_below_here,
- force, no_ignore, ctx, subpool));
+ force, no_ignore, ctx, iterpool));
}
- else if (this_entry.filetype != APR_UNKFILE
- && this_entry.filetype != APR_DIR
+ else if ((dirent->kind == svn_node_file || dirent->special)
&& depth >= svn_depth_files)
{
- err = add_file(abspath, ctx, subpool);
+ err = add_file(abspath, ctx, iterpool);
if (err && err->apr_err == SVN_ERR_ENTRY_EXISTS && force)
svn_error_clear(err);
- else if (err)
- return svn_error_return(err);
+ else
+ SVN_ERR(err);
}
}
/* Destroy the per-iteration pool. */
- svn_pool_destroy(subpool);
+ svn_pool_destroy(iterpool);
return SVN_NO_ERROR;
}
@@ -539,6 +506,9 @@ add(void *baton, apr_pool_t *result_pool
/* Go up the directory tree, looking for a versioned directory. If found,
add all the intermediate directories. Otherwise, return
SVN_ERR_CLIENT_NO_VERSIONED_PARENT. */
+/* ### This function needs rewriting into its callers in a style that finds the
+ parent and then acquires an infinite depth lock there for the entire
+ operation */
static svn_error_t *
add_parent_dirs(svn_client_ctx_t *ctx,
const char *local_abspath,
@@ -546,8 +516,10 @@ add_parent_dirs(svn_client_ctx_t *ctx,
{
int format;
const char *parent_abspath;
+ svn_boolean_t own_lock;
+ svn_wc_context_t *wc_ctx = ctx->wc_ctx;
- SVN_ERR(svn_wc_check_wc2(&format, ctx->wc_ctx, local_abspath, scratch_pool));
+ SVN_ERR(svn_wc_check_wc2(&format, wc_ctx, local_abspath, scratch_pool));
if (format > 0)
return SVN_NO_ERROR;
@@ -565,7 +537,15 @@ add_parent_dirs(svn_client_ctx_t *ctx,
parent_abspath = svn_dirent_dirname(local_abspath, scratch_pool);
SVN_ERR(add_parent_dirs(ctx, parent_abspath, scratch_pool));
- SVN_ERR(svn_wc_add4(ctx->wc_ctx, local_abspath, svn_depth_infinity,
+
+ SVN_ERR(svn_wc_locked2(&own_lock, NULL, wc_ctx, parent_abspath,
+ scratch_pool));
+
+ if (!own_lock)
+ SVN_ERR(svn_wc__acquire_write_lock(NULL, wc_ctx, parent_abspath,
+ scratch_pool, scratch_pool));
+
+ SVN_ERR(svn_wc_add4(wc_ctx, local_abspath, svn_depth_infinity,
NULL, SVN_INVALID_REVNUM,
ctx->cancel_func, ctx->cancel_baton,
ctx->notify_func2, ctx->notify_baton2,
@@ -573,7 +553,7 @@ add_parent_dirs(svn_client_ctx_t *ctx,
/* ### New dir gets added with its own per-directory lock which we
must release. This code should be redundant when we move to a
single db. */
- SVN_ERR(svn_wc__release_write_lock(ctx->wc_ctx, local_abspath, scratch_pool));
+ SVN_ERR(svn_wc__release_write_lock(wc_ctx, parent_abspath, scratch_pool));
return SVN_NO_ERROR;
}
Modified: subversion/trunk/subversion/libsvn_wc/adm_ops.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_ops.c?rev=964090&r1=964089&r2=964090&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_ops.c (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_ops.c Wed Jul 14 16:08:07 2010
@@ -1025,6 +1025,8 @@ svn_wc_add4(svn_wc_context_t *wc_ctx,
svn_dirent_local_style(local_abspath, scratch_pool));
#endif
+ SVN_ERR(svn_wc__write_check(db, parent_abspath, scratch_pool));
+
{
svn_wc__db_status_t parent_status;
svn_wc__db_kind_t parent_kind;