Skip to content

Commit d2e49d2

Browse files
committed
Merge branch 'jc/merge-compact-summary'
"git merge/pull" has been taught the "--compact-summary" option to use the compact-summary format, intead of diffstat, when showing the summary of the incoming changes. * jc/merge-compact-summary: merge/pull: extend merge.stat configuration variable to cover --compact-summary merge/pull: add the "--compact-summary" option
2 parents 91f10d7 + c8b4805 commit d2e49d2

File tree

6 files changed

+154
-8
lines changed

6 files changed

+154
-8
lines changed

Documentation/config/merge.adoc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,18 @@ as `false`. Defaults to `conflict`.
8181
attributes" in linkgit:gitattributes[5].
8282

8383
`merge.stat`::
84-
Whether to print the diffstat between `ORIG_HEAD` and the merge result
85-
at the end of the merge. True by default.
84+
What, if anything, to print between `ORIG_HEAD` and the merge result
85+
at the end of the merge. Possible values are:
86+
+
87+
--
88+
`false`;; Show nothing.
89+
`true`;; Show `git diff --diffstat --summary ORIG_HEAD`.
90+
`compact`;; Show `git diff --compact-summary ORIG_HEAD`.
91+
--
92+
+
93+
but any unrecognised value (e.g., a value added by a future version of
94+
Git) is taken as `true` instead of triggering an error. Defaults to
95+
`true`.
8696

8797
`merge.autoStash`::
8898
When set to `true`, automatically create a temporary stash entry

Documentation/git-merge.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git-merge - Join two or more development histories together
99
SYNOPSIS
1010
--------
1111
[synopsis]
12-
git merge [-n] [--stat] [--no-commit] [--squash] [--[no-]edit]
12+
git merge [-n] [--stat] [--compact-summary] [--no-commit] [--squash] [--[no-]edit]
1313
[--no-verify] [-s <strategy>] [-X <strategy-option>] [-S[<keyid>]]
1414
[--[no-]allow-unrelated-histories]
1515
[--[no-]rerere-autoupdate] [-m <msg>] [-F <file>]

Documentation/merge-options.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ include::signoff-option.adoc[]
113113
With `-n` or `--no-stat` do not show a diffstat at the end of the
114114
merge.
115115

116+
`--compact-summary`::
117+
Show a compact-summary at the end of the merge.
118+
116119
`--squash`::
117120
`--no-squash`::
118121
Produce the working tree and index state as if a real merge

builtin/merge.c

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ static const char * const builtin_merge_usage[] = {
6969
NULL
7070
};
7171

72-
static int show_diffstat = 1, shortlog_len = -1, squash;
72+
#define MERGE_SHOW_DIFFSTAT 1
73+
#define MERGE_SHOW_COMPACTSUMMARY 2
74+
75+
static int show_diffstat = MERGE_SHOW_DIFFSTAT, shortlog_len = -1, squash;
7376
static int option_commit = -1;
7477
static int option_edit = -1;
7578
static int allow_trivial = 1, have_message, verify_signatures;
@@ -243,12 +246,28 @@ static int option_parse_strategy(const struct option *opt UNUSED,
243246
return 0;
244247
}
245248

