builtin-am: implement -u/--utf8
Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am.sh supported the -u,--utf8 option. If set, the -u option will be passed to git-mailinfo to re-code the commit log message and authorship in the charset specified by i18n.commitencoding. If unset, the -n option will be passed to git-mailinfo, which disables the re-encoding. Since d84029b (--utf8 is now default for 'git-am', 2007-01-08), --utf8 is specified by default in git-am.sh. Re-implement the above in builtin/am.c. Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paul Tan committed
Aug 4, 2015 at 21:51 UTC
ef7ee16d75855fb17578e3f29e33f17ba107aac1
1 file changed
+11
builtin/am.c
+11
@@ -90,6 +90,7 @@ struct am_state {
90
int threeway;
91
int quiet;
92
int signoff;
93
+ int utf8;
94
const char *resolvemsg;
95
int rebasing;
96
};
@@ -106,6 +107,8 @@ static void am_state_init(struct am_state *state, const char *dir)
107
state->dir = xstrdup(dir);
108
109
state->prec = 4;
110
+
111
+ state->utf8 = 1;
112
}
113
114
/**
@@ -367,6 +370,9 @@ static void am_load(struct am_state *state)
370
read_state_file(&sb, state, "sign", 1);
371
state->signoff = !strcmp(sb.buf, "t");
372
373
+ read_state_file(&sb, state, "utf8", 1);
374
+ state->utf8 = !strcmp(sb.buf, "t");
375
+
376
state->rebasing = !!file_exists(am_path(state, "rebasing"));
377
378
strbuf_release(&sb);
@@ -556,6 +562,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
562
563
write_file(am_path(state, "sign"), 1, state->signoff ? "t" : "f");
564
565
+ write_file(am_path(state, "utf8"), 1, state->utf8 ? "t" : "f");
566
+
567
if (state->rebasing)
568
write_file(am_path(state, "rebasing"), 1, "%s", "");
569
else
@@ -722,6 +730,7 @@ static int parse_mail(struct am_state *state, const char *mail)
730
cp.out = xopen(am_path(state, "info"), O_WRONLY | O_CREAT, 0777);
731
732
argv_array_push(&cp.args, "mailinfo");
733
+ argv_array_push(&cp.args, state->utf8 ? "-u" : "-n");
734
argv_array_push(&cp.args, am_path(state, "msg"));
735
argv_array_push(&cp.args, am_path(state, "patch"));
736
@@ -1460,6 +1469,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1469
OPT__QUIET(&state.quiet, N_("be quiet")),
1470
OPT_BOOL('s', "signoff", &state.signoff,
1471
N_("add a Signed-off-by line to the commit message")),
1472
+ OPT_BOOL('u', "utf8", &state.utf8,
1473
+ N_("recode into utf8 (default)")),
1474
OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
1475
N_("format the patch(es) are in"),
1476
parse_opt_patchformat),