2 * lock-cmd.c -- LOck a working copy path in the repository.
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 /* ==================================================================== */
30 #include "svn_pools.h"
31 #include "svn_client.h"
32 #include "svn_subst.h"
34 #include "svn_error_codes.h"
35 #include "svn_error.h"
36 #include "svn_cmdline.h"
38 #include "svn_private_config.h"
43 /* Get a lock comment, allocate it in POOL and store it in *COMMENT. */
45 get_comment(const char **comment, svn_client_ctx_t *ctx,
46 svn_cl__opt_state_t *opt_state, apr_pool_t *pool)
48 svn_string_t *comment_string;
50 if (opt_state->filedata)
52 /* Get it from the -F argument. */
53 if (strlen(opt_state->filedata->data) < opt_state->filedata->len)
55 /* A message containing a zero byte can't be represented as a C
57 return svn_error_create(SVN_ERR_CL_BAD_LOG_MESSAGE, NULL,
58 _("Lock comment contains a zero byte"));
60 comment_string = svn_string_create(opt_state->filedata->data, pool);
63 else if (opt_state->message)
65 /* Get if from the -m option. */
66 comment_string = svn_string_create(opt_state->message, pool);
74 /* Translate to UTF8/LF. */
75 SVN_ERR(svn_subst_translate_string2(&comment_string, NULL, NULL,
76 comment_string, opt_state->encoding,
78 *comment = comment_string->data;
83 /* Baton for notify_lock_handler */
84 struct notify_lock_baton_t
87 svn_wc_notify_func2_t inner_notify;
88 svn_boolean_t had_failure;
91 /* Implements svn_wc_notify_func2_t for svn_cl__lock */
93 notify_lock_handler(void *baton,
94 const svn_wc_notify_t *notify,
95 apr_pool_t *scratch_pool)
97 struct notify_lock_baton_t *nlb = baton;
99 if (notify->action == svn_wc_notify_failed_lock)
100 nlb->had_failure = TRUE;
102 if (nlb->inner_notify)
103 nlb->inner_notify(nlb->inner_baton, notify, scratch_pool);
106 /* This implements the `svn_opt_subcommand_t' interface. */
108 svn_cl__lock(apr_getopt_t *os,
112 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
113 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
114 apr_array_header_t *targets;
116 struct notify_lock_baton_t nlb;
118 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
122 /* We only support locking files, so '.' is not valid. */
123 if (! targets->nelts)
124 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
126 SVN_ERR(svn_cl__assert_homogeneous_target_type(targets));
129 SVN_ERR(get_comment(&comment, ctx, opt_state, pool));
131 SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
133 nlb.inner_notify = ctx->notify_func2;
134 nlb.inner_baton = ctx->notify_baton2;
135 nlb.had_failure = FALSE;
137 ctx->notify_func2 = notify_lock_handler;
138 ctx->notify_baton2 = &nlb;
140 SVN_ERR(svn_client_lock(targets, comment, opt_state->force, ctx, pool));
143 return svn_error_create(SVN_ERR_ILLEGAL_TARGET, NULL,
144 _("One or more locks could not be obtained"));