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. This was cherry-picked from the fix in 'master' Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Oct 31, 2007 at 14:55 UTC
acef41c9db33f2261e46e17cca098df3403dd745
7 files changed
+23
-9
builtin-branch.c
+1
-1
@@ -276,7 +276,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
276
if (commit && !parse_commit(commit)) {
277
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
278
&subject, &subject_len, 0,
279
- NULL, NULL, 0);
279
+ NULL, NULL, 0, 0);
280
sub = subject;
281
}
282
printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),
builtin-log.c
+1
-1
@@ -795,7 +795,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
795
char *buf = NULL;
796
unsigned long buflen = 0;
797
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
798
- &buf, &buflen, 0, NULL, NULL, 0);
798
+ &buf, &buflen, 0, NULL, NULL, 0, 0);
799
printf("%c %s %s\n", sign,
800
sha1_to_hex(commit->object.sha1), buf);
801
free(buf);
builtin-rev-list.c
+1
-1
@@ -84,7 +84,7 @@ static void show_commit(struct commit *commit)
84
unsigned long buflen = 0;
85
pretty_print_commit(revs.commit_format, commit, ~0,
86
&buf, &buflen,
87
- revs.abbrev, NULL, NULL, revs.date_mode);
87
+ revs.abbrev, NULL, NULL, revs.date_mode, 0);
88
printf("%s%c", buf, hdr_termination);
89
free(buf);
90
}
builtin-show-branch.c
+1
-1
@@ -267,7 +267,7 @@ static void show_one_commit(struct commit *commit, int no_name)
267
if (commit->object.parsed) {
268
pretty_print_commit(CMIT_FMT_ONELINE, commit, ~0,
269
&pretty, &pretty_len,
270
- 0, NULL, NULL, 0);
270
+ 0, NULL, NULL, 0, 0);
271
pretty_str = pretty;
272
}
273
if (!prefixcmp(pretty_str, "[PATCH] "))
commit.c
+3
-3
@@ -479,7 +479,7 @@ static int get_one_line(const char *msg, unsigned long len)
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));
@@ -1158,13 +1158,13 @@ unsigned long pretty_print_commit(enum cmit_fmt fmt,
1158
char **buf_p, unsigned long *space_p,
1159
int abbrev, const char *subject,
1160
const char *after_subject,
1161
- enum date_mode dmode)
1161
+ enum date_mode dmode,
1162
+ int plain_non_ascii)
1163
{
1164
unsigned long offset = 0;
1165
unsigned long beginning_of_body;
1166
int indent = 4;
1167
const char *msg = commit->buffer;
1167
- int plain_non_ascii = 0;
1168
char *reencoded;
1169
const char *encoding;
1170
char *buf;
commit.h
+2
-1
@@ -60,8 +60,9 @@ enum cmit_fmt {
60
CMIT_FMT_UNSPECIFIED,
61
};
62
63
+extern int non_ascii(int);
64
extern enum cmit_fmt get_commit_format(const char *arg);
64
-extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char **buf_p, unsigned long *space_p, int abbrev, const char *subject, const char *after_subject, enum date_mode dmode);
65
+extern unsigned long pretty_print_commit(enum cmit_fmt fmt, const struct commit *, unsigned long len, char **buf_p, unsigned long *space_p, int abbrev, const char *subject, const char *after_subject, enum date_mode dmode, int non_ascii_present);
66
67
/** Removes the first commit from a list sorted by date, and adds all
68
* of its parents.
log-tree.c
+14
-1
@@ -140,6 +140,18 @@ static unsigned int digits_in_number(unsigned int number)
140
return result;
141
}
142
143
+static int has_non_ascii(const char *s)
144
+{
145
+ int ch;
146
+ if (!s)
147
+ return 0;
148
+ while ((ch = *s++) != '\0') {
149
+ if (non_ascii(ch))
150
+ return 1;
151
+ }
152
+ return 0;
153
+}
154
+
155
void show_log(struct rev_info *opt, const char *sep)
156
{
157
char *msgbuf = NULL;
@@ -290,7 +302,8 @@ void show_log(struct rev_info *opt, const char *sep)
302
*/
303
len = pretty_print_commit(opt->commit_format, commit, ~0u,
304
&msgbuf, &msgbuf_len, abbrev, subject,
293
- extra_headers, opt->date_mode);
305
+ extra_headers, opt->date_mode,
306
+ has_non_ascii(opt->add_signoff));
307
308
if (opt->add_signoff)
309
len = append_signoff(&msgbuf, &msgbuf_len, len,