1/*
2 * changelist.c:  implementation of the 'changelist' command
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/* ==================================================================== */
25
26
27
28/*** Includes. ***/
29
30#include "svn_client.h"
31#include "svn_wc.h"
32#include "svn_pools.h"
33#include "svn_dirent_uri.h"
34#include "svn_path.h"
35#include "svn_hash.h"
36
37#include "client.h"
38#include "private/svn_wc_private.h"
39#include "svn_private_config.h"
40
41
42
43
44svn_error_t *
45svn_client_add_to_changelist(const apr_array_header_t *paths,
46                             const char *changelist,
47                             svn_depth_t depth,
48                             const apr_array_header_t *changelists,
49                             svn_client_ctx_t *ctx,
50                             apr_pool_t *pool)
51{
52  apr_pool_t *iterpool = svn_pool_create(pool);
53  int i;
54
55  if (changelist[0] == '\0')
56    return svn_error_create(SVN_ERR_BAD_CHANGELIST_NAME, NULL,
57                            _("Target changelist name must not be empty"));
58
59  for (i = 0; i < paths->nelts; i++)
60    {
61      const char *path = APR_ARRAY_IDX(paths, i, const char *);
62
63      if (svn_path_is_url(path))
64        return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
65                                 _("'%s' is not a local path"), path);
66    }
67
68  for (i = 0; i < paths->nelts; i++)
69    {
70      const char *path = APR_ARRAY_IDX(paths, i, const char *);
71      const char *local_abspath;
72
73      svn_pool_clear(iterpool);
74      SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, iterpool));
75
76      SVN_ERR(svn_wc_set_changelist2(ctx->wc_ctx, local_abspath, changelist,
77                                     depth, changelists,
78                                     ctx->cancel_func, ctx->cancel_baton,
79                                     ctx->notify_func2, ctx->notify_baton2,
80                                     iterpool));
81    }
82
83  svn_pool_destroy(iterpool);
84  return SVN_NO_ERROR;
85}
86
87
88svn_error_t *
89svn_client_remove_from_changelists(const apr_array_header_t *paths,
90                                   svn_depth_t depth,
91                                   const apr_array_header_t *changelists,
92                                   svn_client_ctx_t *ctx,
93                                   apr_pool_t *pool)
94{
95  apr_pool_t *iterpool = svn_pool_create(pool);
96  int i;
97
98  for (i = 0; i < paths->nelts; i++)
99    {
100      const char *path = APR_ARRAY_IDX(paths, i, const char *);
101
102      if (svn_path_is_url(path))
103        return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
104                                 _("'%s' is not a local path"), path);
105    }
106
107  for (i = 0; i < paths->nelts; i++)
108    {
109      const char *path = APR_ARRAY_IDX(paths, i, const char *);
110      const char *local_abspath;
111
112      svn_pool_clear(iterpool);
113      SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, iterpool));
114
115      SVN_ERR(svn_wc_set_changelist2(ctx->wc_ctx, local_abspath, NULL,
116                                     depth, changelists,
117                                     ctx->cancel_func, ctx->cancel_baton,
118                                     ctx->notify_func2, ctx->notify_baton2,
119                                     iterpool));
120    }
121
122  svn_pool_destroy(iterpool);
123  return SVN_NO_ERROR;
124}
125
126
127svn_error_t *
128svn_client_get_changelists(const char *path,
129                           const apr_array_header_t *changelists,
130                           svn_depth_t depth,
131                           svn_changelist_receiver_t callback_func,
132                           void *callback_baton,
133                           svn_client_ctx_t *ctx,
134                           apr_pool_t *pool)
135{
136  const char *local_abspath;
137
138  SVN_ERR(svn_dirent_get_absolute(&local_abspath, path, pool));
139
140  SVN_ERR(svn_wc_get_changelists(ctx->wc_ctx, local_abspath, depth, changelists,
141                                 callback_func, callback_baton,
142                                 ctx->cancel_func, ctx->cancel_baton, pool));
143  return SVN_NO_ERROR;
144}
145