Skip to content

Commit a45e1a8

Browse files
rctaygitster
authored andcommitted
commit::print_summary(): don't use format_commit_message()
This attempts to fix a regression in git-commit, where non-abbreviated SHA-1s were printed in the summary. One possible fix would be to set ctx.abbrev to DEFAULT_ABBREV in the `if` block, where format_commit_message() is used. Instead, we do away with the format_commit_message() codeblock altogether, replacing it with a re-run of log_tree_commit(). We re-run log_tree_commit() with rev.always_show_header set, to force the invocation of show_log(). The effect of this flag can be seen from this excerpt from log-tree.c:560, the only area that rev.always_show_header is checked: shown = log_tree_diff(opt, commit, &log); if (!shown && opt->loginfo && opt->always_show_header) { log.parent = NULL; show_log(opt); shown = 1; } We also set rev.use_terminator, so that a newline is appended at the end of the log message. Note that callers in builtin/log.c that also set rev.always_show_header don't have to set rev.use_terminator, but still get a newline, because they are wrapped in a pager. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cee9f2b commit a45e1a8

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

builtin-commit.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,13 +1136,11 @@ static void print_summary(const char *prefix, const unsigned char *sha1)
11361136
initial_commit ? " (root-commit)" : "");
11371137

11381138
if (!log_tree_commit(&rev, commit)) {
1139-
struct pretty_print_context ctx = {0};
1140-
struct strbuf buf = STRBUF_INIT;
1141-
ctx.date_mode = DATE_NORMAL;
1142-
format_commit_message(commit, format.buf + 7, &buf, &ctx);
1143-
printf("%s\n", buf.buf);
1144-
strbuf_release(&buf);
1139+
rev.always_show_header = 1;
1140+
rev.use_terminator = 1;
1141+
log_tree_commit(&rev, commit);
11451142
}
1143+
11461144
strbuf_release(&format);
11471145
}
11481146

t/t7502-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ test_expect_success 'output summary format' '
3636
check_summary_oneline "" "a change"
3737
'
3838

39-
test_expect_failure 'output summary format for commit with an empty diff' '
39+
test_expect_success 'output summary format for commit with an empty diff' '
4040
4141
check_summary_oneline "" "empty" "--allow-empty"
4242
'
4343

44-
test_expect_failure 'output summary format for merges' '
44+
test_expect_success 'output summary format for merges' '
4545
4646
git checkout -b recursive-base &&
4747
test_commit base file1 &&

0 commit comments

Comments
 (0)