diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index 45c7bd5a8ff8723ec3478a33fbca4216a5b465fa..564e8091ba5ce6788ad97c2109b14afd6d235c83 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -57,6 +57,11 @@ format.suffix:: `.patch`. Use this variable to change that suffix (make sure to include the dot if you want it). +format.encodeEmailHeaders:: + Encode email headers that have non-ASCII characters with + "Q-encoding" (described in RFC 2047) for email transmission. + Defaults to true. + format.pretty:: The default pretty format for log/show/whatchanged command, See linkgit:git-log[1], linkgit:git-show[1], diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 0d4f8951bbb1d1df0ebba15d2619d5a39568469d..0f81d0437bb65bd0ee68ef63edf7bb48d9ea87a6 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -24,6 +24,7 @@ SYNOPSIS [(--reroll-count|-v) ] [--to=] [--cc=] [--[no-]cover-letter] [--quiet] + [--[no-]encode-email-headers] [--no-notes | --notes[=]] [--interdiff=] [--range-diff= [--creation-factor=]] @@ -253,6 +254,13 @@ feeding the result to `git send-email`. containing the branch description, shortlog and the overall diffstat. You can fill in a description in the file before sending it out. +--encode-email-headers:: +--no-encode-email-headers:: + Encode email headers that have non-ASCII characters with + "Q-encoding" (described in RFC 2047), instead of outputting the + headers verbatim. Defaults to the value of the + `format.encodeEmailHeaders` configuration variable. + --interdiff=:: As a reviewer aid, insert an interdiff into the cover letter, or as commentary of the lone patch of a 1-patch series, showing diff --git a/builtin/log.c b/builtin/log.c index 83a4a6188e221caefc5028e59cb7c95c2f1d1e0c..a5c3ace9a0f68912c63f57dc4152d2f9c4f819e8 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -46,6 +46,7 @@ static int default_abbrev_commit; static int default_show_root = 1; static int default_follow; static int default_show_signature; +static int default_encode_email_headers = 1; static int decoration_style; static int decoration_given; static int use_mailmap_config = 1; @@ -151,6 +152,7 @@ static void cmd_log_init_defaults(struct rev_info *rev) rev->show_root_diff = default_show_root; rev->subject_prefix = fmt_patch_subject_prefix; rev->show_signature = default_show_signature; + rev->encode_email_headers = default_encode_email_headers; rev->diffopt.flags.allow_textconv = 1; if (default_date_mode) @@ -438,6 +440,10 @@ static int git_log_config(const char *var, const char *value, void *cb) return git_config_string(&fmt_pretty, var, value); if (!strcmp(var, "format.subjectprefix")) return git_config_string(&fmt_patch_subject_prefix, var, value); + if (!strcmp(var, "format.encodeemailheaders")) { + default_encode_email_headers = git_config_bool(var, value); + return 0; + } if (!strcmp(var, "log.abbrevcommit")) { default_abbrev_commit = git_config_bool(var, value); return 0; @@ -1719,6 +1725,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.show_notes = show_notes; memcpy(&rev.notes_opt, ¬es_opt, sizeof(notes_opt)); rev.commit_format = CMIT_FMT_EMAIL; + rev.encode_email_headers = default_encode_email_headers; rev.expand_tabs_in_log_default = 0; rev.verbose_header = 1; rev.diff = 1; diff --git a/log-tree.c b/log-tree.c index 897a90233e470f5314fa5b6607875b74b139479d..0064788b252cadb98b71eec4d3517f92c88bba86 100644 --- a/log-tree.c +++ b/log-tree.c @@ -693,6 +693,7 @@ void show_log(struct rev_info *opt) ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; ctx.preserve_subject = opt->preserve_subject; + ctx.encode_email_headers = opt->encode_email_headers; ctx.reflog_info = opt->reflog_info; ctx.fmt = opt->commit_format; ctx.mailmap = opt->mailmap; diff --git a/pretty.c b/pretty.c index 28afc701b6a46d1aca84d7867549391d79a6ab68..2a3d46bf42fea1d375eb1b29e52ee1caaa0372a0 100644 --- a/pretty.c +++ b/pretty.c @@ -474,7 +474,8 @@ void pp_user_info(struct pretty_print_context *pp, } strbuf_addstr(sb, "From: "); - if (needs_rfc2047_encoding(namebuf, namelen)) { + if (pp->encode_email_headers && + needs_rfc2047_encoding(namebuf, namelen)) { add_rfc2047(sb, namebuf, namelen, encoding, RFC2047_ADDRESS); max_length = 76; /* per rfc2047 */ @@ -1767,7 +1768,8 @@ void pp_title_line(struct pretty_print_context *pp, if (pp->print_email_subject) { if (pp->rev) fmt_output_email_subject(sb, pp->rev); - if (needs_rfc2047_encoding(title.buf, title.len)) + if (pp->encode_email_headers && + needs_rfc2047_encoding(title.buf, title.len)) add_rfc2047(sb, title.buf, title.len, encoding, RFC2047_SUBJECT); else diff --git a/pretty.h b/pretty.h index 4ad1fc31ff33408881abf2ea5e28ab813d6c1f85..071f2fb8e449cee51c6556998b416c4fa7c8005a 100644 --- a/pretty.h +++ b/pretty.h @@ -43,6 +43,7 @@ struct pretty_print_context { struct string_list *mailmap; int color; struct ident_split *from_ident; + unsigned encode_email_headers:1; /* * Fields below here are manipulated internally by pp_* functions and diff --git a/revision.c b/revision.c index 8136929e23626e3bd9a8e9c6108fd2e32b2bd1cb..58f5826df0cce4c22e5813f3475d7d8a9b12bdb0 100644 --- a/revision.c +++ b/revision.c @@ -2241,6 +2241,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->topo_order = 1; revs->rewrite_parents = 1; revs->graph = graph_init(revs); + } else if (!strcmp(arg, "--encode-email-headers")) { + revs->encode_email_headers = 1; + } else if (!strcmp(arg, "--no-encode-email-headers")) { + revs->encode_email_headers = 0; } else if (!strcmp(arg, "--root")) { revs->show_root_diff = 1; } else if (!strcmp(arg, "--no-commit-id")) { diff --git a/revision.h b/revision.h index 475f048fb61185519b0010ee132d42b1b2c768f7..0f962e4e1724ac45567b4a46eae552f1cd28028b 100644 --- a/revision.h +++ b/revision.h @@ -203,7 +203,8 @@ struct rev_info { use_terminator:1, missing_newline:1, date_mode_explicit:1, - preserve_subject:1; + preserve_subject:1, + encode_email_headers:1; unsigned int disable_stdin:1; /* --show-linear-break */ unsigned int track_linear:1, diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index b653dd7d44521270995b456d7b8e2dcfd6957af5..db7e733af9e5be1abe8991e1513f9d31949433f4 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1160,6 +1160,59 @@ test_expect_success 'format-patch wraps extremely long from-header (rfc2047)' ' check_author "Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" ' +cat >expect <<'EOF' +From: Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar + Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo + Bar Foo Bar Foo Bar Foo Bar +EOF +test_expect_success 'format-patch wraps extremely long from-header (non-ASCII without Q-encoding)' ' + echo content >>file && + git add file && + GIT_AUTHOR_NAME="Foö Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar Foo Bar" \ + git commit -m author-check && + git format-patch --no-encode-email-headers --stdout -1 >patch && + sed -n "/^From: /p; /^ /p; /^$/q" patch >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +Subject: [PATCH] Foö +EOF +test_expect_success 'subject lines are unencoded with --no-encode-email-headers' ' + echo content >>file && + git add file && + git commit -m "Foö" && + git format-patch --no-encode-email-headers -1 --stdout >patch && + grep ^Subject: patch >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +Subject: [PATCH] Foö +EOF +test_expect_success 'subject lines are unencoded with format.encodeEmailHeaders=false' ' + echo content >>file && + git add file && + git commit -m "Foö" && + git config format.encodeEmailHeaders false && + git format-patch -1 --stdout >patch && + grep ^Subject: patch >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +Subject: [PATCH] =?UTF-8?q?Fo=C3=B6?= +EOF +test_expect_success '--encode-email-headers overrides format.encodeEmailHeaders' ' + echo content >>file && + git add file && + git commit -m "Foö" && + git config format.encodeEmailHeaders false && + git format-patch --encode-email-headers -1 --stdout >patch && + grep ^Subject: patch >actual && + test_cmp expect actual +' + cat >expect <<'EOF' Subject: header with . in it EOF