1184588Sdfr/*
2184588Sdfr * resolve-cmd.c -- Subversion resolve subcommand
3184588Sdfr *
4184588Sdfr * ====================================================================
5184588Sdfr *    Licensed to the Apache Software Foundation (ASF) under one
6184588Sdfr *    or more contributor license agreements.  See the NOTICE file
7184588Sdfr *    distributed with this work for additional information
8184588Sdfr *    regarding copyright ownership.  The ASF licenses this file
9184588Sdfr *    to you under the Apache License, Version 2.0 (the
10184588Sdfr *    "License"); you may not use this file except in compliance
11184588Sdfr *    with the License.  You may obtain a copy of the License at
12184588Sdfr *
13184588Sdfr *      http://www.apache.org/licenses/LICENSE-2.0
14184588Sdfr *
15184588Sdfr *    Unless required by applicable law or agreed to in writing,
16184588Sdfr *    software distributed under the License is distributed on an
17184588Sdfr *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18184588Sdfr *    KIND, either express or implied.  See the License for the
19184588Sdfr *    specific language governing permissions and limitations
20184588Sdfr *    under the License.
21184588Sdfr * ====================================================================
22184588Sdfr */
23184588Sdfr
24184588Sdfr/* ==================================================================== */
25184588Sdfr
26184588Sdfr
27249592Sken
28249592Sken/*** Includes. ***/
29249592Sken#include "svn_path.h"
30249592Sken#include "svn_client.h"
31249592Sken#include "svn_error.h"
32249592Sken#include "svn_pools.h"
33249592Sken#include "cl.h"
34249592Sken
35249592Sken#include "svn_private_config.h"
36249592Sken
37249592Sken
38260097Smav
39249592Sken/*** Code. ***/
40249592Sken
41249592Sken/* This implements the `svn_opt_subcommand_t' interface. */
42249592Skensvn_error_t *
43249592Skensvn_cl__resolve(apr_getopt_t *os,
44249592Sken                void *baton,
45249592Sken                apr_pool_t *scratch_pool)
46249592Sken{
47249592Sken  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
48249592Sken  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
49249592Sken  svn_wc_conflict_choice_t conflict_choice;
50249592Sken  svn_error_t *err;
51249592Sken  apr_array_header_t *targets;
52249592Sken  int i;
53249592Sken  apr_pool_t *iterpool;
54249592Sken  svn_boolean_t had_error = FALSE;
55249592Sken
56249592Sken  switch (opt_state->accept_which)
57249592Sken    {
58249592Sken    case svn_cl__accept_working:
59249592Sken      conflict_choice = svn_wc_conflict_choose_merged;
60249592Sken      break;
61260097Smav    case svn_cl__accept_base:
62249592Sken      conflict_choice = svn_wc_conflict_choose_base;
63249592Sken      break;
64249592Sken    case svn_cl__accept_theirs_conflict:
65249592Sken      conflict_choice = svn_wc_conflict_choose_theirs_conflict;
66249592Sken      break;
67249592Sken    case svn_cl__accept_mine_conflict:
68249592Sken      conflict_choice = svn_wc_conflict_choose_mine_conflict;
69249592Sken      break;
70249592Sken    case svn_cl__accept_theirs_full:
71249592Sken      conflict_choice = svn_wc_conflict_choose_theirs_full;
72260097Smav      break;
73260097Smav    case svn_cl__accept_mine_full:
74260097Smav      conflict_choice = svn_wc_conflict_choose_mine_full;
75260097Smav      break;
76260097Smav    case svn_cl__accept_unspecified:
77249592Sken      if (opt_state->non_interactive)
78249592Sken        return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
79249592Sken                                _("missing --accept option"));
80249592Sken      conflict_choice = svn_wc_conflict_choose_unspecified;
81249592Sken      break;
82249592Sken    default:
83249592Sken      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
84249592Sken                              _("invalid 'accept' ARG"));
85249592Sken    }
86249592Sken
87259765Smav  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
88249592Sken                                                      opt_state->targets,
89249592Sken                                                      ctx, FALSE,
90249592Sken                                                      scratch_pool));
91249592Sken  if (! targets->nelts)
92249592Sken    svn_opt_push_implicit_dot_target(targets, scratch_pool);
93249592Sken
94249592Sken  if (opt_state->depth == svn_depth_unknown)
95249592Sken    {
96249592Sken      if (opt_state->accept_which == svn_cl__accept_unspecified)
97249592Sken        opt_state->depth = svn_depth_infinity;
98260097Smav      else
99249592Sken        opt_state->depth = svn_depth_empty;
100249592Sken    }
101249592Sken
102249592Sken  SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, scratch_pool));
103249592Sken
104249592Sken  SVN_ERR(svn_cl__check_targets_are_local_paths(targets));
105249592Sken
106249592Sken  iterpool = svn_pool_create(scratch_pool);
107184588Sdfr  for (i = 0; i < targets->nelts; i++)
108249592Sken    {
109249592Sken      const char *target = APR_ARRAY_IDX(targets, i, const char *);
110249592Sken      svn_pool_clear(iterpool);
111249592Sken      SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
112249592Sken      err = svn_client_resolve(target,
113249592Sken                               opt_state->depth, conflict_choice,
114249592Sken                               ctx,
115                               iterpool);
116      if (err)
117        {
118          svn_handle_warning2(stderr, err, "svn: ");
119          svn_error_clear(err);
120          had_error = TRUE;
121        }
122    }
123  svn_pool_destroy(iterpool);
124
125  if (had_error)
126    return svn_error_create(SVN_ERR_CL_ERROR_PROCESSING_EXTERNALS, NULL,
127                            _("Failure occurred resolving one or more "
128                              "conflicts"));
129
130  return SVN_NO_ERROR;
131}
132