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 /* This implements the `svn_opt_subcommand_t' interface. */
85 svn_cl__lock(apr_getopt_t *os,
89 svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
90 svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
91 apr_array_header_t *targets;
94 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
98 /* We only support locking files, so '.' is not valid. */
100 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
102 SVN_ERR(svn_cl__assert_homogeneous_target_type(targets));
105 SVN_ERR(get_comment(&comment, ctx, opt_state, pool));
107 SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
109 return svn_client_lock(targets, comment, opt_state->force, ctx, pool);