From 08353ebbab2dfdee50a6daa616ec8b6483cb07c8 Mon Sep 17 00:00:00 2001 From: Matthieu Moy Date: Wed, 11 Aug 2010 10:38:04 +0200 Subject: Turn unpack_trees_options.msgs into an array + enum The list of error messages was introduced as a structure, but an array indexed over an enum is more flexible, since it allows one to store a type of error message (index in the array) in a variable. This change needs to rename would_lose_untracked -> would_lose_untracked_file to avoid a clash with the function would_lose_untracked in merge-recursive.c. Signed-off-by: Matthieu Moy Signed-off-by: Junio C Hamano --- merge-recursive.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'merge-recursive.c') diff --git a/merge-recursive.c b/merge-recursive.c index fb6aa4a551..d3bd963890 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -185,7 +185,7 @@ static int git_merge_trees(int index_only, opts.fn = threeway_merge; opts.src_index = &the_index; opts.dst_index = &the_index; - opts.msgs = get_porcelain_error_msgs(); + set_porcelain_error_msgs(opts.msgs); init_tree_desc_from_tree(t+0, common); init_tree_desc_from_tree(t+1, head); @@ -1178,26 +1178,19 @@ static int process_entry(struct merge_options *o, return clean_merge; } -struct unpack_trees_error_msgs get_porcelain_error_msgs(void) +void set_porcelain_error_msgs(const char **msgs) { - struct unpack_trees_error_msgs msgs = { - /* would_overwrite */ - "Your local changes to '%s' would be overwritten by merge. Aborting.", - /* not_uptodate_file */ - "Your local changes to '%s' would be overwritten by merge. Aborting.", - /* not_uptodate_dir */ - "Updating '%s' would lose untracked files in it. Aborting.", - /* would_lose_untracked */ - "Untracked working tree file '%s' would be %s by merge. Aborting", - /* bind_overlap -- will not happen here */ - NULL, - }; - if (advice_commit_before_merge) { - msgs.would_overwrite = msgs.not_uptodate_file = + if (advice_commit_before_merge) + msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = "Your local changes to '%s' would be overwritten by merge. Aborting.\n" "Please, commit your changes or stash them before you can merge."; - } - return msgs; + else + msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = + "Your local changes to '%s' would be overwritten by merge. Aborting."; + msgs[ERROR_NOT_UPTODATE_DIR] = + "Updating '%s' would lose untracked files in it. Aborting."; + msgs[ERROR_WOULD_LOSE_UNTRACKED] = + "Untracked working tree file '%s' would be %s by merge. Aborting"; } int merge_trees(struct merge_options *o, -- cgit v1.2.3