Skip to content

Commit 965f803

Browse files
author
Junio C Hamano
committed
combine-diff: show diffstat with the first parent.
Asking for stat (either with --stat or --patch-with-stat) gives you diffstat for the first parent, even under combine-diff. While the combined patch is useful to highlight the complexity and interaction of the parts touched by all branches when reviewing a merge commit, diffstat is a tool to assess the extent of damage the merge brings in, and showing stat with the first parent is more sensible than clever per-parent diffstat. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent b073f26 commit 965f803

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

combine-diff.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -831,10 +831,11 @@ void show_combined_diff(struct combine_diff_path *p,
831831
case DIFF_FORMAT_NAME:
832832
show_raw_diff(p, num_parent, rev);
833833
return;
834-
835-
default:
836834
case DIFF_FORMAT_PATCH:
837835
show_patch_diff(p, num_parent, dense, rev);
836+
return;
837+
default:
838+
return;
838839
}
839840
}
840841

@@ -847,10 +848,13 @@ void diff_tree_combined_merge(const unsigned char *sha1,
847848
struct commit_list *parents;
848849
struct combine_diff_path *p, *paths = NULL;
849850
int num_parent, i, num_paths;
851+
int do_diffstat;
850852

853+
do_diffstat = (opt->output_format == DIFF_FORMAT_DIFFSTAT ||
854+
opt->with_stat);
851855
diffopts = *opt;
852-
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
853856
diffopts.with_raw = 0;
857+
diffopts.with_stat = 0;
854858
diffopts.recursive = 1;
855859

856860
/* count parents */
@@ -864,14 +868,24 @@ void diff_tree_combined_merge(const unsigned char *sha1,
864868
parents;
865869
parents = parents->next, i++) {
866870
struct commit *parent = parents->item;
871+
/* show stat against the first parent even
872+
* when doing combined diff.
873+
*/
874+
if (i == 0 && do_diffstat)
875+
diffopts.output_format = DIFF_FORMAT_DIFFSTAT;
876+
else
877+
diffopts.output_format = DIFF_FORMAT_NO_OUTPUT;
867878
diff_tree_sha1(parent->object.sha1, commit->object.sha1, "",
868879
&diffopts);
869880
diffcore_std(&diffopts);
870881
paths = intersect_paths(paths, i, num_parent);
871882

872-
if (diffopts.with_stat && rev->loginfo)
873-
show_log(rev, rev->loginfo, "---\n");
883+
if (do_diffstat && rev->loginfo)
884+
show_log(rev, rev->loginfo,
885+
opt->with_stat ? "---\n" : "\n");
874886
diff_flush(&diffopts);
887+
if (opt->with_stat)
888+
putchar('\n');
875889
}
876890

877891
/* find out surviving paths */

0 commit comments

Comments
 (0)