In the command-line client, forbid
[svn.git] / subversion / libsvn_client / revert.c
blob8e3ca49db183ee391de8f6ff8f288a6fbda71a16
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 Consult CTX to determine whether or not to revert timestamp to the
48 time of last commit ('use-commit-times = yes'). Use POOL for
49 temporary allocation.
51 If PATH is unversioned, return SVN_ERR_UNVERSIONED_RESOURCE. */
52 static svn_error_t *
53 revert(const char *path,
54 svn_depth_t depth,
55 svn_boolean_t use_commit_times,
56 svn_client_ctx_t *ctx,
57 apr_pool_t *pool)
59 svn_wc_adm_access_t *adm_access, *target_access;
60 const char *target;
61 svn_error_t *err;
62 int adm_lock_level = SVN_WC__LEVELS_TO_LOCK_FROM_DEPTH(depth);
64 SVN_ERR(svn_wc_adm_open_anchor(&adm_access, &target_access, &target, path,
65 TRUE, adm_lock_level,
66 ctx->cancel_func, ctx->cancel_baton,
67 pool));
69 err = svn_wc_revert3(path, adm_access, depth, use_commit_times,
70 ctx->cancel_func, ctx->cancel_baton,
71 ctx->notify_func2, ctx->notify_baton2,
72 pool);
74 if (err)
76 /* If target isn't versioned, just send a 'skip'
77 notification and move on. */
78 if (err->apr_err == SVN_ERR_ENTRY_NOT_FOUND
79 || err->apr_err == SVN_ERR_UNVERSIONED_RESOURCE)
81 if (ctx->notify_func2)
82 (*ctx->notify_func2)
83 (ctx->notify_baton2,
84 svn_wc_create_notify(path, svn_wc_notify_skip, pool),
85 pool);
86 svn_error_clear(err);
88 else
89 return err;
92 SVN_ERR(svn_wc_adm_close(adm_access));
94 return SVN_NO_ERROR;
98 svn_error_t *
99 svn_client_revert2(const apr_array_header_t *paths,
100 svn_depth_t depth,
101 svn_client_ctx_t *ctx,
102 apr_pool_t *pool)
104 apr_pool_t *subpool;
105 svn_error_t *err = SVN_NO_ERROR;
106 int i;
107 svn_config_t *cfg;
108 svn_boolean_t use_commit_times;
110 cfg = ctx->config ? apr_hash_get(ctx->config, SVN_CONFIG_CATEGORY_CONFIG,
111 APR_HASH_KEY_STRING) : NULL;
113 SVN_ERR(svn_config_get_bool(cfg, &use_commit_times,
114 SVN_CONFIG_SECTION_MISCELLANY,
115 SVN_CONFIG_OPTION_USE_COMMIT_TIMES,
116 FALSE));
118 subpool = svn_pool_create(pool);
120 for (i = 0; i < paths->nelts; i++)
122 const char *path = APR_ARRAY_IDX(paths, i, const char *);
124 svn_pool_clear(subpool);
126 /* See if we've been asked to cancel this operation. */
127 if ((ctx->cancel_func)
128 && ((err = ctx->cancel_func(ctx->cancel_baton))))
129 goto errorful;
131 err = revert(path, depth, use_commit_times, ctx, subpool);
132 if (err)
133 goto errorful;
136 errorful:
138 svn_pool_destroy(subpool);
140 /* Sleep to ensure timestamp integrity. */
141 svn_sleep_for_timestamps();
143 return err;
147 svn_error_t *
148 svn_client_revert(const apr_array_header_t *paths,
149 svn_boolean_t recursive,
150 svn_client_ctx_t *ctx,
151 apr_pool_t *pool)
153 return svn_client_revert2(paths,
154 recursive ? svn_depth_infinity : svn_depth_empty,
155 ctx, pool);