builtin-am: implement -s/--signoff

Since d1c5f2a (Add git-am, applymbox replacement., 2005-10-07), git-am supported the --signoff option which will append a signoff at the end of the commit messsage. Re-implement this feature in parse_mail() by calling append_signoff() if the option is set. 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 eb898b83f2417b99f290459884f6ea8d2db2bd4d
1 file changed +12
builtin/am.c
+12
@@ -18,6 +18,7 @@
18 #include "diffcore.h"
19 #include "unpack-trees.h"
20 #include "branch.h"
21 +#include "sequencer.h"
22
23 /**
24 * Returns 1 if the file is empty or does not exist, 0 otherwise.
@@ -83,6 +84,7 @@ struct am_state {
84
85 /* various operating modes and command line options */
86 int quiet;
87 + int signoff;
88 const char *resolvemsg;
89 };
90
@@ -353,6 +355,9 @@ static void am_load(struct am_state *state)
355 read_state_file(&sb, state, "quiet", 1);
356 state->quiet = !strcmp(sb.buf, "t");
357
358 + read_state_file(&sb, state, "sign", 1);
359 + state->signoff = !strcmp(sb.buf, "t");
360 +
361 strbuf_release(&sb);
362 }
363
@@ -533,6 +538,8 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,
538
539 write_file(am_path(state, "quiet"), 1, state->quiet ? "t" : "f");
540
541 + write_file(am_path(state, "sign"), 1, state->signoff ? "t" : "f");
542 +
543 if (!get_sha1("HEAD", curr_head)) {
544 write_file(am_path(state, "abort-safety"), 1, "%s", sha1_to_hex(curr_head));
545 update_ref("am", "ORIG_HEAD", curr_head, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
@@ -734,6 +741,9 @@ static int parse_mail(struct am_state *state, const char *mail)
741 die_errno(_("could not read '%s'"), am_path(state, "msg"));
742 stripspace(&msg, 0);
743
744 + if (state->signoff)
745 + append_signoff(&msg, 0, 0);
746 +
747 assert(!state->author_name);
748 state->author_name = strbuf_detach(&author_name, NULL);
749
@@ -1150,6 +1160,8 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1160
1161 struct option options[] = {
1162 OPT__QUIET(&state.quiet, N_("be quiet")),
1163 + OPT_BOOL('s', "signoff", &state.signoff,
1164 + N_("add a Signed-off-by line to the commit message")),
1165 OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
1166 N_("format the patch(es) are in"),
1167 parse_opt_patchformat),