2 * revert.c: wrapper around wc revert functionality.
4 * ====================================================================
5 * Licensed to the Apache Software Foundation (ASF) under one
6 * or more contributor license agreements. See the NOTICE file
7 * distributed with this work for additional information
8 * regarding copyright ownership. The ASF licenses this file
9 * to you under the Apache License, Version 2.0 (the
10 * "License"); you may not use this file except in compliance
11 * with the License. You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing,
16 * software distributed under the License is distributed on an
17 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18 * KIND, either express or implied. See the License for the
19 * specific language governing permissions and limitations
21 * ====================================================================
24 /* ==================================================================== */
32 #include "svn_client.h"
33 #include "svn_dirent_uri.h"
35 #include "svn_pools.h"
36 #include "svn_error.h"
38 #include "svn_config.h"
40 #include "private/svn_wc_private.h"
42 #include "svn_private_config.h"
47 struct revert_with_write_lock_baton {
48 const char *local_abspath;
50 svn_boolean_t use_commit_times;
51 const apr_array_header_t *changelists;
52 svn_boolean_t clear_changelists;
53 svn_boolean_t metadata_only;
54 svn_client_ctx_t *ctx;
57 /* (Note: All arguments are in the baton above.)
59 Attempt to revert LOCAL_ABSPATH.
61 If DEPTH is svn_depth_empty, revert just the properties on the
62 directory; else if svn_depth_files, revert the properties and any
63 files immediately under the directory; else if
64 svn_depth_immediates, revert all of the preceding plus properties
65 on immediate subdirectories; else if svn_depth_infinity, revert
66 path and everything under it fully recursively.
68 CHANGELISTS is an array of const char * changelist names, used as a
69 restrictive filter on items reverted; that is, don't revert any
70 item unless it's a member of one of those changelists. If
71 CHANGELISTS is empty (or altogether NULL), no changelist filtering occurs.
73 Consult CTX to determine whether or not to revert timestamp to the
74 time of last commit ('use-commit-times = yes').
76 If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
78 revert(void *baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
80 struct revert_with_write_lock_baton *b = baton;
83 err = svn_wc_revert5(b->ctx->wc_ctx,
90 b->ctx->cancel_func, b->ctx->cancel_baton,
91 b->ctx->notify_func2, b->ctx->notify_baton2,
96 /* If target isn't versioned, just send a 'skip'
97 notification and move on. */
98 if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
99 || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE
100 || err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
102 if (b->ctx->notify_func2)
104 svn_wc_notify_t *notify;
106 notify = svn_wc_create_notify(b->local_abspath,
112 b->ctx->notify_func2(b->ctx->notify_baton2,
113 notify, scratch_pool);
115 svn_error_clear(err);
118 return svn_error_trace(err);
126 svn_client_revert3(const apr_array_header_t *paths,
128 const apr_array_header_t *changelists,
129 svn_boolean_t clear_changelists,
130 svn_boolean_t metadata_only,
131 svn_client_ctx_t *ctx,
134 apr_pool_t *iterpool;
135 svn_error_t *err = SVN_NO_ERROR;
138 svn_boolean_t use_commit_times;
139 struct revert_with_write_lock_baton baton;
141 /* Don't even attempt to modify the working copy if any of the
142 * targets look like URLs. URLs are invalid input. */
143 for (i = 0; i < paths->nelts; i++)
145 const char *path = APR_ARRAY_IDX(paths, i, const char *);
147 if (svn_path_is_url(path))
148 return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
149 _("'%s' is not a local path"), path);
153 ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG)
156 SVN_ERR(svn_config_get_bool(cfg, &use_commit_times,
157 SVN_CONFIG_SECTION_MISCELLANY,
158 SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
161 iterpool = svn_pool_create(pool);
163 for (i = 0; i < paths->nelts; i++)
165 const char *path = APR_ARRAY_IDX(paths, i, const char *);
166 const char *local_abspath, *lock_target;
167 svn_boolean_t wc_root;
169 svn_pool_clear(iterpool);
171 /* See if we've been asked to cancel this operation. */
172 if ((ctx->cancel_func)
173 && ((err = ctx->cancel_func(ctx->cancel_baton))))
176 err = svn_dirent_get_absolute(&local_abspath, path, iterpool);
180 baton.local_abspath = local_abspath;
182 baton.use_commit_times = use_commit_times;
183 baton.changelists = changelists;
184 baton.clear_changelists = clear_changelists;
185 baton.metadata_only = metadata_only;
188 err = svn_wc__is_wcroot(&wc_root, ctx->wc_ctx, local_abspath, iterpool);
191 lock_target = wc_root ? local_abspath
192 : svn_dirent_dirname(local_abspath, pool);
193 err = svn_wc__call_with_write_lock(revert, &baton, ctx->wc_ctx,
203 /* Sleep to ensure timestamp integrity. */
204 const char *sleep_path = NULL;
206 /* Only specify a path if we are certain all paths are on the
208 if (paths->nelts == 1)
209 sleep_path = APR_ARRAY_IDX(paths, 0, const char *);
211 svn_io_sleep_for_timestamps(sleep_path, iterpool);
214 svn_pool_destroy(iterpool);
216 return svn_error_trace(err);