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 /* ==================================================================== */
26 #include "svn_client.h"
27 #include "svn_pools.h"
28 #include "svn_error.h"
30 #include "svn_config.h"
32 #include "private/svn_wc_private.h"
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
56 If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
58 revert(const char *path
,
60 svn_boolean_t use_commit_times
,
61 const apr_array_header_t
*changelists
,
62 svn_client_ctx_t
*ctx
,
65 svn_wc_adm_access_t
*adm_access
, *target_access
;
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
,
72 ctx
->cancel_func
, ctx
->cancel_baton
,
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
,
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
)
90 svn_wc_create_notify(path
, svn_wc_notify_skip
, pool
),
98 SVN_ERR(svn_wc_adm_close(adm_access
));
105 svn_client_revert2(const apr_array_header_t
*paths
,
107 const apr_array_header_t
*changelists
,
108 svn_client_ctx_t
*ctx
,
112 svn_error_t
*err
= SVN_NO_ERROR
;
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
,
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
))))
138 err
= revert(path
, depth
, use_commit_times
, changelists
, ctx
, subpool
);
145 svn_pool_destroy(subpool
);
147 /* Sleep to ensure timestamp integrity. */
148 svn_sleep_for_timestamps();
155 svn_client_revert(const apr_array_header_t
*paths
,
156 svn_boolean_t recursive
,
157 svn_client_ctx_t
*ctx
,
160 return svn_client_revert2(paths
,
161 recursive
? svn_depth_infinity
: svn_depth_empty
,