Pass -t and --trailer flags to git-reinterpret-trailers.

Signed-off-by: Michael S. Tsirkin <m...@redhat.com>
---
 builtin/am.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/builtin/am.c b/builtin/am.c
index 4180b04..480c4c2 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -122,6 +122,7 @@ struct am_state {
        int message_id;
        int scissors; /* enum scissors_type */
        struct argv_array git_apply_opts;
+       struct argv_array git_interpret_trailers_opts;
        const char *resolvemsg;
        int committer_date_is_author_date;
        int ignore_date;
@@ -157,6 +158,8 @@ static void am_state_init(struct am_state *state, const 
char *dir)
 
        if (!git_config_get_bool("commit.gpgsign", &gpgsign))
                state->sign_commit = gpgsign ? "" : NULL;
+
+       argv_array_init(&state->git_interpret_trailers_opts);
 }
 
 /**
@@ -170,6 +173,7 @@ static void am_state_release(struct am_state *state)
        free(state->author_date);
        free(state->msg);
        argv_array_clear(&state->git_apply_opts);
+       argv_array_clear(&state->git_interpret_trailers_opts);
 }
 
 /**
@@ -472,6 +476,11 @@ static void am_load(struct am_state *state)
        if (sq_dequote_to_argv_array(sb.buf, &state->git_apply_opts) < 0)
                die(_("could not parse %s"), am_path(state, "apply-opt"));
 
+       read_state_file(&sb, state, "interpret-trailers-opt", 1);
+       argv_array_clear(&state->git_interpret_trailers_opts);
+       if (sq_dequote_to_argv_array(sb.buf, 
&state->git_interpret_trailers_opts) < 0)
+               die(_("could not parse %s"), am_path(state, 
"interpret-trailers-opt"));
+
        state->rebasing = !!file_exists(am_path(state, "rebasing"));
 
        strbuf_release(&sb);
@@ -988,6 +997,7 @@ static void am_setup(struct am_state *state, enum 
patch_format patch_format,
        unsigned char curr_head[GIT_SHA1_RAWSZ];
        const char *str;
        struct strbuf sb = STRBUF_INIT;
+       struct strbuf tsb = STRBUF_INIT;
 
        if (!patch_format)
                patch_format = detect_patch_format(paths);
@@ -1048,6 +1058,9 @@ static void am_setup(struct am_state *state, enum 
patch_format patch_format,
        sq_quote_argv(&sb, state->git_apply_opts.argv, 0);
        write_state_text(state, "apply-opt", sb.buf);
 
+       sq_quote_argv(&tsb, state->git_interpret_trailers_opts.argv, 0);
+       write_state_text(state, "interpret-trailers-opt", tsb.buf);
+
        if (state->rebasing)
                write_state_text(state, "rebasing", "");
        else
@@ -1072,6 +1085,7 @@ static void am_setup(struct am_state *state, enum 
patch_format patch_format,
        write_state_count(state, "next", state->cur);
        write_state_count(state, "last", state->last);
 
+       strbuf_release(&tsb);
        strbuf_release(&sb);
 }
 
@@ -1233,6 +1247,34 @@ static void am_append_signoff(struct am_state *state)
 }
 
 /**
+ * Processes the supplied message file in-place with git-interpret-trailers.
+ * Returns 0 on success, -1 otherwise.
+ */
+static int run_interpret_trailers(const struct am_state *state, const char 
*msg)
+{
+       struct child_process cp = CHILD_PROCESS_INIT;
+
+       if (!state->git_interpret_trailers_opts.argc)
+               return 0;
+
+       cp.git_cmd = 1;
+
+       argv_array_push(&cp.args, "interpret-trailers");
+
+       argv_array_push(&cp.args, "--in-place");
+       argv_array_push(&cp.args, "--suppress-blank-line");
+
+       argv_array_pushv(&cp.args, state->git_interpret_trailers_opts.argv);
+
+       argv_array_push(&cp.args, msg);
+
+       if (run_command(&cp))
+               return -1;
+
+       return 0;
+}
+
+/**
  * Parses `mail` using git-mailinfo, extracting its patch and authorship info.
  * state->msg will be set to the patch message. state->author_name,
  * state->author_email and state->author_date will be set to the patch author's
@@ -1301,6 +1343,9 @@ static int parse_mail(struct am_state *state, const char 
*mail)
        fclose(mi.input);
        fclose(mi.output);
 
+       if (run_interpret_trailers(state, am_path(state, "msg")) < 0)
+               die("could not interpret trailers");
+
        /* Extract message and author information */
        fp = xfopen(am_path(state, "info"), "r");
        while (!strbuf_getline_lf(&sb, fp)) {
@@ -2299,6 +2344,9 @@ int cmd_am(int argc, const char **argv, const char 
*prefix)
                OPT_PASSTHRU_ARGV('p', NULL, &state.git_apply_opts, N_("num"),
                        N_("pass it through git-apply"),
                        0),
+               OPT_PASSTHRU_ARGV('t', "trailer", 
&state.git_interpret_trailers_opts, N_("trailer"),
+                       N_("pass it through git-interpret-trailers"),
+                       0),
                OPT_CALLBACK(0, "patch-format", &patch_format, N_("format"),
                        N_("format the patch(es) are in"),
                        parse_opt_patchformat),
-- 
MST

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to