]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/subversion/subversion/svn/patch-cmd.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / subversion / subversion / svn / patch-cmd.c
1 /*
2  * patch-cmd.c -- Apply changes to a working copy.
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 \f
28 /*** Includes. ***/
29
30 #include "svn_client.h"
31 #include "svn_dirent_uri.h"
32 #include "svn_path.h"
33 #include "svn_error.h"
34 #include "svn_types.h"
35 #include "cl.h"
36
37 #include "svn_private_config.h"
38
39 \f
40 /*** Code. ***/
41
42
43 /* This implements the `svn_opt_subcommand_t' interface. */
44 svn_error_t *
45 svn_cl__patch(apr_getopt_t *os,
46               void *baton,
47               apr_pool_t *pool)
48 {
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;
56
57   opt_state = ((svn_cl__cmd_baton_t *)baton)->opt_state;
58   ctx = ((svn_cl__cmd_baton_t *)baton)->ctx;
59
60   SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
61                                                       opt_state->targets,
62                                                       ctx, FALSE, pool));
63   SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, pool));
64
65   if (targets->nelts < 1)
66     return svn_error_create(SVN_ERR_CL_INSUFFICIENT_ARGS, 0, NULL);
67
68   if (targets->nelts > 2)
69     return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, 0, NULL);
70
71   patch_path = APR_ARRAY_IDX(targets, 0, const char *);
72
73   SVN_ERR(svn_cl__check_target_is_local_path(patch_path));
74
75   SVN_ERR(svn_dirent_get_absolute(&abs_patch_path, patch_path, pool));
76
77   if (targets->nelts == 1)
78     target_path = ""; /* "" is the canonical form of "." */
79   else
80     {
81       target_path = APR_ARRAY_IDX(targets, 1, const char *);
82
83       SVN_ERR(svn_cl__check_target_is_local_path(target_path));
84     }
85   SVN_ERR(svn_dirent_get_absolute(&abs_target_path, target_path, pool));
86
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));
92
93
94   if (! opt_state->quiet)
95     SVN_ERR(svn_cl__notifier_print_conflict_stats(ctx->notify_baton2, pool));
96
97   return SVN_NO_ERROR;
98 }