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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed May 26, 2011 at 18:28 UTC 9553d2b26395d9a19bf60875784661090f607f4a
6 files changed +8 -3
builtin/log.c
+1
@@ -1131,6 +1131,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1131 die ("-n and -k are mutually exclusive.");
1132 if (keep_subject && subject_prefix)
1133 die ("--subject-prefix and -k are mutually exclusive.");
1134 + rev.preserve_subject = keep_subject;
1135
1136 argc = setup_revisions(argc, argv, &rev, &s_r_opt);
1137 if (argc > 1)
commit.h
+1
@@ -74,6 +74,7 @@ struct pretty_print_context
74 int abbrev;
75 const char *subject;
76 const char *after_subject;
77 + int preserve_subject;
78 enum date_mode date_mode;
79 int need_8bit_cte;
80 int show_notes;
log-tree.c
+1
@@ -504,6 +504,7 @@ void show_log(struct rev_info *opt)
504 ctx.date_mode = opt->date_mode;
505 ctx.abbrev = opt->diffopt.abbrev;
506 ctx.after_subject = extra_headers;
507 + ctx.preserve_subject = opt->preserve_subject;
508 ctx.reflog_info = opt->reflog_info;
509 ctx.fmt = opt->commit_format;
510 pretty_print_commit(&ctx, commit, &msgbuf);
pretty.c
+2 -1
@@ -1131,7 +1131,8 @@ void pp_title_line(const struct pretty_print_context *pp,
1131 struct strbuf title;
1132
1133 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" : " ");
1136
1137 strbuf_grow(sb, title.len + 1024);
1138 if (pp->subject) {
revision.h
+2 -1
@@ -90,7 +90,8 @@ struct rev_info {
90 abbrev_commit:1,
91 use_terminator:1,
92 missing_newline:1,
93 - date_mode_explicit:1;
93 + date_mode_explicit:1,
94 + preserve_subject:1;
95 unsigned int disable_stdin:1;
96
97 enum date_mode date_mode;
t/t4152-am-subjects.sh
+1 -1
@@ -70,7 +70,7 @@ test_expect_success 'multiline subject unwrapped (format-patch -k | am)' '
70 check_subject multiline-k
71 '
72 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)' '
74 check_subject multiline-k -k
75 '
76