Re: [PATCH v4 31/44] builtin-am: implement -S/--gpg-sign, commit.gpgsign
From: Stefan Beller <hidden>
Date: 2016-06-15 23:05:35
On Sun, Jun 28, 2015 at 7:05 AM, Paul Tan [off-list ref] wrote:
quoted hunk ↗ jump to hunk
Since 3b4e395 (am: add the --gpg-sign option, 2014-02-01), git-am.sh supported the --gpg-sign option, and would pass it to git-commit-tree, thus GPG-signing the commit object. Re-implement this option in builtin/am.c. git-commit-tree would also sign the commit by default if the commit.gpgsign setting is true. Since we do not run commit-tree, we re-implement this behavior by handling the commit.gpgsign setting ourselves. Signed-off-by: Paul Tan <redacted> --- builtin/am.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)diff --git a/builtin/am.c b/builtin/am.c index 80850e8..d44f5e2 100644 --- a/builtin/am.c +++ b/builtin/am.c@@ -124,6 +124,8 @@ struct am_state { int ignore_date; + const char *sign_commit; + int rebasing; };@@ -134,6 +136,7 @@ struct am_state { static void am_state_init(struct am_state *state, const char *dir) { const char *quiet; + int sign_commit;
I needed to read this patch a few times as this patch introduces `sign_commit` twice. This is mostly a review problem I'd guess as in the code it just affects this method and you'd see all the code of the method easily compared to hunks sent via email. But renaming this variable doesn't hurt.
quoted hunk ↗ jump to hunk
memset(state, 0, sizeof(*state));@@ -155,6 +158,9 @@ static void am_state_init(struct am_state *state, const char *dir) state->scissors = SCISSORS_UNSET; argv_array_init(&state->git_apply_opts); + + if (!git_config_get_bool("commit.gpgsign", &sign_commit)) + state->sign_commit = sign_commit ? "" : NULL; } /**@@ -1272,7 +1278,7 @@ static void do_commit(const struct am_state *state) state->ignore_date ? "" : state->author_date, 1); if (commit_tree(state->msg, state->msg_len, tree, parents, commit, - author, NULL)) + author, state->sign_commit)) die(_("failed to write commit object")); reflog_msg = getenv("GIT_REFLOG_ACTION");@@ -1694,6 +1700,9 @@ int cmd_am(int argc, const char **argv, const char *prefix) N_("lie about committer date")), OPT_BOOL(0, "ignore-date", &state.ignore_date, N_("use current timestamp for author date")), + { OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"), + N_("GPG-sign commits"), + PARSE_OPT_OPTARG, NULL, (intptr_t) "" }, OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing, N_("(internal use for git-rebase)")), OPT_END() --2.5.0.rc0.76.gb2c6e93