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>
This commit is contained in:
parent
6bf139440c
commit
9553d2b263
@ -1131,6 +1131,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
|
|||||||
die ("-n and -k are mutually exclusive.");
|
die ("-n and -k are mutually exclusive.");
|
||||||
if (keep_subject && subject_prefix)
|
if (keep_subject && subject_prefix)
|
||||||
die ("--subject-prefix and -k are mutually exclusive.");
|
die ("--subject-prefix and -k are mutually exclusive.");
|
||||||
|
rev.preserve_subject = keep_subject;
|
||||||
|
|
||||||
argc = setup_revisions(argc, argv, &rev, &s_r_opt);
|
argc = setup_revisions(argc, argv, &rev, &s_r_opt);
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
|
1
commit.h
1
commit.h
@ -74,6 +74,7 @@ struct pretty_print_context
|
|||||||
int abbrev;
|
int abbrev;
|
||||||
const char *subject;
|
const char *subject;
|
||||||
const char *after_subject;
|
const char *after_subject;
|
||||||
|
int preserve_subject;
|
||||||
enum date_mode date_mode;
|
enum date_mode date_mode;
|
||||||
int need_8bit_cte;
|
int need_8bit_cte;
|
||||||
int show_notes;
|
int show_notes;
|
||||||
|
@ -504,6 +504,7 @@ void show_log(struct rev_info *opt)
|
|||||||
ctx.date_mode = opt->date_mode;
|
ctx.date_mode = opt->date_mode;
|
||||||
ctx.abbrev = opt->diffopt.abbrev;
|
ctx.abbrev = opt->diffopt.abbrev;
|
||||||
ctx.after_subject = extra_headers;
|
ctx.after_subject = extra_headers;
|
||||||
|
ctx.preserve_subject = opt->preserve_subject;
|
||||||
ctx.reflog_info = opt->reflog_info;
|
ctx.reflog_info = opt->reflog_info;
|
||||||
ctx.fmt = opt->commit_format;
|
ctx.fmt = opt->commit_format;
|
||||||
pretty_print_commit(&ctx, commit, &msgbuf);
|
pretty_print_commit(&ctx, commit, &msgbuf);
|
||||||
|
3
pretty.c
3
pretty.c
@ -1131,7 +1131,8 @@ void pp_title_line(const struct pretty_print_context *pp,
|
|||||||
struct strbuf title;
|
struct strbuf title;
|
||||||
|
|
||||||
strbuf_init(&title, 80);
|
strbuf_init(&title, 80);
|
||||||
*msg_p = format_subject(&title, *msg_p, " ");
|
*msg_p = format_subject(&title, *msg_p,
|
||||||
|
pp->preserve_subject ? "\n" : " ");
|
||||||
|
|
||||||
strbuf_grow(sb, title.len + 1024);
|
strbuf_grow(sb, title.len + 1024);
|
||||||
if (pp->subject) {
|
if (pp->subject) {
|
||||||
|
@ -90,7 +90,8 @@ struct rev_info {
|
|||||||
abbrev_commit:1,
|
abbrev_commit:1,
|
||||||
use_terminator:1,
|
use_terminator:1,
|
||||||
missing_newline:1,
|
missing_newline:1,
|
||||||
date_mode_explicit:1;
|
date_mode_explicit:1,
|
||||||
|
preserve_subject:1;
|
||||||
unsigned int disable_stdin:1;
|
unsigned int disable_stdin:1;
|
||||||
|
|
||||||
enum date_mode date_mode;
|
enum date_mode date_mode;
|
||||||
|
@ -70,7 +70,7 @@ test_expect_success 'multiline subject unwrapped (format-patch -k | am)' '
|
|||||||
check_subject multiline-k
|
check_subject multiline-k
|
||||||
'
|
'
|
||||||
echo "$MULTILINE_SUBJECT" >expect
|
echo "$MULTILINE_SUBJECT" >expect
|
||||||
test_expect_failure 'multiline subject preserved (format-patch -k | am -k)' '
|
test_expect_success 'multiline subject preserved (format-patch -k | am -k)' '
|
||||||
check_subject multiline-k -k
|
check_subject multiline-k -k
|
||||||
'
|
'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user