Change the format of the revprops block sent in svnserve for
[svn.git] / subversion / libsvn_client / revert.c
blob944a1aef1bd43ecfa96deec17d380599de198582
1 /*
2 * revert.c: wrapper around wc revert functionality.
4 * ====================================================================
5 * Copyright (c) 2000-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 /* ==================================================================== */
23 /*** Includes. ***/
25 #include "svn_wc.h"
26 #include "svn_client.h"
27 #include "svn_pools.h"
28 #include "svn_error.h"
29 #include "svn_time.h"
30 #include "svn_config.h"
31 #include "client.h"
32 #include "private/svn_wc_private.h"
36 /*** Code. ***/
38 /* Attempt to revert PATH.
40 If DEPTH is svn_depth_empty, revert just the properties on the
41 directory; else if svn_depth_files, revert the properties and any
42 files immediately under the directory; else if
43 svn_depth_immediates, revert all of the preceding plus properties
44 on immediate subdirectories; else if svn_depth_infinity, revert
45 path and everything under it fully recursively.
47 CHANGELISTS is an array of const char * changelist names, used as a
48 restrictive filter on items reverted; that is, don't revert any
49 item unless it's a member of one of those changelists. If
50 CHANGELISTS is empty (or altogether NULL), no changelist filtering occurs.
52 Consult CTX to determine whether or not to revert timestamp to the
53 time of last commit ('use-commit-times = yes'). Use POOL for
54 temporary allocation.
56 If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
57 static svn_error_t *
58 revert(const char *path,
59 svn_depth_t depth,
60 svn_boolean_t use_commit_times,
61 const apr_array_header_t *changelists,
62 svn_client_ctx_t *ctx,
63 apr_pool_t *pool)
65 svn_wc_adm_access_t *adm_access, *target_access;
66 const char *target;
67 svn_error_t *err;
68 int adm_lock_level = SVN_WC__LEVELS_TO_LOCK_FROM_DEPTH(depth);
70 SVN_ERR(svn_wc_adm_open_anchor(&adm_access, &target_access, &target, path,
71 TRUE, adm_lock_level,
72 ctx->cancel_func, ctx->cancel_baton,
73 pool));
75 err = svn_wc_revert3(path, adm_access, depth, use_commit_times, changelists,
76 ctx->cancel_func, ctx->cancel_baton,
77 ctx->notify_func2, ctx->notify_baton2,
78 pool);
80 if (err)
82 /* If target isn't versioned, just send a 'skip'
83 notification and move on. */
84 if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
85 || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE)
87 if (ctx->notify_func2)
88 (*ctx->notify_func2)
89 (ctx->notify_baton2,
90 svn_wc_create_notify(path, svn_wc_notify_skip, pool),
91 pool);
92 svn_error_clear(err);
94 else
95 return err;
98 SVN_ERR(svn_wc_adm_close(adm_access));
100 return SVN_NO_ERROR;
104 svn_error_t *
105 svn_client_revert2(const apr_array_header_t *paths,
106 svn_depth_t depth,
107 const apr_array_header_t *changelists,
108 svn_client_ctx_t *ctx,
109 apr_pool_t *pool)
111 apr_pool_t *subpool;
112 svn_error_t *err = SVN_NO_ERROR;
113 int i;
114 svn_config_t *cfg;
115 svn_boolean_t use_commit_times;
117 cfg = ctx->config ? apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG,
118 APR_HASH_KEY_STRING) : NULL;
120 SVN_ERR(svn_config_get_bool(cfg, &use_commit_times,
121 SVN_CONFIG_SECTION_MISCELLANY,
122 SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
123 FALSE));
125 subpool = svn_pool_create(pool);
127 for (i = 0; i < paths->nelts; i++)
129 const char *path = APR_ARRAY_IDX(paths, i, const char *);
131 svn_pool_clear(subpool);
133 /* See if we've been asked to cancel this operation. */
134 if ((ctx->cancel_func)
135 && ((err = ctx->cancel_func(ctx->cancel_baton))))
136 goto errorful;
138 err = revert(path, depth, use_commit_times, changelists, ctx, subpool);
139 if (err)
140 goto errorful;
143 errorful:
145 svn_pool_destroy(subpool);
147 /* Sleep to ensure timestamp integrity. */
148 svn_sleep_for_timestamps();
150 return err;
154 svn_error_t *
155 svn_client_revert(const apr_array_header_t *paths,
156 svn_boolean_t recursive,
157 svn_client_ctx_t *ctx,
158 apr_pool_t *pool)
160 return svn_client_revert2(paths,
161 recursive ? svn_depth_infinity : svn_depth_empty,
162 NULL, ctx, pool);