1251881Speter/* 2251881Speter * changelist-cmd.c -- Associate (or deassociate) a wc path with a changelist. 3251881Speter * 4251881Speter * ==================================================================== 5251881Speter * Licensed to the Apache Software Foundation (ASF) under one 6251881Speter * or more contributor license agreements. See the NOTICE file 7251881Speter * distributed with this work for additional information 8251881Speter * regarding copyright ownership. The ASF licenses this file 9251881Speter * to you under the Apache License, Version 2.0 (the 10251881Speter * "License"); you may not use this file except in compliance 11251881Speter * with the License. You may obtain a copy of the License at 12251881Speter * 13251881Speter * http://www.apache.org/licenses/LICENSE-2.0 14251881Speter * 15251881Speter * Unless required by applicable law or agreed to in writing, 16251881Speter * software distributed under the License is distributed on an 17251881Speter * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 18251881Speter * KIND, either express or implied. See the License for the 19251881Speter * specific language governing permissions and limitations 20251881Speter * under the License. 21251881Speter * ==================================================================== 22251881Speter */ 23251881Speter 24251881Speter#include "svn_client.h" 25251881Speter#include "svn_error_codes.h" 26251881Speter#include "svn_error.h" 27251881Speter#include "svn_path.h" 28251881Speter#include "svn_utf.h" 29251881Speter 30251881Speter#include "cl.h" 31251881Speter 32251881Speter#include "svn_private_config.h" 33251881Speter 34251881Speter 35251881Speter 36251881Speter 37251881Speter/* This implements the `svn_opt_subcommand_t' interface. */ 38251881Spetersvn_error_t * 39251881Spetersvn_cl__changelist(apr_getopt_t *os, 40251881Speter void *baton, 41251881Speter apr_pool_t *pool) 42251881Speter{ 43251881Speter const char *changelist_name = NULL; 44251881Speter svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state; 45251881Speter svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx; 46251881Speter apr_array_header_t *targets; 47251881Speter svn_depth_t depth = opt_state->depth; 48251881Speter apr_array_header_t *errors = apr_array_make(pool, 0, sizeof(apr_status_t)); 49251881Speter 50251881Speter /* If we're not removing changelists, then our first argument should 51251881Speter be the name of a changelist. */ 52251881Speter 53251881Speter if (! opt_state->remove) 54251881Speter { 55251881Speter apr_array_header_t *args; 56251881Speter SVN_ERR(svn_opt_parse_num_args(&args, os, 1, pool)); 57251881Speter changelist_name = APR_ARRAY_IDX(args, 0, const char *); 58251881Speter SVN_ERR(svn_utf_cstring_to_utf8(&changelist_name, 59251881Speter changelist_name, pool)); 60251881Speter } 61251881Speter 62251881Speter /* Parse the remaining arguments as paths. */ 63251881Speter SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os, 64251881Speter opt_state->targets, 65251881Speter ctx, FALSE, pool)); 66251881Speter 67251881Speter /* Changelist has no implicit dot-target `.', so don't you put that 68251881Speter code here! */ 69251881Speter if (! targets->nelts) 70251881Speter return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL); 71251881Speter 72251881Speter SVN_ERR(svn_cl__check_targets_are_local_paths(targets)); 73251881Speter 74251881Speter if (opt_state->quiet) 75251881Speter /* FIXME: This is required because svn_client_create_context() 76251881Speter always initializes ctx->notify_func2 to a wrapper function 77251881Speter which calls ctx->notify_func() if it isn't NULL. In other 78251881Speter words, typically, ctx->notify_func2 is never NULL. This isn't 79251881Speter usually a problem, but the changelist logic generates 80251881Speter svn_error_t's as part of its notification. 81251881Speter 82251881Speter So, svn_wc_set_changelist() checks its notify_func (our 83251881Speter ctx->notify_func2) for NULL-ness, and seeing non-NULL-ness, 84251881Speter generates a notificaton object and svn_error_t to describe some 85251881Speter problem. It passes that off to its notify_func (our 86251881Speter ctx->notify_func2) which drops the notification on the floor 87251881Speter (because it wraps a NULL ctx->notify_func). But svn_error_t's 88251881Speter dropped on the floor cause SEGFAULTs at pool cleanup time -- 89251881Speter they need instead to be cleared. 90251881Speter 91251881Speter SOOOooo... we set our ctx->notify_func2 to NULL so the WC code 92251881Speter doesn't even generate the errors. */ 93251881Speter ctx->notify_func2 = NULL; 94251881Speter 95251881Speter if (depth == svn_depth_unknown) 96251881Speter depth = svn_depth_empty; 97251881Speter 98251881Speter SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool)); 99251881Speter 100251881Speter if (changelist_name) 101251881Speter { 102251881Speter SVN_ERR(svn_cl__try( 103251881Speter svn_client_add_to_changelist(targets, changelist_name, 104251881Speter depth, opt_state->changelists, 105251881Speter ctx, pool), 106251881Speter errors, opt_state->quiet, 107251881Speter SVN_ERR_UNVERSIONED_RESOURCE, 108251881Speter SVN_ERR_WC_PATH_NOT_FOUND, 109251881Speter SVN_NO_ERROR)); 110251881Speter } 111251881Speter else 112251881Speter { 113251881Speter SVN_ERR(svn_cl__try( 114251881Speter svn_client_remove_from_changelists(targets, depth, 115251881Speter opt_state->changelists, 116251881Speter ctx, pool), 117251881Speter errors, opt_state->quiet, 118251881Speter SVN_ERR_UNVERSIONED_RESOURCE, 119251881Speter SVN_ERR_WC_PATH_NOT_FOUND, 120251881Speter SVN_NO_ERROR)); 121251881Speter } 122251881Speter 123251881Speter if (errors->nelts > 0) 124251881Speter { 125251881Speter int i; 126251881Speter svn_error_t *err; 127251881Speter 128251881Speter err = svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL, NULL); 129251881Speter for (i = 0; i < errors->nelts; i++) 130251881Speter { 131251881Speter apr_status_t status = APR_ARRAY_IDX(errors, i, apr_status_t); 132251881Speter 133251881Speter if (status == SVN_ERR_WC_PATH_NOT_FOUND) 134251881Speter err = svn_error_quick_wrap(err, 135251881Speter _("Could not set changelists on " 136251881Speter "all targets because some targets " 137251881Speter "don't exist")); 138251881Speter else if (status == SVN_ERR_UNVERSIONED_RESOURCE) 139251881Speter err = svn_error_quick_wrap(err, 140251881Speter _("Could not set changelists on " 141251881Speter "all targets because some targets " 142251881Speter "are not versioned")); 143251881Speter } 144251881Speter 145251881Speter return svn_error_trace(err); 146251881Speter } 147251881Speter 148251881Speter return SVN_NO_ERROR; 149251881Speter} 150