merge-recursive: give callers of handle_content_merge() access to contents

Pass a merge_file_info struct to handle_content_merge() so that the callers can access the oid and mode of the result afterward. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 5, 2019 at 08:00 UTC e62d11239cad847d1c55684f6c4ba939adc8e053
1 file changed +20 -17
merge-recursive.c
+20 -17
@@ -2982,7 +2982,8 @@ static int handle_modify_delete(struct merge_options *opt,
2982 _("modify"), _("modified"));
2983 }
2984
2985 -static int handle_content_merge(struct merge_options *opt,
2985 +static int handle_content_merge(struct merge_file_info *mfi,
2986 + struct merge_options *opt,
2987 const char *path,
2988 int is_dirty,
2989 const struct diff_filespec *o,
@@ -2991,7 +2992,6 @@ static int handle_content_merge(struct merge_options *opt,
2992 struct rename_conflict_info *ci)
2993 {
2994 const char *reason = _("content");
2994 - struct merge_file_info mfi;
2995 unsigned df_conflict_remains = 0;
2996
2997 if (!is_valid(o))
@@ -3004,7 +3004,7 @@ static int handle_content_merge(struct merge_options *opt,
3004
3005 if (merge_mode_and_contents(opt, o, a, b, path,
3006 opt->branch1, opt->branch2,
3007 - opt->call_depth * 2, &mfi))
3007 + opt->call_depth * 2, mfi))
3008 return -1;
3009
3010 /*
@@ -3013,13 +3013,13 @@ static int handle_content_merge(struct merge_options *opt,
3013 * b) The merge matches what was in HEAD (content, mode, pathname)
3014 * c) The target path is usable (i.e. not involved in D/F conflict)
3015 */
3016 - if (mfi.clean && was_tracked_and_matches(opt, path, &mfi.blob) &&
3016 + if (mfi->clean && was_tracked_and_matches(opt, path, &mfi->blob) &&
3017 !df_conflict_remains) {
3018 int pos;
3019 struct cache_entry *ce;
3020
3021 output(opt, 3, _("Skipped %s (merged same as existing)"), path);
3022 - if (add_cacheinfo(opt, &mfi.blob, path,
3022 + if (add_cacheinfo(opt, &mfi->blob, path,
3023 0, (!opt->call_depth && !is_dirty), 0))
3024 return -1;
3025 /*
@@ -3035,11 +3035,11 @@ static int handle_content_merge(struct merge_options *opt,
3035 ce = opt->repo->index->cache[pos];
3036 ce->ce_flags |= CE_SKIP_WORKTREE;
3037 }
3038 - return mfi.clean;
3038 + return mfi->clean;
3039 }
3040
3041 - if (!mfi.clean) {
3042 - if (S_ISGITLINK(mfi.blob.mode))
3041 + if (!mfi->clean) {
3042 + if (S_ISGITLINK(mfi->blob.mode))
3043 reason = _("submodule");
3044 output(opt, 1, _("CONFLICT (%s): Merge conflict in %s"),
3045 reason, path);
@@ -3053,15 +3053,15 @@ static int handle_content_merge(struct merge_options *opt,
3053 if (opt->call_depth) {
3054 remove_file_from_index(opt->repo->index, path);
3055 } else {
3056 - if (!mfi.clean) {
3056 + if (!mfi->clean) {
3057 if (update_stages(opt, path, o, a, b))
3058 return -1;
3059 } else {
3060 int file_from_stage2 = was_tracked(opt, path);
3061
3062 if (update_stages(opt, path, NULL,
3063 - file_from_stage2 ? &mfi.blob : NULL,
3064 - file_from_stage2 ? NULL : &mfi.blob))
3063 + file_from_stage2 ? &mfi->blob : NULL,
3064 + file_from_stage2 ? NULL : &mfi->blob))
3065 return -1;
3066 }
3067
@@ -3072,15 +3072,15 @@ static int handle_content_merge(struct merge_options *opt,
3072 path);
3073 }
3074 output(opt, 1, _("Adding as %s instead"), new_path);
3075 - if (update_file(opt, 0, &mfi.blob, new_path)) {
3075 + if (update_file(opt, 0, &mfi->blob, new_path)) {
3076 free(new_path);
3077 return -1;
3078 }
3079 free(new_path);
3080 - mfi.clean = 0;
3081 - } else if (update_file(opt, mfi.clean, &mfi.blob, path))
3080 + mfi->clean = 0;
3081 + } else if (update_file(opt, mfi->clean, &mfi->blob, path))
3082 return -1;
3083 - return !is_dirty && mfi.clean;
3083 + return !is_dirty && mfi->clean;
3084 }
3085
3086 static int handle_rename_normal(struct merge_options *opt,
@@ -3091,7 +3091,8 @@ static int handle_rename_normal(struct merge_options *opt,
3091 struct rename_conflict_info *ci)
3092 {
3093 /* Merge the content and write it out */
3094 - return handle_content_merge(opt, path, was_dirty(opt, path),
3094 + struct merge_file_info mfi;
3095 + return handle_content_merge(&mfi, opt, path, was_dirty(opt, path),
3096 o, a, b, ci);
3097 }
3098
@@ -3256,8 +3257,10 @@ static int process_entry(struct merge_options *opt,
3257 a, b);
3258 } else {
3259 /* case D: Modified in both, but differently. */
3260 + struct merge_file_info mfi;
3261 int is_dirty = 0; /* unpack_trees would have bailed if dirty */
3260 - clean_merge = handle_content_merge(opt, path, is_dirty,
3262 + clean_merge = handle_content_merge(&mfi, opt, path,
3263 + is_dirty,
3264 o, a, b, NULL);
3265 }
3266 } else if (!o_valid && !a_valid && !b_valid) {