Felipe Contreras <[email protected]> writes:
> As we should.
>
> Signed-off-by: Felipe Contreras <[email protected]>
> ---
> sequencer.c | 45 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/sequencer.c b/sequencer.c
> index c217716..3aa480e 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -127,6 +127,37 @@ static void add_rewritten(unsigned char *from, unsigned
> char *to)
> rewritten.nr++;
> }
>
> +static void run_rewrite_hook(void)
> +{
> + struct strbuf buf = STRBUF_INIT;
> + struct child_process proc;
> + const char *argv[3];
> + int code, i;
> +
> + argv[0] = find_hook("post-rewrite");
> + if (!argv[0])
> + return;
> +
> + argv[1] = "rebase";
> + argv[2] = NULL;
When the end-user action is "git cherry-pick A..B", shouldn't
the rewrite hook be called with "cherry-pick" not "rebase" as its
first argument?
More importantly, doesn't "git revert A..B" also trigger the
codepath for [4/8] and hence this function?
I think [3/8] --skip-empty makes sense also for revert, but I do not
think this one does as-is. As what [4/8] introduces is a record of
"rewrite", the patch does not make sense either. These two steps
would want to limit themselves to cherry-pick only, no?
> + memset(&proc, 0, sizeof(proc));
> + proc.argv = argv;
> + proc.in = -1;
> + proc.stdout_to_stderr = 1;
> +
> + code = start_command(&proc);
> + if (code)
> + return;
> + for (i = 0; i < rewritten.nr; i++) {
> + struct rewritten_list_item *item = &rewritten.items[i];
> + strbuf_addf(&buf, "%s %s\n", sha1_to_hex(item->from),
> sha1_to_hex(item->to));
> + }
> + write_in_full(proc.in, buf.buf, buf.len);
> + close(proc.in);
> + finish_command(&proc);
> +}
> +
> static void remove_sequencer_state(void)
> {
> struct strbuf seq_dir = STRBUF_INIT;
> @@ -1099,6 +1130,8 @@ static int pick_commits(struct commit_list *todo_list,
> struct replay_opts *opts)
> }
> }
>
> + run_rewrite_hook();
> +
> /*
> * Sequence of picks finished successfully; cleanup by
> * removing the .git/sequencer directory
> @@ -1136,14 +1169,24 @@ static int sequencer_continue(struct replay_opts
> *opts)
> }
> if (index_differs_from("HEAD", 0))
> return error_dirty_index(opts);
> + {
> + unsigned char to[20];
> + if (!read_ref("HEAD", to))
> + add_rewritten(todo_list->item->object.sha1, to);
> + }
> todo_list = todo_list->next;
> return pick_commits(todo_list, opts);
> }
>
> static int single_pick(struct commit *cmit, struct replay_opts *opts)
> {
> + int ret;
> setenv(GIT_REFLOG_ACTION, action_name(opts), 0);
> - return do_pick_commit(cmit, opts);
> + ret = do_pick_commit(cmit, opts);
> + if (ret)
> + return ret;
> + run_rewrite_hook();
> + return 0;
> }
>
> int sequencer_pick_revisions(struct replay_opts *opts)
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html