]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/subversion/subversion/svn/changelist-cmd.c
MFC r275385 (by bapt):
[FreeBSD/stable/10.git] / contrib / subversion / subversion / svn / changelist-cmd.c
1 /*
2  * changelist-cmd.c -- Associate (or deassociate) a wc path with a changelist.
3  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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
20  *    under the License.
21  * ====================================================================
22  */
23
24 #include "svn_client.h"
25 #include "svn_error_codes.h"
26 #include "svn_error.h"
27 #include "svn_path.h"
28 #include "svn_utf.h"
29
30 #include "cl.h"
31
32 #include "svn_private_config.h"
33
34
35 \f
36
37 /* This implements the `svn_opt_subcommand_t' interface. */
38 svn_error_t *
39 svn_cl__changelist(apr_getopt_t *os,
40                    void *baton,
41                    apr_pool_t *pool)
42 {
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));
49
50   /* If we're not removing changelists, then our first argument should
51      be the name of a changelist. */
52
53   if (! opt_state->remove)
54     {
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));
60     }
61
62   /* Parse the remaining arguments as paths. */
63   SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
64                                                       opt_state->targets,
65                                                       ctx, FALSE, pool));
66
67   /* Changelist has no implicit dot-target `.', so don't you put that
68      code here! */
69   if (! targets->nelts)
70     return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
71
72   SVN_ERR(svn_cl__check_targets_are_local_paths(targets));
73
74   if (opt_state->quiet)
75     ctx->notify_func2 = NULL; /* Easy out: avoid unneeded work */
76
77   if (depth == svn_depth_unknown)
78     depth = svn_depth_empty;
79
80   SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
81
82   if (changelist_name)
83     {
84       SVN_ERR(svn_cl__try(
85                svn_client_add_to_changelist(targets, changelist_name,
86                                             depth, opt_state->changelists,
87                                             ctx, pool),
88                errors, opt_state->quiet,
89                SVN_ERR_UNVERSIONED_RESOURCE,
90                SVN_ERR_WC_PATH_NOT_FOUND,
91                0));
92     }
93   else
94     {
95       SVN_ERR(svn_cl__try(
96                svn_client_remove_from_changelists(targets, depth,
97                                                   opt_state->changelists,
98                                                   ctx, pool),
99                errors, opt_state->quiet,
100                SVN_ERR_UNVERSIONED_RESOURCE,
101                SVN_ERR_WC_PATH_NOT_FOUND,
102                0));
103     }
104
105   if (errors->nelts > 0)
106     {
107       int i;
108       svn_error_t *err;
109
110       err = svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL, NULL);
111       for (i = 0; i < errors->nelts; i++)
112         {
113           apr_status_t status = APR_ARRAY_IDX(errors, i, apr_status_t);
114
115           if (status == SVN_ERR_WC_PATH_NOT_FOUND)
116             err = svn_error_quick_wrap(err,
117                                        _("Could not set changelists on "
118                                          "all targets because some targets "
119                                          "don't exist"));
120           else if (status == SVN_ERR_UNVERSIONED_RESOURCE)
121             err = svn_error_quick_wrap(err,
122                                        _("Could not set changelists on "
123                                          "all targets because some targets "
124                                          "are not versioned"));
125         }
126
127       return svn_error_trace(err);
128     }
129
130   return SVN_NO_ERROR;
131 }