2 * changelist-cmd.c -- Associate (or deassociate) a wc path with a changelist.
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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
21 * ====================================================================
24 #include "svn_client.h"
25 #include "svn_error_codes.h"
26 #include "svn_error.h"
32 #include "svn_private_config.h"
37 /* This implements the `svn_opt_subcommand_t' interface. */
39 svn_cl__changelist(apr_getopt_t *os,
43 const char *changelist_name = NULL;
44 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
45 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
46 apr_array_header_t *targets;
47 svn_depth_t depth = opt_state->depth;
48 apr_array_header_t *errors = apr_array_make(pool, 0, sizeof(apr_status_t));
50 /* If we're not removing changelists, then our first argument should
51 be the name of a changelist. */
53 if (! opt_state->remove)
55 apr_array_header_t *args;
56 SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool));
57 changelist_name = APR_ARRAY_IDX(args, 0, const char *);
58 SVN_ERR(svn_utf_cstring_to_utf8(&changelist_name,
59 changelist_name, pool));
62 /* Parse the remaining arguments as paths. */
63 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
67 /* Changelist has no implicit dot-target `.', so don't you put that
70 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
72 SVN_ERR(svn_cl__check_targets_are_local_paths(targets));
75 /* FIXME: This is required because svn_client_create_context()
76 always initializes ctx->notify_func2 to a wrapper function
77 which calls ctx->notify_func() if it isn't NULL. In other
78 words, typically, ctx->notify_func2 is never NULL. This isn't
79 usually a problem, but the changelist logic generates
80 svn_error_t's as part of its notification.
82 So, svn_wc_set_changelist() checks its notify_func (our
83 ctx->notify_func2) for NULL-ness, and seeing non-NULL-ness,
84 generates a notificaton object and svn_error_t to describe some
85 problem. It passes that off to its notify_func (our
86 ctx->notify_func2) which drops the notification on the floor
87 (because it wraps a NULL ctx->notify_func). But svn_error_t's
88 dropped on the floor cause SEGFAULTs at pool cleanup time --
89 they need instead to be cleared.
91 SOOOooo... we set our ctx->notify_func2 to NULL so the WC code
92 doesn't even generate the errors. */
93 ctx->notify_func2 = NULL;
95 if (depth == svn_depth_unknown)
96 depth = svn_depth_empty;
98 SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
103 svn_client_add_to_changelist(targets, changelist_name,
104 depth, opt_state->changelists,
106 errors, opt_state->quiet,
107 SVN_ERR_UNVERSIONED_RESOURCE,
108 SVN_ERR_WC_PATH_NOT_FOUND,
114 svn_client_remove_from_changelists(targets, depth,
115 opt_state->changelists,
117 errors, opt_state->quiet,
118 SVN_ERR_UNVERSIONED_RESOURCE,
119 SVN_ERR_WC_PATH_NOT_FOUND,
123 if (errors->nelts > 0)
128 err = svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL, NULL);
129 for (i = 0; i < errors->nelts; i++)
131 apr_status_t status = APR_ARRAY_IDX(errors, i, apr_status_t);
133 if (status == SVN_ERR_WC_PATH_NOT_FOUND)
134 err = svn_error_quick_wrap(err,
135 _("Could not set changelists on "
136 "all targets because some targets "
138 else if (status == SVN_ERR_UNVERSIONED_RESOURCE)
139 err = svn_error_quick_wrap(err,
140 _("Could not set changelists on "
141 "all targets because some targets "
142 "are not versioned"));
145 return svn_error_trace(err);