]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/libsvn_client/revert.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / libsvn_client / revert.c
1 /*
2  * revert.c:  wrapper around wc revert functionality.
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 /* ==================================================================== */
25
26
27 \f
28 /*** Includes. ***/
29
30 #include "svn_path.h"
31 #include "svn_wc.h"
32 #include "svn_client.h"
33 #include "svn_dirent_uri.h"
34 #include "svn_hash.h"
35 #include "svn_pools.h"
36 #include "svn_error.h"
37 #include "svn_time.h"
38 #include "svn_config.h"
39 #include "client.h"
40 #include "private/svn_wc_private.h"
41
42 #include "svn_private_config.h"
43
44 \f
45 /*** Code. ***/
46
47 struct revert_with_write_lock_baton {
48   const char *local_abspath;
49   svn_depth_t depth;
50   svn_boolean_t use_commit_times;
51   const apr_array_header_t *changelists;
52   svn_client_ctx_t *ctx;
53 };
54
55 /* (Note: All arguments are in the baton above.)
56
57    Attempt to revert LOCAL_ABSPATH.
58
59    If DEPTH is svn_depth_empty, revert just the properties on the
60    directory; else if svn_depth_files, revert the properties and any
61    files immediately under the directory; else if
62    svn_depth_immediates, revert all of the preceding plus properties
63    on immediate subdirectories; else if svn_depth_infinity, revert
64    path and everything under it fully recursively.
65
66    CHANGELISTS is an array of const char * changelist names, used as a
67    restrictive filter on items reverted; that is, don't revert any
68    item unless it's a member of one of those changelists.  If
69    CHANGELISTS is empty (or altogether NULL), no changelist filtering occurs.
70
71    Consult CTX to determine whether or not to revert timestamp to the
72    time of last commit ('use-commit-times = yes').
73
74    If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
75 static svn_error_t *
76 revert(void *baton, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
77 {
78   struct revert_with_write_lock_baton *b = baton;
79   svn_error_t *err;
80
81   err = svn_wc_revert4(b->ctx->wc_ctx,
82                        b->local_abspath,
83                        b->depth,
84                        b->use_commit_times,
85                        b->changelists,
86                        b->ctx->cancel_func, b->ctx->cancel_baton,
87                        b->ctx->notify_func2, b->ctx->notify_baton2,
88                        scratch_pool);
89
90   if (err)
91     {
92       /* If target isn't versioned, just send a 'skip'
93          notification and move on. */
94       if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
95           || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE
96           || err->apr_err == SVN_ERR_WC_PATH_NOT_FOUND)
97         {
98           if (b->ctx->notify_func2)
99             (*b->ctx->notify_func2)(
100                b->ctx->notify_baton2,
101                svn_wc_create_notify(b->local_abspath, svn_wc_notify_skip,
102                                     scratch_pool),
103                scratch_pool);
104           svn_error_clear(err);
105         }
106       else
107         return svn_error_trace(err);
108     }
109
110   return SVN_NO_ERROR;
111 }
112
113
114 svn_error_t *
115 svn_client_revert2(const apr_array_header_t *paths,
116                    svn_depth_t depth,
117                    const apr_array_header_t *changelists,
118                    svn_client_ctx_t *ctx,
119                    apr_pool_t *pool)
120 {
121   apr_pool_t *subpool;
122   svn_error_t *err = SVN_NO_ERROR;
123   int i;
124   svn_config_t *cfg;
125   svn_boolean_t use_commit_times;
126   struct revert_with_write_lock_baton baton;
127
128   /* Don't even attempt to modify the working copy if any of the
129    * targets look like URLs. URLs are invalid input. */
130   for (i = 0; i < paths->nelts; i++)
131     {
132       const char *path = APR_ARRAY_IDX(paths, i, const char *);
133
134       if (svn_path_is_url(path))
135         return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
136                                  _("'%s' is not a local path"), path);
137     }
138
139   cfg = ctx->config
140         ? svn_hash_gets(ctx->config, SVN_CONFIG_CATEGORY_CONFIG)
141         : NULL;
142
143   SVN_ERR(svn_config_get_bool(cfg, &use_commit_times,
144                               SVN_CONFIG_SECTION_MISCELLANY,
145                               SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
146                               FALSE));
147
148   subpool = svn_pool_create(pool);
149
150   for (i = 0; i < paths->nelts; i++)
151     {
152       const char *path = APR_ARRAY_IDX(paths, i, const char *);
153       const char *local_abspath, *lock_target;
154       svn_boolean_t wc_root;
155
156       svn_pool_clear(subpool);
157
158       /* See if we've been asked to cancel this operation. */
159       if ((ctx->cancel_func)
160           && ((err = ctx->cancel_func(ctx->cancel_baton))))
161         goto errorful;
162
163       err = svn_dirent_get_absolute(&local_abspath, path, pool);
164       if (err)
165         goto errorful;
166
167       baton.local_abspath = local_abspath;
168       baton.depth = depth;
169       baton.use_commit_times = use_commit_times;
170       baton.changelists = changelists;
171       baton.ctx = ctx;
172
173       err = svn_wc__is_wcroot(&wc_root, ctx->wc_ctx, local_abspath, pool);
174       if (err)
175         goto errorful;
176       lock_target = wc_root ? local_abspath
177                             : svn_dirent_dirname(local_abspath, pool);
178       err = svn_wc__call_with_write_lock(revert, &baton, ctx->wc_ctx,
179                                          lock_target, FALSE, pool, pool);
180       if (err)
181         goto errorful;
182     }
183
184  errorful:
185
186   {
187     /* Sleep to ensure timestamp integrity. */
188     const char *sleep_path = NULL;
189
190     /* Only specify a path if we are certain all paths are on the
191        same filesystem */
192     if (paths->nelts == 1)
193       sleep_path = APR_ARRAY_IDX(paths, 0, const char *);
194
195     svn_io_sleep_for_timestamps(sleep_path, subpool);
196   }
197
198   svn_pool_destroy(subpool);
199
200   return svn_error_trace(err);
201 }