@matheusbsbs / matheus-bagliano / commits / 4593fb8405
Fork 0

format-patch -s: add MIME encoding header if signer's name requires so

When the body of the commit log message contains a non-ASCII character, format-patch correctly emitted the encoding header to mark the resulting message as such. However, if the original message was fully ASCII, the command line switch "-s" was given to add a new sign-off, and the signer's name was not ASCII only, the resulting message would have contained non-ASCII character but was not marked as such. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Oct 31, 2007 at 14:55 UTC 4593fb84051d39f65cec81958e91056986e4682f
7 files changed +24 -9
builtin-branch.c
+1 -1
@@ -276,7 +276,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
276 commit = lookup_commit(item->sha1);
277 if (commit && !parse_commit(commit)) {
278 pretty_print_commit(CMIT_FMT_ONELINE, commit,
279 - &subject, 0, NULL, NULL, 0);
279 + &subject, 0, NULL, NULL, 0, 0);
280 sub = subject.buf;
281 }
282 printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
builtin-log.c
+1 -1
@@ -787,7 +787,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
787 struct strbuf buf;
788 strbuf_init(&buf, 0);
789 pretty_print_commit(CMIT_FMT_ONELINE, commit,
790 - &buf, 0, NULL, NULL, 0);
790 + &buf, 0, NULL, NULL, 0, 0);
791 printf("%c %s %s\n", sign,
792 sha1_to_hex(commit->object.sha1), buf.buf);
793 strbuf_release(&buf);
builtin-rev-list.c
+2 -1
@@ -86,7 +86,8 @@ static void show_commit(struct commit *commit)
86 struct strbuf buf;
87 strbuf_init(&buf, 0);
88 pretty_print_commit(revs.commit_format, commit,
89 - &buf, revs.abbrev, NULL, NULL, revs.date_mode);
89 + &buf, revs.abbrev, NULL, NULL,
90 + revs.date_mode, 0);
91 if (buf.len)
92 printf("%s%c", buf.buf, hdr_termination);
93 strbuf_release(&buf);
builtin-show-branch.c
+1 -1
@@ -266,7 +266,7 @@ static void show_one_commit(struct commit *commit, int no_name)
266 strbuf_init(&pretty, 0);
267 if (commit->object.parsed) {
268 pretty_print_commit(CMIT_FMT_ONELINE, commit,
269 - &pretty, 0, NULL, NULL, 0);
269 + &pretty, 0, NULL, NULL, 0, 0);
270 pretty_str = pretty.buf;
271 }
272 if (!prefixcmp(pretty_str, "[PATCH] "))
commit.c
+2 -3
@@ -479,7 +479,7 @@ static int get_one_line(const char *msg)
479 }
480
481 /* High bit set, or ISO-2022-INT */
482 -static int non_ascii(int ch)
482 +int non_ascii(int ch)
483 {
484 ch = (ch & 0xff);
485 return ((ch & 0x80) || (ch == 0x1b));
@@ -1046,12 +1046,11 @@ static void pp_remainder(enum cmit_fmt fmt,
1046 void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
1047 struct strbuf *sb, int abbrev,
1048 const char *subject, const char *after_subject,
1049 - enum date_mode dmode)
1049 + enum date_mode dmode, int plain_non_ascii)
1050 {
1051 unsigned long beginning_of_body;
1052 int indent = 4;
1053 const char *msg = commit->buffer;
1054 - int plain_non_ascii = 0;
1054 char *reencoded;
1055 const char *encoding;
1056
commit.h
+3 -1
@@ -61,13 +61,15 @@ enum cmit_fmt {
61 CMIT_FMT_UNSPECIFIED,
62 };
63
64 +extern int non_ascii(int);
65 extern enum cmit_fmt get_commit_format(const char *arg);
66 extern void format_commit_message(const struct commit *commit,
67 const void *format, struct strbuf *sb);
68 extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
69 struct strbuf *,
70 int abbrev, const char *subject,
70 - const char *after_subject, enum date_mode);
71 + const char *after_subject, enum date_mode,
72 + int non_ascii_present);
73
74 /** Removes the first commit from a list sorted by date, and adds all
75 * of its parents.
log-tree.c
+14 -1
@@ -125,6 +125,18 @@ static unsigned int digits_in_number(unsigned int number)
125 return result;
126 }
127
128 +static int has_non_ascii(const char *s)
129 +{
130 + int ch;
131 + if (!s)
132 + return 0;
133 + while ((ch = *s++) != '\0') {
134 + if (non_ascii(ch))
135 + return 1;
136 + }
137 + return 0;
138 +}
139 +
140 void show_log(struct rev_info *opt, const char *sep)
141 {
142 struct strbuf msgbuf;
@@ -273,7 +285,8 @@ void show_log(struct rev_info *opt, const char *sep)
285 */
286 strbuf_init(&msgbuf, 0);
287 pretty_print_commit(opt->commit_format, commit, &msgbuf,
276 - abbrev, subject, extra_headers, opt->date_mode);
288 + abbrev, subject, extra_headers, opt->date_mode,
289 + has_non_ascii(opt->add_signoff));
290
291 if (opt->add_signoff)
292 append_signoff(&msgbuf, opt->add_signoff);