1238384Sjkim/*
2238384Sjkim * resolve-cmd.c -- Subversion resolve subcommand
3238384Sjkim *
4238384Sjkim * ====================================================================
5238384Sjkim *    Licensed to the Apache Software Foundation (ASF) under one
6238384Sjkim *    or more contributor license agreements.  See the NOTICE file
7238384Sjkim *    distributed with this work for additional information
8238384Sjkim *    regarding copyright ownership.  The ASF licenses this file
9238384Sjkim *    to you under the Apache License, Version 2.0 (the
10238384Sjkim *    "License"); you may not use this file except in compliance
11238384Sjkim *    with the License.  You may obtain a copy of the License at
12238384Sjkim *
13238384Sjkim *      http://www.apache.org/licenses/LICENSE-2.0
14238384Sjkim *
15238384Sjkim *    Unless required by applicable law or agreed to in writing,
16238384Sjkim *    software distributed under the License is distributed on an
17238384Sjkim *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18238384Sjkim *    KIND, either express or implied.  See the License for the
19238384Sjkim *    specific language governing permissions and limitations
20238384Sjkim *    under the License.
21238384Sjkim * ====================================================================
22238384Sjkim */
23238384Sjkim
24238384Sjkim/* ==================================================================== */
25238384Sjkim
26238384Sjkim
27238384Sjkim
28238384Sjkim/*** Includes. ***/
29238384Sjkim#include "svn_path.h"
30238384Sjkim#include "svn_client.h"
31238384Sjkim#include "svn_error.h"
32238384Sjkim#include "svn_pools.h"
33238384Sjkim#include "cl.h"
34238384Sjkim
35238384Sjkim#include "svn_private_config.h"
36238384Sjkim
37238384Sjkim
38238384Sjkim
39238384Sjkim/*** Code. ***/
40238384Sjkim
41238384Sjkim/* This implements the `svn_opt_subcommand_t' interface. */
42238384Sjkimsvn_error_t *
43238384Sjkimsvn_cl__resolve(apr_getopt_t *os,
44238384Sjkim                void *baton,
45238384Sjkim                apr_pool_t *scratch_pool)
46238384Sjkim{
47238384Sjkim  svn_cl__opt_state_t *opt_state = ((svn_cl__cmd_baton_t *) baton)->opt_state;
48238384Sjkim  svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
49238384Sjkim  svn_wc_conflict_choice_t conflict_choice;
50238384Sjkim  svn_error_t *err;
51238384Sjkim  apr_array_header_t *targets;
52238384Sjkim  int i;
53238384Sjkim  apr_pool_t *iterpool;
54238384Sjkim  svn_boolean_t had_error = FALSE;
55238384Sjkim
56238384Sjkim  switch (opt_state->accept_which)
57238384Sjkim    {
58238384Sjkim    case svn_cl__accept_working:
59238384Sjkim      conflict_choice = svn_wc_conflict_choose_merged;
60238384Sjkim      break;
61238384Sjkim    case svn_cl__accept_base:
62238384Sjkim      conflict_choice = svn_wc_conflict_choose_base;
63238384Sjkim      break;
64238384Sjkim    case svn_cl__accept_theirs_conflict:
65238384Sjkim      conflict_choice = svn_wc_conflict_choose_theirs_conflict;
66238384Sjkim      break;
67238384Sjkim    case svn_cl__accept_mine_conflict:
68238384Sjkim      conflict_choice = svn_wc_conflict_choose_mine_conflict;
69238384Sjkim      break;
70238384Sjkim    case svn_cl__accept_theirs_full:
71246772Sjkim      conflict_choice = svn_wc_conflict_choose_theirs_full;
72246772Sjkim      break;
73238384Sjkim    case svn_cl__accept_mine_full:
74238384Sjkim      conflict_choice = svn_wc_conflict_choose_mine_full;
75238384Sjkim      break;
76238384Sjkim    case svn_cl__accept_unspecified:
77238384Sjkim      if (opt_state->non_interactive)
78238384Sjkim        return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
79238384Sjkim                                _("missing --accept option"));
80238384Sjkim      conflict_choice = svn_wc_conflict_choose_unspecified;
81238384Sjkim      break;
82238384Sjkim    default:
83238384Sjkim      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
84238384Sjkim                              _("invalid 'accept' ARG"));
85238384Sjkim    }
86238384Sjkim
87238384Sjkim  SVN_ERR(svn_cl__args_to_target_array_print_reserved(&targets, os,
88238384Sjkim                                                      opt_state->targets,
89238384Sjkim                                                      ctx, FALSE,
90238384Sjkim                                                      scratch_pool));
91238384Sjkim  if (! targets->nelts)
92238384Sjkim    svn_opt_push_implicit_dot_target(targets, scratch_pool);
93238384Sjkim
94238384Sjkim  if (opt_state->depth == svn_depth_unknown)
95238384Sjkim    {
96238384Sjkim      if (opt_state->accept_which == svn_cl__accept_unspecified)
97238384Sjkim        opt_state->depth = svn_depth_infinity;
98238384Sjkim      else
99238384Sjkim        opt_state->depth = svn_depth_empty;
100238384Sjkim    }
101238384Sjkim
102238384Sjkim  SVN_ERR(svn_cl__eat_peg_revisions(&targets, targets, scratch_pool));
103238384Sjkim
104238384Sjkim  SVN_ERR(svn_cl__check_targets_are_local_paths(targets));
105238384Sjkim
106238384Sjkim  iterpool = svn_pool_create(scratch_pool);
107238384Sjkim  for (i = 0; i < targets->nelts; i++)
108238384Sjkim    {
109238384Sjkim      const char *target = APR_ARRAY_IDX(targets, i, const char *);
110238384Sjkim      svn_pool_clear(iterpool);
111238384Sjkim      SVN_ERR(svn_cl__check_cancel(ctx->cancel_baton));
112238384Sjkim      err = svn_client_resolve(target,
113238384Sjkim                               opt_state->depth, conflict_choice,
114238384Sjkim                               ctx,
115238384Sjkim                               iterpool);
116238384Sjkim      if (err)
117238384Sjkim        {
118238384Sjkim          svn_handle_warning2(stderr, err, "svn: ");
119238384Sjkim          svn_error_clear(err);
120238384Sjkim          had_error = TRUE;
121238384Sjkim        }
122238384Sjkim    }
123238384Sjkim  svn_pool_destroy(iterpool);
124238384Sjkim
125238384Sjkim  if (had_error)
126238384Sjkim    return svn_error_create(SVN_ERR_WC_CONFLICT_RESOLVER_FAILURE, NULL,
127238384Sjkim                            _("Failure occurred resolving one or more "
128238384Sjkim                              "conflicts"));
129238384Sjkim
130238384Sjkim  return SVN_NO_ERROR;
131238384Sjkim}
132238384Sjkim