Skip to content

Commit 140dd77

Browse files
committed
Merge branch 'jc/format-patch-encoding'
* jc/format-patch-encoding: test format-patch -s: make sure MIME content type is shown as needed format-patch -s: add MIME encoding header if signer's name requires so
2 parents 02273fd + aacb8f1 commit 140dd77

File tree

8 files changed

+66
-9
lines changed

8 files changed

+66
-9
lines changed

builtin-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,
282282
commit = lookup_commit(item->sha1);
283283
if (commit && !parse_commit(commit)) {
284284
pretty_print_commit(CMIT_FMT_ONELINE, commit,
285-
&subject, 0, NULL, NULL, 0);
285+
&subject, 0, NULL, NULL, 0, 0);
286286
sub = subject.buf;
287287
}
288288
printf("%c %s%-*s%s %s %s\n", c, branch_get_color(color),

builtin-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
787787
struct strbuf buf;
788788
strbuf_init(&buf, 0);
789789
pretty_print_commit(CMIT_FMT_ONELINE, commit,
790-
&buf, 0, NULL, NULL, 0);
790+
&buf, 0, NULL, NULL, 0, 0);
791791
printf("%c %s %s\n", sign,
792792
sha1_to_hex(commit->object.sha1), buf.buf);
793793
strbuf_release(&buf);

builtin-rev-list.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ static void show_commit(struct commit *commit)
8686
struct strbuf buf;
8787
strbuf_init(&buf, 0);
8888
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);
9091
if (buf.len)
9192
printf("%s%c", buf.buf, hdr_termination);
9293
strbuf_release(&buf);

builtin-show-branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ static void show_one_commit(struct commit *commit, int no_name)
266266
strbuf_init(&pretty, 0);
267267
if (commit->object.parsed) {
268268
pretty_print_commit(CMIT_FMT_ONELINE, commit,
269-
&pretty, 0, NULL, NULL, 0);
269+
&pretty, 0, NULL, NULL, 0, 0);
270270
pretty_str = pretty.buf;
271271
}
272272
if (!prefixcmp(pretty_str, "[PATCH] "))

commit.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int get_one_line(const char *msg)
479479
}
480480

481481
/* High bit set, or ISO-2022-INT */
482-
static int non_ascii(int ch)
482+
int non_ascii(int ch)
483483
{
484484
ch = (ch & 0xff);
485485
return ((ch & 0x80) || (ch == 0x1b));
@@ -1046,12 +1046,11 @@ static void pp_remainder(enum cmit_fmt fmt,
10461046
void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
10471047
struct strbuf *sb, int abbrev,
10481048
const char *subject, const char *after_subject,
1049-
enum date_mode dmode)
1049+
enum date_mode dmode, int plain_non_ascii)
10501050
{
10511051
unsigned long beginning_of_body;
10521052
int indent = 4;
10531053
const char *msg = commit->buffer;
1054-
int plain_non_ascii = 0;
10551054
char *reencoded;
10561055
const char *encoding;
10571056

commit.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ enum cmit_fmt {
6161
CMIT_FMT_UNSPECIFIED,
6262
};
6363

64+
extern int non_ascii(int);
6465
extern enum cmit_fmt get_commit_format(const char *arg);
6566
extern void format_commit_message(const struct commit *commit,
6667
const void *format, struct strbuf *sb);
6768
extern void pretty_print_commit(enum cmit_fmt fmt, const struct commit*,
6869
struct strbuf *,
6970
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);
7173

7274
/** Removes the first commit from a list sorted by date, and adds all
7375
* of its parents.

log-tree.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ static unsigned int digits_in_number(unsigned int number)
125125
return result;
126126
}
127127

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+
128140
void show_log(struct rev_info *opt, const char *sep)
129141
{
130142
struct strbuf msgbuf;
@@ -273,7 +285,8 @@ void show_log(struct rev_info *opt, const char *sep)
273285
*/
274286
strbuf_init(&msgbuf, 0);
275287
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));
277290

278291
if (opt->add_signoff)
279292
append_signoff(&msgbuf, opt->add_signoff);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/sh
2+
3+
test_description='format-patch -s should force MIME encoding as needed'
4+
5+
. ./test-lib.sh
6+
7+
test_expect_success setup '
8+
9+
>F &&
10+
git add F &&
11+
git commit -m initial &&
12+
echo new line >F &&
13+
14+
test_tick &&
15+
git commit -m "This adds some lines to F" F
16+
17+
'
18+
19+
test_expect_success 'format normally' '
20+
21+
git format-patch --stdout -1 >output &&
22+
! grep Content-Type output
23+
24+
'
25+
26+
test_expect_success 'format with signoff without funny signer name' '
27+
28+
git format-patch -s --stdout -1 >output &&
29+
! grep Content-Type output
30+
31+
'
32+
33+
test_expect_success 'format with non ASCII signer name' '
34+
35+
GIT_COMMITTER_NAME="$B$O$^$N(B $B$U$K$*$&(B" \
36+
git format-patch -s --stdout -1 >output &&
37+
grep Content-Type output
38+
39+
'
40+
41+
test_done
42+

0 commit comments

Comments
 (0)