From 44b776c3e9bcbfcb7fbf78baafc67394cf56e812 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 10 Aug 2018 18:51:28 +0200 Subject: sequencer: make three functions and an enum from sequencer.c public This makes rebase_path_todo(), get_missing_commit_check_level(), write_message() and the enum check_level accessible outside sequencer.c, renames check_level to missing_commit_check_level, and prefixes its value names by MISSING_COMMIT_ to avoid namespace pollution. This function and this enum will eventually be moved to rebase-interactive.c and become static again, so no special attention was given to the naming. This will be needed for the rewrite of append_todo_help() from shell to C, as it will be in a new library source file, rebase-interactive.c. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index c5787c6b56..792e448b67 100644 --- a/sequencer.h +++ b/sequencer.h @@ -3,6 +3,7 @@ const char *git_path_commit_editmsg(void); const char *git_path_seq_dir(void); +const char *rebase_path_todo(void); #define APPEND_SIGNOFF_DEDUP (1u << 0) @@ -57,6 +58,15 @@ struct replay_opts { }; #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT } +enum missing_commit_check_level { + MISSING_COMMIT_CHECK_IGNORE = 0, + MISSING_COMMIT_CHECK_WARN, + MISSING_COMMIT_CHECK_ERROR +}; + +int write_message(const void *buf, size_t len, const char *filename, + int append_eol); + /* Call this to setup defaults before parsing command line options */ void sequencer_init_config(struct replay_opts *opts); int sequencer_pick_revisions(struct replay_opts *opts); @@ -79,6 +89,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv, int sequencer_add_exec_commands(const char *command); int transform_todos(unsigned flags); +enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(void); int skip_unnecessary_picks(void); int rearrange_squash(void); -- cgit v1.2.3 From 2c58483a5983d1313f674e2ba32b3bac24df6911 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 10 Aug 2018 18:51:33 +0200 Subject: rebase -i: rewrite setup_reflog_action() in C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This rewrites (the misnamed) setup_reflog_action() from shell to C. The new version is called prepare_branch_to_be_rebased(). A new command is added to rebase--helper.c, “checkout-base”, as well as a new flag, “verbose”, to avoid silencing the output of the checkout operation called by checkout_base_commit(). The function `run_git_checkout()` will also be used in the next commit, therefore its code is not part of `checkout_base_commit()`. The shell version is then stripped in favour of a call to the helper. As $GIT_REFLOG_ACTION is no longer set at the first call of checkout_onto(), a call to comment_for_reflog() is added at the beginning of this function. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index 792e448b67..f619b02a13 100644 --- a/sequencer.h +++ b/sequencer.h @@ -109,6 +109,8 @@ int update_head_with_reflog(const struct commit *old_head, void commit_post_rewrite(const struct commit *current_head, const struct object_id *new_head); +int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit); + #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) void print_commit_summary(const char *prefix, const struct object_id *oid, -- cgit v1.2.3 From 4df66c40b08931eb224964f12decbb0f660cf932 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 10 Aug 2018 18:51:34 +0200 Subject: rebase -i: rewrite checkout_onto() in C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This rewrites checkout_onto() from shell to C. A new command (“checkout-onto”) is added to rebase--helper.c. The shell version is then stripped. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index f619b02a13..d2b54adf45 100644 --- a/sequencer.h +++ b/sequencer.h @@ -110,6 +110,9 @@ void commit_post_rewrite(const struct commit *current_head, const struct object_id *new_head); int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit); +int checkout_onto(struct replay_opts *opts, + const char *onto_name, const char *onto, + const char *orig_head); #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) -- cgit v1.2.3 From d4ed5d7713c779487a52d30e83185a056c4bf023 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 10 Aug 2018 18:51:36 +0200 Subject: sequencer: change the way skip_unnecessary_picks() returns its result Instead of skip_unnecessary_picks() printing its result to stdout, it returns it into a struct object_id, as the rewrite of complete_action() (to come in the next commit) will need it. rebase--helper then is modified to fit this change. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index d2b54adf45..fcbcd246c2 100644 --- a/sequencer.h +++ b/sequencer.h @@ -91,7 +91,7 @@ int sequencer_add_exec_commands(const char *command); int transform_todos(unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(void); -int skip_unnecessary_picks(void); +int skip_unnecessary_picks(struct object_id *output_oid); int rearrange_squash(void); extern const char sign_off_header[]; -- cgit v1.2.3 From b97e187364990fb8410355ff8b4365d0e37bbbbe Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Tue, 28 Aug 2018 14:10:36 +0200 Subject: rebase -i: rewrite complete_action() in C MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This rewrites complete_action() from shell to C. A new mode is added to rebase--helper (`--complete-action`), as well as a new flag (`--autosquash`). Finally, complete_action() is stripped from git-rebase--interactive.sh. The original complete_action() would return the code 2 when the todo list contained no actions. This was a special case for rebase -i and -p; git-rebase.sh would then apply the autostash, delete the state directory, and die with the message "Nothing to do". This cleanup is rewritten in C instead of returning 2. As rebase -i no longer returns 2, the comment describing this behaviour in git-rebase.sh is updated to reflect this change. The message "Nothing to do" is now printed with error(), and so becomes "error: nothing to do". Some tests in t3404 check this value, so they are updated to fit this change. The first check might seem useless as we write "noop" to the todo list if it is empty. Actually, the todo list might contain commented commands (ie. empty commits). In this case, complete_action() won’t write "noop", and will abort without starting the editor. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index fcbcd246c2..d58766c6d7 100644 --- a/sequencer.h +++ b/sequencer.h @@ -92,6 +92,10 @@ int transform_todos(unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(void); int skip_unnecessary_picks(struct object_id *output_oid); +int complete_action(struct replay_opts *opts, unsigned flags, + const char *shortrevisions, const char *onto_name, + const char *onto, const char *orig_head, const char *cmd, + unsigned autosquash); int rearrange_squash(void); extern const char sign_off_header[]; -- cgit v1.2.3 From 91f0d95dcb4dd9c388881b64a7d79a3809927126 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Tue, 28 Aug 2018 14:10:37 +0200 Subject: rebase -i: remove unused modes and functions This removes the modes `--skip-unnecessary-picks`, `--append-todo-help`, and `--checkout-onto` from rebase--helper.c, the functions of git-rebase--interactive.sh that were rendered useless by the rewrite of complete_action(), and append_todo_help_to_file() from rebase-interactive.c. skip_unnecessary_picks() and checkout_onto() becomes static, as they are only used inside of the sequencer. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index d58766c6d7..02e3d7940e 100644 --- a/sequencer.h +++ b/sequencer.h @@ -91,7 +91,6 @@ int sequencer_add_exec_commands(const char *command); int transform_todos(unsigned flags); enum missing_commit_check_level get_missing_commit_check_level(void); int check_todo_list(void); -int skip_unnecessary_picks(struct object_id *output_oid); int complete_action(struct replay_opts *opts, unsigned flags, const char *shortrevisions, const char *onto_name, const char *onto, const char *orig_head, const char *cmd, @@ -114,9 +113,6 @@ void commit_post_rewrite(const struct commit *current_head, const struct object_id *new_head); int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit); -int checkout_onto(struct replay_opts *opts, - const char *onto_name, const char *onto, - const char *orig_head); #define SUMMARY_INITIAL_COMMIT (1 << 0) #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1) -- cgit v1.2.3 From 65850686cf072d6de88880247adb7113db8a52f2 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Tue, 28 Aug 2018 14:10:40 +0200 Subject: rebase -i: rewrite write_basic_state() in C This rewrites write_basic_state() from git-rebase.sh in C. This is the first step in the conversion of init_basic_state(), hence the mode in rebase--helper.c is called INIT_BASIC_STATE. init_basic_state() will be converted in the next commit. The part of read_strategy_opts() that parses the stategy options is moved to a new function to allow its use in rebase--helper.c. Finally, the call to write_basic_state() is removed from git-rebase--interactive.sh, replaced by a call to `--init-basic-state`. Signed-off-by: Alban Gruin Signed-off-by: Junio C Hamano --- sequencer.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sequencer.h') diff --git a/sequencer.h b/sequencer.h index 02e3d7940e..aab280f276 100644 --- a/sequencer.h +++ b/sequencer.h @@ -119,3 +119,7 @@ int prepare_branch_to_be_rebased(struct replay_opts *opts, const char *commit); void print_commit_summary(const char *prefix, const struct object_id *oid, unsigned int flags); #endif + +void parse_strategy_opts(struct replay_opts *opts, char *raw_opts); +int write_basic_state(struct replay_opts *opts, const char *head_name, + const char *onto, const char *orig_head); -- cgit v1.2.3