Skip to content

Commit 9553d2b

Browse files
peffgitster
authored andcommitted
format-patch: preserve subject newlines with -k
In older versions of git, we used rfc822 header folding to indicate that the original subject line had multiple lines in it. But since a1f6baa (format-patch: wrap long header lines, 2011-02-23), we now use header folding whenever there is a long line. This means that "git am" cannot trust header folding as a sign from format-patch that newlines should be preserved. Instead, format-patch needs to signal more explicitly that the newlines are significant. This patch does so by rfc2047-encoding the newlines in the subject line. No changes are needed on the "git am" end; it already decodes the newlines properly. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6bf1394 commit 9553d2b

File tree

6 files changed

+8
-3
lines changed

6 files changed

+8
-3
lines changed

builtin/log.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
11311131
die ("-n and -k are mutually exclusive.");
11321132
if (keep_subject && subject_prefix)
11331133
die ("--subject-prefix and -k are mutually exclusive.");
1134+
rev.preserve_subject = keep_subject;
11341135

11351136
argc = setup_revisions(argc, argv, &rev, &s_r_opt);
11361137
if (argc > 1)

commit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ struct pretty_print_context
7474
int abbrev;
7575
const char *subject;
7676
const char *after_subject;
77+
int preserve_subject;
7778
enum date_mode date_mode;
7879
int need_8bit_cte;
7980
int show_notes;

log-tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ void show_log(struct rev_info *opt)
504504
ctx.date_mode = opt->date_mode;
505505
ctx.abbrev = opt->diffopt.abbrev;
506506
ctx.after_subject = extra_headers;
507+
ctx.preserve_subject = opt->preserve_subject;
507508
ctx.reflog_info = opt->reflog_info;
508509
ctx.fmt = opt->commit_format;
509510
pretty_print_commit(&ctx, commit, &msgbuf);

pretty.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,8 @@ void pp_title_line(const struct pretty_print_context *pp,
11311131
struct strbuf title;
11321132

11331133
strbuf_init(&title, 80);
1134-
*msg_p = format_subject(&title, *msg_p, " ");
1134+
*msg_p = format_subject(&title, *msg_p,
1135+
pp->preserve_subject ? "\n" : " ");
11351136

11361137
strbuf_grow(sb, title.len + 1024);
11371138
if (pp->subject) {

revision.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ struct rev_info {
9090
abbrev_commit:1,
9191
use_terminator:1,
9292
missing_newline:1,
93-
date_mode_explicit:1;
93+
date_mode_explicit:1,
94+
preserve_subject:1;
9495
unsigned int disable_stdin:1;
9596

9697
enum date_mode date_mode;

t/t4152-am-subjects.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ test_expect_success 'multiline subject unwrapped (format-patch -k | am)' '
7070
check_subject multiline-k
7171
'
7272
echo "$MULTILINE_SUBJECT" >expect
73-
test_expect_failure 'multiline subject preserved (format-patch -k | am -k)' '
73+
test_expect_success 'multiline subject preserved (format-patch -k | am -k)' '
7474
check_subject multiline-k -k
7575
'
7676

0 commit comments

Comments
 (0)