conflict-callbacks.c [plain text]
#include <apr_xlate.h>
#define APR_WANT_STRFUNC
#include <apr_want.h>
#include "svn_hash.h"
#include "svn_cmdline.h"
#include "svn_client.h"
#include "svn_dirent_uri.h"
#include "svn_types.h"
#include "svn_pools.h"
#include "svn_sorts.h"
#include "svn_utf.h"
#include "cl.h"
#include "cl-conflicts.h"
#include "private/svn_cmdline_private.h"
#include "svn_private_config.h"
#define ARRAY_LEN(ary) ((sizeof (ary)) / (sizeof ((ary)[0])))
#define MAX_ARRAY_LEN(aryx, aryz) \
(ARRAY_LEN((aryx)) > ARRAY_LEN((aryz)) \
? ARRAY_LEN((aryx)) : ARRAY_LEN((aryz)))
struct svn_cl__interactive_conflict_baton_t {
svn_cl__accept_t accept_which;
apr_hash_t *config;
const char *editor_cmd;
svn_boolean_t external_failed;
svn_cmdline_prompt_baton_t *pb;
const char *path_prefix;
svn_boolean_t quit;
svn_cl__conflict_stats_t *conflict_stats;
svn_boolean_t printed_summary;
};
svn_error_t *
svn_cl__get_conflict_func_interactive_baton(
svn_cl__interactive_conflict_baton_t **b,
svn_cl__accept_t accept_which,
apr_hash_t *config,
const char *editor_cmd,
svn_cl__conflict_stats_t *conflict_stats,
svn_cancel_func_t cancel_func,
void *cancel_baton,
apr_pool_t *result_pool)
{
svn_cmdline_prompt_baton_t *pb = apr_palloc(result_pool, sizeof(*pb));
pb->cancel_func = cancel_func;
pb->cancel_baton = cancel_baton;
*b = apr_palloc(result_pool, sizeof(**b));
(*b)->accept_which = accept_which;
(*b)->config = config;
(*b)->editor_cmd = editor_cmd;
(*b)->external_failed = FALSE;
(*b)->pb = pb;
SVN_ERR(svn_dirent_get_absolute(&(*b)->path_prefix, "", result_pool));
(*b)->quit = FALSE;
(*b)->conflict_stats = conflict_stats;
(*b)->printed_summary = FALSE;
return SVN_NO_ERROR;
}
svn_cl__accept_t
svn_cl__accept_from_word(const char *word)
{
if (strcmp(word, SVN_CL__ACCEPT_POSTPONE) == 0
|| strcmp(word, "p") == 0 || strcmp(word, ":-P") == 0)
return svn_cl__accept_postpone;
if (strcmp(word, SVN_CL__ACCEPT_BASE) == 0)
return svn_cl__accept_base;
if (strcmp(word, SVN_CL__ACCEPT_WORKING) == 0)
return svn_cl__accept_working;
if (strcmp(word, SVN_CL__ACCEPT_MINE_CONFLICT) == 0
|| strcmp(word, "mc") == 0 || strcmp(word, "X-)") == 0)
return svn_cl__accept_mine_conflict;
if (strcmp(word, SVN_CL__ACCEPT_THEIRS_CONFLICT) == 0
|| strcmp(word, "tc") == 0 || strcmp(word, "X-(") == 0)
return svn_cl__accept_theirs_conflict;
if (strcmp(word, SVN_CL__ACCEPT_MINE_FULL) == 0
|| strcmp(word, "mf") == 0 || strcmp(word, ":-)") == 0)
return svn_cl__accept_mine_full;
if (strcmp(word, SVN_CL__ACCEPT_THEIRS_FULL) == 0
|| strcmp(word, "tf") == 0 || strcmp(word, ":-(") == 0)
return svn_cl__accept_theirs_full;
if (strcmp(word, SVN_CL__ACCEPT_EDIT) == 0
|| strcmp(word, "e") == 0 || strcmp(word, ":-E") == 0)
return svn_cl__accept_edit;
if (strcmp(word, SVN_CL__ACCEPT_LAUNCH) == 0
|| strcmp(word, "l") == 0 || strcmp(word, ":-l") == 0)
return svn_cl__accept_launch;
return svn_cl__accept_invalid;
}
static svn_error_t *
show_diff(const svn_wc_conflict_description2_t *desc,
const char *path_prefix,
svn_cancel_func_t cancel_func,
void *cancel_baton,
apr_pool_t *pool)
{
const char *path1, *path2;
const char *label1, *label2;
svn_diff_t *diff;
svn_stream_t *output;
svn_diff_file_options_t *options;
if (desc->merged_file)
{
if (desc->operation == svn_wc_operation_merge)
{
path1 = desc->my_abspath;
label1 = _("MINE");
}
else
{
path1 = desc->their_abspath;
label1 = _("THEIRS");
}
path2 = desc->merged_file;
label2 = _("MERGED");
}
else
{
path1 = desc->their_abspath;
label1 = _("THEIRS");
path2 = desc->my_abspath;
label2 = _("MINE");
}
label1 = apr_psprintf(pool, "%s\t- %s",
svn_cl__local_style_skip_ancestor(
path_prefix, path1, pool), label1);
label2 = apr_psprintf(pool, "%s\t- %s",
svn_cl__local_style_skip_ancestor(
path_prefix, path2, pool), label2);
options = svn_diff_file_options_create(pool);
options->ignore_eol_style = TRUE;
SVN_ERR(svn_stream_for_stdout(&output, pool));
SVN_ERR(svn_diff_file_diff_2(&diff, path1, path2,
options, pool));
return svn_diff_file_output_unified4(output, diff,
path1, path2,
label1, label2,
APR_LOCALE_CHARSET,
NULL,
options->show_c_function,
options->context_size,
cancel_func, cancel_baton,
pool);
}
static svn_error_t *
show_conflicts(const svn_wc_conflict_description2_t *desc,
svn_cancel_func_t cancel_func,
void *cancel_baton,
apr_pool_t *pool)
{
svn_diff_t *diff;
svn_stream_t *output;
svn_diff_file_options_t *options;
options = svn_diff_file_options_create(pool);
options->ignore_eol_style = TRUE;
SVN_ERR(svn_stream_for_stdout(&output, pool));
SVN_ERR(svn_diff_file_diff3_2(&diff,
desc->base_abspath,
desc->my_abspath,
desc->their_abspath,
options, pool));
return svn_diff_file_output_merge3(output, diff,
desc->base_abspath,
desc->my_abspath,
desc->their_abspath,
_("||||||| ORIGINAL"),
_("<<<<<<< MINE (select with 'mc')"),
_(">>>>>>> THEIRS (select with 'tc')"),
"=======",
svn_diff_conflict_display_only_conflicts,
cancel_func,
cancel_baton,
pool);
}
static svn_error_t *
merge_prop_conflict(svn_stream_t *output,
const svn_wc_conflict_description2_t *desc,
const char *merged_abspath,
svn_cancel_func_t cancel_func,
void *cancel_baton,
apr_pool_t *pool)
{
const char *base_abspath = desc->base_abspath;
const char *my_abspath = desc->my_abspath;
const char *their_abspath = desc->their_abspath;
svn_diff_file_options_t *options = svn_diff_file_options_create(pool);
svn_diff_t *diff;
if (! base_abspath || ! my_abspath || ! their_abspath)
{
const char *empty_file;
SVN_ERR(svn_io_open_unique_file3(NULL, &empty_file,
NULL, svn_io_file_del_on_pool_cleanup,
pool, pool));
if (! base_abspath)
base_abspath = empty_file;
if (! my_abspath)
my_abspath = empty_file;
if (! their_abspath)
their_abspath = empty_file;
}
options->ignore_eol_style = TRUE;
SVN_ERR(svn_diff_file_diff3_2(&diff,
base_abspath,
merged_abspath ? merged_abspath : my_abspath,
their_abspath,
options, pool));
SVN_ERR(svn_diff_file_output_merge3(output, diff,
base_abspath,
merged_abspath ? merged_abspath
: my_abspath,
their_abspath,
_("||||||| ORIGINAL"),
_("<<<<<<< MINE"),
_(">>>>>>> THEIRS"),
"=======",
svn_diff_conflict_display_modified_original_latest,
cancel_func,
cancel_baton,
pool));
return SVN_NO_ERROR;
}
static svn_error_t *
show_prop_conflict(const svn_wc_conflict_description2_t *desc,
const char *merged_abspath,
svn_cancel_func_t cancel_func,
void *cancel_baton,
apr_pool_t *pool)
{
svn_stream_t *output;
SVN_ERR(svn_stream_for_stdout(&output, pool));
SVN_ERR(merge_prop_conflict(output, desc, merged_abspath,
cancel_func, cancel_baton, pool));
return SVN_NO_ERROR;
}
static svn_error_t *
open_editor(svn_boolean_t *performed_edit,
const char *merged_file,
svn_cl__interactive_conflict_baton_t *b,
apr_pool_t *pool)
{
svn_error_t *err;
if (merged_file)
{
err = svn_cmdline__edit_file_externally(merged_file, b->editor_cmd,
b->config, pool);
if (err && (err->apr_err == SVN_ERR_CL_NO_EXTERNAL_EDITOR ||
err->apr_err == SVN_ERR_EXTERNAL_PROGRAM))
{
char buf[1024];
const char *message;
message = svn_err_best_message(err, buf, sizeof(buf));
SVN_ERR(svn_cmdline_fprintf(stderr, pool, "%s\n", message));
svn_error_clear(err);
}
else if (err)
return svn_error_trace(err);
else
*performed_edit = TRUE;
}
else
SVN_ERR(svn_cmdline_fprintf(stderr, pool,
_("Invalid option; there's no "
"merged version to edit.\n\n")));
return SVN_NO_ERROR;
}
static svn_error_t *
edit_prop_conflict(const char **merged_file_path,
const svn_wc_conflict_description2_t *desc,
svn_cl__interactive_conflict_baton_t *b,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
apr_file_t *file;
const char *file_path;
svn_boolean_t performed_edit = FALSE;
svn_stream_t *merged_prop;
SVN_ERR(svn_io_open_unique_file3(&file, &file_path, NULL,
svn_io_file_del_on_pool_cleanup,
result_pool, scratch_pool));
merged_prop = svn_stream_from_aprfile2(file, TRUE ,
scratch_pool);
SVN_ERR(merge_prop_conflict(merged_prop, desc, NULL,
b->pb->cancel_func,
b->pb->cancel_baton,
scratch_pool));
SVN_ERR(svn_stream_close(merged_prop));
SVN_ERR(svn_io_file_flush(file, scratch_pool));
SVN_ERR(open_editor(&performed_edit, file_path, b, scratch_pool));
*merged_file_path = (performed_edit ? file_path : NULL);
return SVN_NO_ERROR;
}
#define MAX_PROMPT_WIDTH 70
typedef struct resolver_option_t
{
const char *code;
const char *short_desc;
const char *long_desc;
svn_wc_conflict_choice_t choice;
} resolver_option_t;
static const resolver_option_t text_conflict_options[] =
{
{ "e", N_("edit file"), N_("change merged file in an editor"
" [edit]"),
svn_wc_conflict_choose_undefined },
{ "df", N_("show diff"), N_("show all changes made to merged file"),
svn_wc_conflict_choose_undefined },
{ "r", N_("mark resolved"), N_("accept merged version of file [working]"),
svn_wc_conflict_choose_merged },
{ "", "", "", svn_wc_conflict_choose_unspecified },
{ "dc", N_("display conflict"), N_("show all conflicts "
"(ignoring merged version)"),
svn_wc_conflict_choose_undefined },
{ "mc", N_("my side of conflict"), N_("accept my version for all conflicts "
"(same) [mine-conflict]"),
svn_wc_conflict_choose_mine_conflict },
{ "tc", N_("their side of conflict"), N_("accept their version for all "
"conflicts (same)"
" [theirs-conflict]"),
svn_wc_conflict_choose_theirs_conflict },
{ "", "", "", svn_wc_conflict_choose_unspecified },
{ "mf", N_("my version"), N_("accept my version of entire file (even "
"non-conflicts) [mine-full]"),
svn_wc_conflict_choose_mine_full },
{ "tf", N_("their version"), N_("accept their version of entire file "
"(same) [theirs-full]"),
svn_wc_conflict_choose_theirs_full },
{ "", "", "", svn_wc_conflict_choose_unspecified },
{ "m", N_("merge"), N_("use merge tool to resolve conflict"),
svn_wc_conflict_choose_undefined },
{ "l", N_("launch tool"), N_("launch external merge tool to resolve "
"conflict [launch]"),
svn_wc_conflict_choose_undefined },
{ "i", N_("internal merge tool"), N_("use built-in merge tool to "
"resolve conflict"),
svn_wc_conflict_choose_undefined },
{ "p", N_("postpone"), N_("mark the conflict to be resolved later"
" [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "s", N_("show all options"), N_("show this list (also 'h', '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t binary_conflict_options[] =
{
{ "r", N_("mark resolved"), N_("accept the working copy version of file "
" [working]"),
svn_wc_conflict_choose_merged },
{ "tf", N_("their version"), N_("accept the incoming version of file "
" [theirs-full]"),
svn_wc_conflict_choose_theirs_full },
{ "p", N_("postpone"), N_("mark the conflict to be resolved later "
" [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "s", N_("show all options"), N_("show this list (also 'h', '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t prop_conflict_options[] =
{
{ "mf", N_("my version"), N_("accept my version of entire property (even "
"non-conflicts) [mine-full]"),
svn_wc_conflict_choose_mine_full },
{ "tf", N_("their version"), N_("accept their version of entire property "
"(same) [theirs-full]"),
svn_wc_conflict_choose_theirs_full },
{ "dc", N_("display conflict"), N_("show conflicts in this property"),
svn_wc_conflict_choose_undefined },
{ "e", N_("edit property"), N_("change merged property value in an editor"
" [edit]"),
svn_wc_conflict_choose_undefined },
{ "r", N_("mark resolved"), N_("accept edited version of property"),
svn_wc_conflict_choose_merged },
{ "p", N_("postpone"), N_("mark the conflict to be resolved later"
" [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "h", N_("help"), N_("show this help (also '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t tree_conflict_options[] =
{
{ "r", N_("mark resolved"), N_("accept current working copy state"),
svn_wc_conflict_choose_merged },
{ "p", N_("postpone"), N_("resolve the conflict later [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "h", N_("help"), N_("show this help (also '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t tree_conflict_options_update_moved_away[] =
{
{ "mc", N_("apply update to move destination (recommended)"),
N_("apply incoming update to move destination"
" [mine-conflict]"),
svn_wc_conflict_choose_mine_conflict },
{ "p", N_("postpone"), N_("resolve the conflict later [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "h", N_("help"), N_("show this help (also '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t tree_conflict_options_update_edit_deleted_dir[] =
{
{ "mc", N_("prepare for updating moved-away children, if any (recommended)"),
N_("allow updating moved-away children "
"with 'svn resolve' [mine-conflict]"),
svn_wc_conflict_choose_mine_conflict },
{ "p", N_("postpone"), N_("resolve the conflict later [postpone]"),
svn_wc_conflict_choose_postpone },
{ "q", N_("quit resolution"), N_("postpone all remaining conflicts"),
svn_wc_conflict_choose_postpone },
{ "h", N_("help"), N_("show this help (also '?')"),
svn_wc_conflict_choose_undefined },
{ NULL }
};
static const resolver_option_t *
find_option(const resolver_option_t *options,
const char *option_code)
{
const resolver_option_t *opt;
for (opt = options; opt->code; opt++)
{
if (opt->code[0] && strcmp(opt->code, option_code) == 0)
return opt;
}
return NULL;
}
static const char *
prompt_string(const resolver_option_t *options,
const char *const *option_codes,
apr_pool_t *pool)
{
const char *result = _("Select:");
int left_margin = svn_utf_cstring_utf8_width(result);
const char *line_sep = apr_psprintf(pool, "\n%*s", left_margin, "");
int this_line_len = left_margin;
svn_boolean_t first = TRUE;
while (1)
{
const resolver_option_t *opt;
const char *s;
int slen;
if (option_codes)
{
if (! *option_codes)
break;
opt = find_option(options, *option_codes++);
}
else
{
opt = options++;
if (! opt->code)
break;
}
if (! first)
result = apr_pstrcat(pool, result, ",", SVN_VA_NULL);
s = apr_psprintf(pool, _(" (%s) %s"),
opt->code, _(opt->short_desc));
slen = svn_utf_cstring_utf8_width(s);
if (this_line_len + slen > MAX_PROMPT_WIDTH)
{
result = apr_pstrcat(pool, result, line_sep, SVN_VA_NULL);
this_line_len = left_margin;
}
result = apr_pstrcat(pool, result, s, SVN_VA_NULL);
this_line_len += slen;
first = FALSE;
}
return apr_pstrcat(pool, result, ": ", SVN_VA_NULL);
}
static const char *
help_string(const resolver_option_t *options,
apr_pool_t *pool)
{
const char *result = "";
const resolver_option_t *opt;
for (opt = options; opt->code; opt++)
{
if (opt->code[0])
{
const char *s = apr_psprintf(pool, " (%s)", opt->code);
result = apr_psprintf(pool, "%s%-6s - %s\n",
result, s, _(opt->long_desc));
}
else
{
result = apr_pstrcat(pool, result, "\n", SVN_VA_NULL);
}
}
result = apr_pstrcat(pool, result,
_("Words in square brackets are the corresponding "
"--accept option arguments.\n"),
SVN_VA_NULL);
return result;
}
static svn_error_t *
prompt_user(const resolver_option_t **opt,
const resolver_option_t *conflict_options,
const char *const *options_to_show,
void *prompt_baton,
apr_pool_t *scratch_pool)
{
const char *prompt
= prompt_string(conflict_options, options_to_show, scratch_pool);
const char *answer;
SVN_ERR(svn_cmdline_prompt_user2(&answer, prompt, prompt_baton, scratch_pool));
if (strcmp(answer, "h") == 0 || strcmp(answer, "?") == 0)
{
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool, "\n%s\n",
help_string(conflict_options,
scratch_pool)));
*opt = NULL;
}
else
{
*opt = find_option(conflict_options, answer);
if (! *opt)
{
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool,
_("Unrecognized option.\n\n")));
}
}
return SVN_NO_ERROR;
}
static svn_error_t *
handle_text_conflict(svn_wc_conflict_result_t *result,
const svn_wc_conflict_description2_t *desc,
svn_cl__interactive_conflict_baton_t *b,
apr_pool_t *scratch_pool)
{
apr_pool_t *iterpool = svn_pool_create(scratch_pool);
svn_boolean_t diff_allowed = FALSE;
svn_boolean_t performed_edit = FALSE;
svn_boolean_t knows_something = FALSE;
const char *local_relpath;
SVN_ERR_ASSERT(desc->kind == svn_wc_conflict_kind_text);
local_relpath = svn_cl__local_style_skip_ancestor(b->path_prefix,
desc->local_abspath,
scratch_pool);;
if (desc->is_binary)
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool,
_("Conflict discovered in binary file '%s'.\n"),
local_relpath));
else
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool,
_("Conflict discovered in file '%s'.\n"),
local_relpath));
if (!desc->is_binary &&
((desc->merged_file && desc->base_abspath)
|| (!desc->base_abspath && desc->my_abspath && desc->their_abspath)))
diff_allowed = TRUE;
while (TRUE)
{
const char *options[1 + MAX_ARRAY_LEN(binary_conflict_options,
text_conflict_options)];
const resolver_option_t *conflict_options = desc->is_binary
? binary_conflict_options
: text_conflict_options;
const char **next_option = options;
const resolver_option_t *opt;
svn_pool_clear(iterpool);
*next_option++ = "p";
if (diff_allowed)
{
if (desc->my_abspath)
*next_option++ = "df";
*next_option++ = "e";
if (desc->my_abspath)
*next_option++ = "m";
if (knows_something)
*next_option++ = "r";
*next_option++ = "mc";
*next_option++ = "tc";
}
else
{
if (knows_something || desc->is_binary)
*next_option++ = "r";
if (desc->my_abspath)
*next_option++ = "mf";
*next_option++ = "tf";
}
*next_option++ = "s";
*next_option++ = NULL;
SVN_ERR(prompt_user(&opt, conflict_options, options, b->pb, iterpool));
if (! opt)
continue;
if (strcmp(opt->code, "q") == 0)
{
result->choice = opt->choice;
b->accept_which = svn_cl__accept_postpone;
b->quit = TRUE;
break;
}
else if (strcmp(opt->code, "s") == 0)
{
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool, "\n%s\n",
help_string(conflict_options,
iterpool)));
}
else if (strcmp(opt->code, "dc") == 0)
{
if (desc->is_binary)
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; cannot "
"display conflicts for a "
"binary file.\n\n")));
continue;
}
else if (! (desc->my_abspath && desc->base_abspath &&
desc->their_abspath))
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; original "
"files not available.\n\n")));
continue;
}
SVN_ERR(show_conflicts(desc,
b->pb->cancel_func,
b->pb->cancel_baton,
iterpool));
knows_something = TRUE;
}
else if (strcmp(opt->code, "df") == 0)
{
if (! diff_allowed || ! desc->my_abspath)
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; there's no "
"merged version to diff.\n\n")));
continue;
}
SVN_ERR(show_diff(desc, b->path_prefix,
b->pb->cancel_func, b->pb->cancel_baton,
iterpool));
knows_something = TRUE;
}
else if (strcmp(opt->code, "e") == 0 || strcmp(opt->code, ":-E") == 0)
{
SVN_ERR(open_editor(&performed_edit, desc->merged_file, b, iterpool));
if (performed_edit)
knows_something = TRUE;
}
else if (strcmp(opt->code, "m") == 0 || strcmp(opt->code, ":-g") == 0 ||
strcmp(opt->code, "=>-") == 0 || strcmp(opt->code, ":>.") == 0)
{
svn_error_t *err;
if (! desc->my_abspath)
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; there's no "
"base path to merge.\n\n")));
continue;
}
err = svn_cl__merge_file_externally(desc->base_abspath,
desc->their_abspath,
desc->my_abspath,
desc->merged_file,
desc->local_abspath, b->config,
NULL, iterpool);
if (err)
{
if (err->apr_err == SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL)
{
svn_boolean_t remains_in_conflict = TRUE;
svn_error_clear(err);
SVN_ERR(svn_cl__merge_file(&remains_in_conflict,
desc->base_abspath,
desc->their_abspath,
desc->my_abspath,
desc->merged_file,
desc->local_abspath,
b->path_prefix,
b->editor_cmd,
b->config,
b->pb->cancel_func,
b->pb->cancel_baton,
iterpool));
knows_something = !remains_in_conflict;
}
else if (err->apr_err == SVN_ERR_EXTERNAL_PROGRAM)
{
char buf[1024];
const char *message;
message = svn_err_best_message(err, buf, sizeof(buf));
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
"%s\n", message));
svn_error_clear(err);
continue;
}
else
return svn_error_trace(err);
}
else
{
performed_edit = TRUE;
knows_something = TRUE;
}
}
else if (strcmp(opt->code, "l") == 0 || strcmp(opt->code, ":-l") == 0)
{
if (desc->base_abspath && desc->their_abspath &&
desc->my_abspath && desc->merged_file)
{
svn_error_t *err;
char buf[1024];
const char *message;
err = svn_cl__merge_file_externally(desc->base_abspath,
desc->their_abspath,
desc->my_abspath,
desc->merged_file,
desc->local_abspath,
b->config, NULL, iterpool);
if (err && (err->apr_err == SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL ||
err->apr_err == SVN_ERR_EXTERNAL_PROGRAM))
{
message = svn_err_best_message(err, buf, sizeof(buf));
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool, "%s\n",
message));
svn_error_clear(err);
}
else if (err)
return svn_error_trace(err);
else
performed_edit = TRUE;
if (performed_edit)
knows_something = TRUE;
}
else
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option.\n\n")));
}
else if (strcmp(opt->code, "i") == 0)
{
svn_boolean_t remains_in_conflict = TRUE;
SVN_ERR(svn_cl__merge_file(&remains_in_conflict,
desc->base_abspath,
desc->their_abspath,
desc->my_abspath,
desc->merged_file,
desc->local_abspath,
b->path_prefix,
b->editor_cmd,
b->config,
b->pb->cancel_func,
b->pb->cancel_baton,
iterpool));
if (!remains_in_conflict)
knows_something = TRUE;
}
else if (opt->choice != svn_wc_conflict_choose_undefined)
{
if ((opt->choice == svn_wc_conflict_choose_mine_conflict
|| opt->choice == svn_wc_conflict_choose_theirs_conflict)
&& desc->is_binary)
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; cannot choose "
"based on conflicts in a "
"binary file.\n\n")));
continue;
}
if (opt->choice == svn_wc_conflict_choose_merged
&& ! knows_something && diff_allowed)
{
SVN_ERR(svn_cmdline_fprintf(
stderr, iterpool,
_("Invalid option; use diff/edit/merge/launch "
"before choosing 'mark resolved'.\n\n")));
continue;
}
result->choice = opt->choice;
if (performed_edit)
result->save_merged = TRUE;
break;
}
}
svn_pool_destroy(iterpool);
return SVN_NO_ERROR;
}
static svn_error_t *
handle_prop_conflict(svn_wc_conflict_result_t *result,
const svn_wc_conflict_description2_t *desc,
svn_cl__interactive_conflict_baton_t *b,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
apr_pool_t *iterpool;
const char *message;
const char *merged_file_path = NULL;
svn_boolean_t resolved_allowed = FALSE;
((svn_wc_conflict_description2_t *)desc)->their_abspath = desc->merged_file;
((svn_wc_conflict_description2_t *)desc)->merged_file = NULL;
SVN_ERR_ASSERT(desc->kind == svn_wc_conflict_kind_property);
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool,
_("Conflict for property '%s' discovered"
" on '%s'.\n"),
desc->property_name,
svn_cl__local_style_skip_ancestor(
b->path_prefix, desc->local_abspath,
scratch_pool)));
SVN_ERR(svn_cl__get_human_readable_prop_conflict_description(&message, desc,
scratch_pool));
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool, "%s\n", message));
iterpool = svn_pool_create(scratch_pool);
while (TRUE)
{
const resolver_option_t *opt;
const char *options[ARRAY_LEN(prop_conflict_options)];
const char **next_option = options;
*next_option++ = "p";
*next_option++ = "mf";
*next_option++ = "tf";
*next_option++ = "dc";
*next_option++ = "e";
if (resolved_allowed)
*next_option++ = "r";
*next_option++ = "q";
*next_option++ = "h";
*next_option++ = NULL;
svn_pool_clear(iterpool);
SVN_ERR(prompt_user(&opt, prop_conflict_options, options, b->pb,
iterpool));
if (! opt)
continue;
if (strcmp(opt->code, "q") == 0)
{
result->choice = opt->choice;
b->accept_which = svn_cl__accept_postpone;
b->quit = TRUE;
break;
}
else if (strcmp(opt->code, "dc") == 0)
{
SVN_ERR(show_prop_conflict(desc, merged_file_path,
b->pb->cancel_func, b->pb->cancel_baton,
scratch_pool));
}
else if (strcmp(opt->code, "e") == 0)
{
SVN_ERR(edit_prop_conflict(&merged_file_path, desc, b,
result_pool, scratch_pool));
resolved_allowed = (merged_file_path != NULL);
}
else if (strcmp(opt->code, "r") == 0)
{
if (! resolved_allowed)
{
SVN_ERR(svn_cmdline_fprintf(stderr, iterpool,
_("Invalid option; please edit the property "
"first.\n\n")));
continue;
}
result->merged_file = merged_file_path;
result->choice = svn_wc_conflict_choose_merged;
break;
}
else if (opt->choice != svn_wc_conflict_choose_undefined)
{
result->choice = opt->choice;
break;
}
}
svn_pool_destroy(iterpool);
return SVN_NO_ERROR;
}
static svn_error_t *
handle_tree_conflict(svn_wc_conflict_result_t *result,
const svn_wc_conflict_description2_t *desc,
svn_cl__interactive_conflict_baton_t *b,
apr_pool_t *scratch_pool)
{
const char *readable_desc;
apr_pool_t *iterpool;
SVN_ERR(svn_cl__get_human_readable_tree_conflict_description(
&readable_desc, desc, scratch_pool));
SVN_ERR(svn_cmdline_fprintf(
stderr, scratch_pool,
_("Tree conflict on '%s'\n > %s\n"),
svn_cl__local_style_skip_ancestor(b->path_prefix,
desc->local_abspath,
scratch_pool),
readable_desc));
iterpool = svn_pool_create(scratch_pool);
while (1)
{
const resolver_option_t *opt;
const resolver_option_t *tc_opts;
svn_pool_clear(iterpool);
tc_opts = tree_conflict_options;
if (desc->operation == svn_wc_operation_update ||
desc->operation == svn_wc_operation_switch)
{
if (desc->reason == svn_wc_conflict_reason_moved_away)
{
tc_opts = tree_conflict_options_update_moved_away;
}
else if (desc->reason == svn_wc_conflict_reason_deleted ||
desc->reason == svn_wc_conflict_reason_replaced)
{
if (desc->action == svn_wc_conflict_action_edit &&
desc->node_kind == svn_node_dir)
tc_opts = tree_conflict_options_update_edit_deleted_dir;
}
}
SVN_ERR(prompt_user(&opt, tc_opts, NULL, b->pb, iterpool));
if (! opt)
continue;
if (strcmp(opt->code, "q") == 0)
{
result->choice = opt->choice;
b->accept_which = svn_cl__accept_postpone;
b->quit = TRUE;
break;
}
else if (opt->choice != svn_wc_conflict_choose_undefined)
{
result->choice = opt->choice;
break;
}
}
svn_pool_destroy(iterpool);
return SVN_NO_ERROR;
}
static svn_error_t *
conflict_func_interactive(svn_wc_conflict_result_t **result,
const svn_wc_conflict_description2_t *desc,
void *baton,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
svn_cl__interactive_conflict_baton_t *b = baton;
svn_error_t *err;
*result = svn_wc_create_conflict_result(svn_wc_conflict_choose_postpone,
NULL, result_pool);
switch (b->accept_which)
{
case svn_cl__accept_invalid:
case svn_cl__accept_unspecified:
break;
case svn_cl__accept_postpone:
(*result)->choice = svn_wc_conflict_choose_postpone;
return SVN_NO_ERROR;
case svn_cl__accept_base:
(*result)->choice = svn_wc_conflict_choose_base;
return SVN_NO_ERROR;
case svn_cl__accept_working:
if (! desc->merged_file)
(*result)->merged_file = desc->my_abspath;
(*result)->choice = svn_wc_conflict_choose_merged;
return SVN_NO_ERROR;
case svn_cl__accept_mine_conflict:
(*result)->choice = svn_wc_conflict_choose_mine_conflict;
return SVN_NO_ERROR;
case svn_cl__accept_theirs_conflict:
(*result)->choice = svn_wc_conflict_choose_theirs_conflict;
return SVN_NO_ERROR;
case svn_cl__accept_mine_full:
(*result)->choice = svn_wc_conflict_choose_mine_full;
return SVN_NO_ERROR;
case svn_cl__accept_theirs_full:
(*result)->choice = svn_wc_conflict_choose_theirs_full;
return SVN_NO_ERROR;
case svn_cl__accept_edit:
if (desc->merged_file)
{
if (b->external_failed)
{
(*result)->choice = svn_wc_conflict_choose_postpone;
return SVN_NO_ERROR;
}
err = svn_cmdline__edit_file_externally(desc->merged_file,
b->editor_cmd, b->config,
scratch_pool);
if (err && (err->apr_err == SVN_ERR_CL_NO_EXTERNAL_EDITOR ||
err->apr_err == SVN_ERR_EXTERNAL_PROGRAM))
{
char buf[1024];
const char *message;
message = svn_err_best_message(err, buf, sizeof(buf));
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool, "%s\n",
message));
svn_error_clear(err);
b->external_failed = TRUE;
}
else if (err)
return svn_error_trace(err);
(*result)->choice = svn_wc_conflict_choose_merged;
return SVN_NO_ERROR;
}
break;
case svn_cl__accept_launch:
if (desc->base_abspath && desc->their_abspath
&& desc->my_abspath && desc->merged_file)
{
svn_boolean_t remains_in_conflict;
if (b->external_failed)
{
(*result)->choice = svn_wc_conflict_choose_postpone;
return SVN_NO_ERROR;
}
err = svn_cl__merge_file_externally(desc->base_abspath,
desc->their_abspath,
desc->my_abspath,
desc->merged_file,
desc->local_abspath,
b->config,
&remains_in_conflict,
scratch_pool);
if (err && (err->apr_err == SVN_ERR_CL_NO_EXTERNAL_MERGE_TOOL ||
err->apr_err == SVN_ERR_EXTERNAL_PROGRAM))
{
char buf[1024];
const char *message;
message = svn_err_best_message(err, buf, sizeof(buf));
SVN_ERR(svn_cmdline_fprintf(stderr, scratch_pool, "%s\n",
message));
b->external_failed = TRUE;
return svn_error_trace(err);
}
else if (err)
return svn_error_trace(err);
if (remains_in_conflict)
(*result)->choice = svn_wc_conflict_choose_postpone;
else
(*result)->choice = svn_wc_conflict_choose_merged;
return SVN_NO_ERROR;
}
break;
}
if (! b->printed_summary)
{
SVN_ERR(svn_cl__print_conflict_stats(b->conflict_stats, scratch_pool));
b->printed_summary = TRUE;
}
if (((desc->kind == svn_wc_conflict_kind_text)
&& (desc->action == svn_wc_conflict_action_edit)
&& (desc->reason == svn_wc_conflict_reason_edited)))
SVN_ERR(handle_text_conflict(*result, desc, b, scratch_pool));
else if (desc->kind == svn_wc_conflict_kind_property)
SVN_ERR(handle_prop_conflict(*result, desc, b, result_pool, scratch_pool));
else if (desc->kind == svn_wc_conflict_kind_tree)
SVN_ERR(handle_tree_conflict(*result, desc, b, scratch_pool));
else
{
(*result)->choice = svn_wc_conflict_choose_postpone;
}
return SVN_NO_ERROR;
}
svn_error_t *
svn_cl__conflict_func_interactive(svn_wc_conflict_result_t **result,
const svn_wc_conflict_description2_t *desc,
void *baton,
apr_pool_t *result_pool,
apr_pool_t *scratch_pool)
{
svn_cl__interactive_conflict_baton_t *b = baton;
SVN_ERR(conflict_func_interactive(result, desc, baton,
result_pool, scratch_pool));
if ((*result)->choice != svn_wc_conflict_choose_postpone)
{
const char *local_path
= svn_cl__local_style_skip_ancestor(
b->path_prefix, desc->local_abspath, scratch_pool);
svn_cl__conflict_stats_resolved(b->conflict_stats, local_path,
desc->kind);
}
return SVN_NO_ERROR;
}