In the command-line client, forbid
[svn.git] / subversion / libsvn_client / changelist.c
blob7bc4ced428617d64b94a30e35406dbec676347c8
1 /*
2 * changelist.c: implementation of the 'changelist' command
4 * ====================================================================
5 * Copyright (c) 2006-2007 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_client.h"
26 #include "svn_wc.h"
27 #include "svn_pools.h"
29 #include "client.h"
32 /*** Code. ***/
34 svn_error_t *
35 svn_client_add_to_changelist(const apr_array_header_t *paths,
36 const char *changelist_name,
37 svn_client_ctx_t *ctx,
38 apr_pool_t *pool)
40 /* Someday this routine might be use a different underlying API to
41 to make the associations in a centralized database. */
43 return svn_wc_set_changelist(paths, changelist_name, NULL,
44 ctx->cancel_func, ctx->cancel_baton,
45 ctx->notify_func2, ctx->notify_baton2, pool);
49 svn_error_t *
50 svn_client_remove_from_changelist(const apr_array_header_t *paths,
51 const char *changelist_name,
52 svn_client_ctx_t *ctx,
53 apr_pool_t *pool)
55 /* Someday this routine might be use a different underlying API to
56 remove the associations from a centralized database.
58 To that end, we should keep our semantics consistent. If
59 CHANGELIST_NAME is defined, then it's not enough to just "blank
60 out" any changelist name attached to each path's entry_t; we need
61 to verify that each incoming path is already a member of the
62 named changelist first... if not, then skip over it or show a
63 warning. This is what a centralized database would do.
65 If CHANGELIST_NAME is undefined, then we can be more lax and
66 remove the path from whatever changelist it's already a part of.
69 return svn_wc_set_changelist(paths, NULL, changelist_name,
70 ctx->cancel_func, ctx->cancel_baton,
71 ctx->notify_func2, ctx->notify_baton2, pool);
75 /* Entry-walker callback for svn_client_get_changelist*() below. */
77 struct fe_baton
79 svn_boolean_t store_paths;
80 svn_changelist_receiver_t callback_func;
81 void *callback_baton;
82 apr_array_header_t *path_list;
83 const char *changelist_name;
84 apr_pool_t *pool;
88 static svn_error_t *
89 found_an_entry(const char *path,
90 const svn_wc_entry_t *entry,
91 void *baton,
92 apr_pool_t *pool)
94 struct fe_baton *b = (struct fe_baton *)baton;
96 if (entry->changelist
97 && (strcmp(entry->changelist, b->changelist_name) == 0))
99 if ((entry->kind == svn_node_file)
100 || ((entry->kind == svn_node_dir)
101 && (strcmp(entry->name, SVN_WC_ENTRY_THIS_DIR) == 0)))
103 if (b->store_paths)
104 APR_ARRAY_PUSH(b->path_list, const char *) = apr_pstrdup(b->pool,
105 path);
106 else
107 SVN_ERR(b->callback_func(b->callback_baton, path));
111 return SVN_NO_ERROR;
114 static const svn_wc_entry_callbacks2_t entry_callbacks =
115 { found_an_entry, svn_client__default_walker_error_handler };
117 svn_error_t *
118 svn_client_get_changelist(apr_array_header_t **paths,
119 const char *changelist_name,
120 const char *root_path,
121 svn_client_ctx_t *ctx,
122 apr_pool_t *pool)
124 struct fe_baton feb;
125 svn_wc_adm_access_t *adm_access;
127 feb.store_paths = TRUE;
128 feb.pool = pool;
129 feb.changelist_name = changelist_name;
130 feb.path_list = apr_array_make(pool, 1, sizeof(const char *));
132 SVN_ERR(svn_wc_adm_probe_open3(&adm_access, NULL, root_path,
133 FALSE, /* no write lock */
134 -1, /* levels to lock == infinity */
135 ctx->cancel_func, ctx->cancel_baton, pool));
137 SVN_ERR(svn_wc_walk_entries3(root_path, adm_access,
138 &entry_callbacks, &feb,
139 svn_depth_infinity,
140 FALSE, /* don't show hidden entries */
141 ctx->cancel_func, ctx->cancel_baton,
142 pool));
144 SVN_ERR(svn_wc_adm_close(adm_access));
146 *paths = feb.path_list;
147 return SVN_NO_ERROR;
151 svn_error_t *
152 svn_client_get_changelist_streamy(svn_changelist_receiver_t callback_func,
153 void *callback_baton,
154 const char *changelist_name,
155 const char *root_path,
156 svn_client_ctx_t *ctx,
157 apr_pool_t *pool)
159 struct fe_baton feb;
160 svn_wc_adm_access_t *adm_access;
162 feb.store_paths = FALSE;
163 feb.callback_func = callback_func;
164 feb.callback_baton = callback_baton;
165 feb.pool = pool;
166 feb.changelist_name = changelist_name;
167 feb.path_list = apr_array_make(pool, 1, sizeof(const char *));
169 SVN_ERR(svn_wc_adm_probe_open3(&adm_access, NULL, root_path,
170 FALSE, /* no write lock */
171 -1, /* levels to lock == infinity */
172 ctx->cancel_func, ctx->cancel_baton, pool));
174 SVN_ERR(svn_wc_walk_entries3(root_path, adm_access,
175 &entry_callbacks, &feb,
176 svn_depth_infinity,
177 FALSE, /* don't show hidden entries */
178 ctx->cancel_func, ctx->cancel_baton,
179 pool));
181 SVN_ERR(svn_wc_adm_close(adm_access));
183 return SVN_NO_ERROR;