249+
static int option_parse_compact_summary(const struct option *opt,
250+
const char *name UNUSED, int unset)
251+
{
252+
int *setting = opt->value;
253+
254+
if (unset)
255+
*setting = 0;
256+
else
257+
*setting = MERGE_SHOW_COMPACTSUMMARY;
258+
return 0;
259+
}
260+
246261
static struct option builtin_merge_options[] = {
247262
OPT_SET_INT('n', NULL, &show_diffstat,
248263
N_("do not show a diffstat at the end of the merge"), 0),
249264
OPT_BOOL(0, "stat", &show_diffstat,
250265
N_("show a diffstat at the end of the merge")),
251266
OPT_BOOL(0, "summary", &show_diffstat, N_("(synonym to --stat)")),
267+
OPT_CALLBACK_F(0, "compact-summary", &show_diffstat, N_("compact-summary"),
268+
N_("show a compact-summary at the end of the merge"),
269+
PARSE_OPT_NOARG,
270+
option_parse_compact_summary),
252271
{
253272
.type = OPTION_INTEGER,
254273
.long_name = "log",
@@ -494,8 +513,19 @@ static void finish(struct commit *head_commit,
494513
struct diff_options opts;
495514
repo_diff_setup(the_repository, &opts);
496515
init_diffstat_widths(&opts);
497-
opts.output_format |=
498-
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
516+
517+
switch (show_diffstat) {
518+
case MERGE_SHOW_DIFFSTAT: /* 1 */
519+
opts.output_format |=
520+
DIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;
521+
break;
522+
case MERGE_SHOW_COMPACTSUMMARY: /* 2 */
523+
opts.output_format |= DIFF_FORMAT_DIFFSTAT;
524+
opts.flags.stat_with_summary = 1;
525+
break;
526+
default:
527+
break;
528+
}
499529
opts.detect_rename = DIFF_DETECT_RENAME;
500530
diff_setup_done(&opts);
501531
diff_tree_oid(head, new_head, "", &opts);
@@ -643,7 +673,35 @@ static int git_merge_config(const char *k, const char *v,
643673
}
644674

645675
if (!strcmp(k, "merge.diffstat") || !strcmp(k, "merge.stat")) {
646-
show_diffstat = git_config_bool(k, v);
676+
int val = git_parse_maybe_bool_text(v);
677+
switch (val) {
678+
case 0:
679+
show_diffstat = 0;
680+
break;
681+
case 1:
682+
show_diffstat = MERGE_SHOW_DIFFSTAT;
683+
break;
684+
default:
685+
if (!strcmp(v, "compact"))
686+
show_diffstat = MERGE_SHOW_COMPACTSUMMARY;
687+
/*
688+
* We do not need to have an explicit
689+
*
690+
* else if (!strcmp(v, "diffstat"))
691+
* show_diffstat = MERGE_SHOW_DIFFSTAT;
692+
*
693+
* here, because the catch-all uses the
694+
* diffstat style anyway.
695+
*/
696+
else
697+
/*
698+
* A setting from a future? It is not an
699+
* error grave enough to fail the command.
700+
* proceed using the default one.
701+
*/
702+
show_diffstat = MERGE_SHOW_DIFFSTAT;
703+
break;
704+
}
647705
} else if (!strcmp(k, "merge.verifysignatures")) {
648706
verify_signatures = git_config_bool(k, v);
649707
} else if (!strcmp(k, "pull.twohead")) {

builtin/pull.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ static struct option pull_options[] = {
143143
OPT_PASSTHRU(0, "summary", &opt_diffstat, NULL,
144144
N_("(synonym to --stat)"),
145145
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
146+
OPT_PASSTHRU(0, "compact-summary", &opt_diffstat, NULL,
147+
N_("show a compact-summary at the end of the merge"),
148+
PARSE_OPT_NOARG),
146149
OPT_PASSTHRU(0, "log", &opt_log, N_("n"),
147150
N_("add (at most <n>) entries from shortlog to merge commit message"),
148151
PARSE_OPT_OPTARG),

t/t7600-merge.sh

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,19 @@ test_expect_success 'reject non-strategy with a git-merge-foo name' '
185185
test_expect_success 'merge c0 with c1' '
186186
echo "OBJID HEAD@{0}: merge c1: Fast-forward" >reflog.expected &&
187187
188+
cat >expect <<-\EOF &&
189+
Updating FROM..TO
190+
Fast-forward
191+
file | 2 +-
192+
other | 9 +++++++++
193+
2 files changed, 10 insertions(+), 1 deletion(-)
194+
create mode 100644 other
195+
EOF
196+
188197
git reset --hard c0 &&
189-
git merge c1 &&
198+
git merge c1 >out &&
199+
sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
200+
test_cmp expect actual &&
190201
verify_merge file result.1 &&
191202
verify_head "$c1" &&
192203
@@ -205,6 +216,67 @@ test_expect_success 'merge c0 with c1 with --ff-only' '
205216
verify_head "$c1"
206217
'
207218

219+
test_expect_success 'the same merge with merge.stat=diffstat' '
220+
cat >expect <<-\EOF &&
221+
Updating FROM..TO
222+
Fast-forward
223+
file | 2 +-
224+
other | 9 +++++++++
225+
2 files changed, 10 insertions(+), 1 deletion(-)
226+
create mode 100644 other
227+
EOF
228+
229+
git reset --hard c0 &&
230+
git -c merge.stat=diffstat merge c1 >out &&
231+
sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
232+
test_cmp expect actual
233+
'
234+
235+
test_expect_success 'the same merge with compact summary' '
236+
cat >expect <<-\EOF &&
237+
Updating FROM..TO
238+
Fast-forward
239+
file | 2 +-
240+
other (new) | 9 +++++++++
241+
2 files changed, 10 insertions(+), 1 deletion(-)
242+
EOF
243+
244+
git reset --hard c0 &&
245+
git merge --compact-summary c1 >out &&
246+
sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
247+
test_cmp expect actual
248+
'
249+
250+
test_expect_success 'the same merge with compact summary' '
251+
cat >expect <<-\EOF &&
252+
Updating FROM..TO
253+
Fast-forward
254+
file | 2 +-
255+
other (new) | 9 +++++++++
256+
2 files changed, 10 insertions(+), 1 deletion(-)
257+
EOF
258+
259+
git reset --hard c0 &&
260+
git merge --compact-summary c1 >out &&
261+
sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
262+
test_cmp expect actual
263+
'
264+
265+
test_expect_success 'the same merge with merge.stat=compact' '
266+
cat >expect <<-\EOF &&
267+
Updating FROM..TO
268+
Fast-forward
269+
file | 2 +-
270+
other (new) | 9 +++++++++
271+
2 files changed, 10 insertions(+), 1 deletion(-)
272+
EOF
273+
274+
git reset --hard c0 &&
275+
git -c merge.stat=compact merge c1 >out &&
276+
sed -e "1s/^Updating [0-9a-f.]*/Updating FROM..TO/" out >actual &&
277+
test_cmp expect actual
278+
'
279+
208280
test_debug 'git log --graph --decorate --oneline --all'
209281

210282
test_expect_success 'merge from unborn branch' '

0 commit comments

Comments
 (0)