2 * patch-cmd.c -- Apply changes to a working copy.
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_client.h"
31 #include "svn_dirent_uri.h"
33 #include "svn_error.h"
34 #include "svn_types.h"
37 #include "svn_private_config.h"
43 /* This implements the `svn_opt_subcommand_t' interface. */
45 svn_cl__patch(apr_getopt_t *os,
49 svn_cl__opt_state_t *opt_state;
50 svn_client_ctx_t *ctx;
51 apr_array_header_t *targets;
52 const char *abs_patch_path;
53 const char *patch_path;
54 const char *abs_target_path;
55 const char *target_path;
57 opt_state = ((svn_cl__cmd_baton_t *)baton)->opt_state;
58 ctx = ((svn_cl__cmd_baton_t *)baton)->ctx;
60 SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
63 SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
65 if (targets->nelts < 1)
66 return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
68 if (targets->nelts > 2)
69 return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
71 patch_path = APR_ARRAY_IDX(targets, 0, const char *);
73 SVN_ERR(svn_cl__check_target_is_local_path(patch_path));
75 SVN_ERR(svn_dirent_get_absolute(&abs_patch_path, patch_path, pool));
77 if (targets->nelts == 1)
78 target_path = ""; /* "" is the canonical form of "." */
81 target_path = APR_ARRAY_IDX(targets, 1, const char *);
83 SVN_ERR(svn_cl__check_target_is_local_path(target_path));
85 SVN_ERR(svn_dirent_get_absolute(&abs_target_path, target_path, pool));
87 SVN_ERR(svn_client_patch(abs_patch_path, abs_target_path,
88 opt_state->dry_run, opt_state->strip,
89 opt_state->reverse_diff,
90 opt_state->ignore_whitespace,
91 TRUE, NULL, NULL, ctx, pool));
94 if (! opt_state->quiet)
95 SVN_ERR(svn_cl__notifier_print_conflict_stats(ctx->notify_baton2, pool));