Skip to content

Commit a6d19ec

Browse files
sorganovgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5733b20 commit a6d19ec

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

diff-merges.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ static void suppress(struct rev_info *revs)
1010
revs->dense_combined_merges = 0;
1111
revs->combined_all_paths = 0;
1212
revs->combined_imply_patch = 0;
13+
revs->merges_need_diff = 0;
1314
}
1415

1516
static void set_separate(struct rev_info *revs)
@@ -51,9 +52,13 @@ static void set_dense_combined(struct rev_info *revs)
5152

5253
static void set_diff_merges(struct rev_info *revs, const char *optarg)
5354
{
54-
if (!strcmp(optarg, "off") || !strcmp(optarg, "none"))
55+
if (!strcmp(optarg, "off") || !strcmp(optarg, "none")) {
5556
suppress(revs);
56-
else if (!strcmp(optarg, "first-parent"))
57+
/* Return early to leave revs->merges_need_diff unset */
58+
return;
59+
}
60+
61+
if (!strcmp(optarg, "first-parent"))
5762
set_first_parent(revs);
5863
else if (!strcmp(optarg, "separate"))
5964
set_separate(revs);
@@ -63,6 +68,9 @@ static void set_diff_merges(struct rev_info *revs, const char *optarg)
6368
set_dense_combined(revs);
6469
else
6570
die(_("unknown value for --diff-merges: %s"), optarg);
71+
72+
/* The flag is cleared by set_xxx() functions, so don't move this up */
73+
revs->merges_need_diff = 1;
6674
}
6775

6876
/*
@@ -129,10 +137,9 @@ void diff_merges_setup_revs(struct rev_info *revs)
129137
revs->first_parent_merges = 0;
130138
if (revs->combined_all_paths && !revs->combine_merges)
131139
die("--combined-all-paths makes no sense without -c or --cc");
132-
if (revs->combine_merges)
140+
if (revs->combined_imply_patch)
133141
revs->diff = 1;
134-
if (revs->combined_imply_patch) {
135-
/* Turn --cc/-c into -p --cc/-c when -p was not given */
142+
if (revs->combined_imply_patch || revs->merges_need_diff) {
136143
if (!revs->diffopt.output_format)
137144
revs->diffopt.output_format = DIFF_FORMAT_PATCH;
138145
}

log-tree.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,15 +899,21 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
899899
int showed_log;
900900
struct commit_list *parents;
901901
struct object_id *oid;
902+
int is_merge;
903+
int all_need_diff = opt->diff || opt->diffopt.flags.exit_with_status;
902904

903-
if (!opt->diff && !opt->diffopt.flags.exit_with_status)
905+
if (!all_need_diff && !opt->merges_need_diff)
904906
return 0;
905907

906908
parse_commit_or_die(commit);
907909
oid = get_commit_tree_oid(commit);
908910

909-
/* Root commit? */
910911
parents = get_saved_parents(opt, commit);
912+
is_merge = parents && parents->next;
913+
if (!is_merge && !all_need_diff)
914+
return 0;
915+
916+
/* Root commit? */
911917
if (!parents) {
912918
if (opt->show_root_diff) {
913919
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
916922
return !opt->loginfo;
917923
}
918924

919-
/* More than one parent? */
920-
if (parents->next) {
925+
if (is_merge) {
921926
if (opt->combine_merges)
922927
return do_diff_combined(opt, commit);
923928
if (opt->separate_merges) {

revision.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct rev_info {
194194
always_show_header:1,
195195
/* Diff-merge flags */
196196
explicit_diff_merges: 1,
197+
merges_need_diff: 1,
197198
separate_merges: 1,
198199
combine_merges:1,
199200
combined_all_paths:1,

0 commit comments

Comments
 (0)