diff-merges: let new options enable diff without -p

New options don't have any visible effect unless -p is either given or
implied, as unlike -c/-cc we don't imply -p with --diff-merges. To fix
this, this patch adds new functionality by letting new options enable
output of diffs for merge commits only.

Add 'merges_need_diff' field and set it whenever diff output for merges is
enabled by any of the new options.

Extend diff output logic accordingly, to output diffs for merges when
'merges_need_diff' is set even when no -p has been provided.

Signed-off-by: Sergey Organov <sorganov@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Sergey Organov
2020-12-21 18:19:53 +03:00
committed by Junio C Hamano
parent 5733b20f41
commit a6d19ecc6b
3 changed files with 22 additions and 9 deletions

View File

@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
int showed_log;
struct commit_list *parents;
struct object_id *oid;
int is_merge;
int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
if (!opt->diff && !opt->diffopt.flags.exit_with_status)
if (!all_need_diff && !opt->merges_need_diff)
return 0;
parse_commit_or_die(commit);
oid = get_commit_tree_oid(commit);
/* Root commit? */
parents = get_saved_parents(opt, commit);
is_merge = parents && parents->next;
if (!is_merge && !all_need_diff)
return 0;
/* Root commit? */
if (!parents) {
if (opt->show_root_diff) {
diff_root_tree_oid(oid, "", &opt->diffopt);
@ -916,8 +922,7 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
return !opt->loginfo;
}
/* More than one parent? */
if (parents->next) {
if (is_merge) {
if (opt->combine_merges)
return do_diff_combined(opt, commit);
if (opt->separate_merges) {