From: Junio C Hamano Date: Fri, 2 Nov 2018 02:04:53 +0000 (+0900) Subject: Merge branch 'ag/rebase-i-in-c' X-Git-Tag: v2.20.0-rc0~94 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=commitdiff_plain;h=b49ef560ed66449d24a3fdfe25972c390bb44951 Merge branch 'ag/rebase-i-in-c' Rewrite of the remaining "rebase -i" machinery in C. * ag/rebase-i-in-c: rebase -i: move rebase--helper modes to rebase--interactive rebase -i: remove git-rebase--interactive.sh rebase--interactive2: rewrite the submodes of interactive rebase in C rebase -i: implement the main part of interactive rebase as a builtin rebase -i: rewrite init_basic_state() in C rebase -i: rewrite write_basic_state() in C rebase -i: rewrite the rest of init_revisions_and_shortrevisions() in C rebase -i: implement the logic to initialize $revisions in C rebase -i: remove unused modes and functions rebase -i: rewrite complete_action() in C t3404: todo list with commented-out commands only aborts sequencer: change the way skip_unnecessary_picks() returns its result sequencer: refactor append_todo_help() to write its message to a buffer rebase -i: rewrite checkout_onto() in C rebase -i: rewrite setup_reflog_action() in C sequencer: add a new function to silence a command, except if it fails rebase -i: rewrite the edit-todo functionality in C editor: add a function to launch the sequence editor rebase -i: rewrite append_todo_help() in C sequencer: make three functions and an enum from sequencer.c public --- b49ef560ed66449d24a3fdfe25972c390bb44951 diff --cc .gitignore index 4d5de166e8,406f26d050..0d77ea5894 --- a/.gitignore +++ b/.gitignore @@@ -122,8 -116,6 +122,7 @@@ /git-read-tree /git-rebase /git-rebase--am +/git-rebase--common - /git-rebase--helper /git-rebase--interactive /git-rebase--merge /git-rebase--preserve-merges diff --cc Makefile index 95b93c709d,ca3a0888dd..bbfbb4292d --- a/Makefile +++ b/Makefile @@@ -626,8 -619,6 +626,7 @@@ SCRIPT_SH += git-web--browse.s SCRIPT_LIB += git-mergetool--lib SCRIPT_LIB += git-parse-remote SCRIPT_LIB += git-rebase--am +SCRIPT_LIB += git-rebase--common - SCRIPT_LIB += git-rebase--interactive SCRIPT_LIB += git-rebase--preserve-merges SCRIPT_LIB += git-rebase--merge SCRIPT_LIB += git-sh-setup @@@ -952,9 -919,9 +951,10 @@@ LIB_OBJS += progress. LIB_OBJS += prompt.o LIB_OBJS += protocol.o LIB_OBJS += quote.o +LIB_OBJS += range-diff.o LIB_OBJS += reachable.o LIB_OBJS += read-cache.o + LIB_OBJS += rebase-interactive.o LIB_OBJS += reflog-walk.o LIB_OBJS += refs.o LIB_OBJS += refs/files-backend.o @@@ -1092,10 -1058,8 +1092,10 @@@ BUILTIN_OBJS += builtin/prune-packed. BUILTIN_OBJS += builtin/prune.o BUILTIN_OBJS += builtin/pull.o BUILTIN_OBJS += builtin/push.o +BUILTIN_OBJS += builtin/range-diff.o BUILTIN_OBJS += builtin/read-tree.o +BUILTIN_OBJS += builtin/rebase.o - BUILTIN_OBJS += builtin/rebase--helper.o + BUILTIN_OBJS += builtin/rebase--interactive.o BUILTIN_OBJS += builtin/receive-pack.o BUILTIN_OBJS += builtin/reflog.o BUILTIN_OBJS += builtin/remote.o diff --cc builtin.h index 6fb66f5ba4,7feb689d87..6538932e99 --- a/builtin.h +++ b/builtin.h @@@ -202,10 -201,8 +202,10 @@@ extern int cmd_prune(int argc, const ch extern int cmd_prune_packed(int argc, const char **argv, const char *prefix); extern int cmd_pull(int argc, const char **argv, const char *prefix); extern int cmd_push(int argc, const char **argv, const char *prefix); +extern int cmd_range_diff(int argc, const char **argv, const char *prefix); extern int cmd_read_tree(int argc, const char **argv, const char *prefix); +extern int cmd_rebase(int argc, const char **argv, const char *prefix); - extern int cmd_rebase__helper(int argc, const char **argv, const char *prefix); + extern int cmd_rebase__interactive(int argc, const char **argv, const char *prefix); extern int cmd_receive_pack(int argc, const char **argv, const char *prefix); extern int cmd_reflog(int argc, const char **argv, const char *prefix); extern int cmd_remote(int argc, const char **argv, const char *prefix); diff --cc git.c index 8e52276831,81aabd1423..2f604a41ea --- a/git.c +++ b/git.c @@@ -524,15 -517,8 +524,15 @@@ static struct cmd_struct commands[] = { "prune-packed", cmd_prune_packed, RUN_SETUP }, { "pull", cmd_pull, RUN_SETUP | NEED_WORK_TREE }, { "push", cmd_push, RUN_SETUP }, + { "range-diff", cmd_range_diff, RUN_SETUP | USE_PAGER }, { "read-tree", cmd_read_tree, RUN_SETUP | SUPPORT_SUPER_PREFIX}, + /* + * NEEDSWORK: Until the rebase is independent and needs no redirection + * to rebase shell script this is kept as is, then should be changed to + * RUN_SETUP | NEED_WORK_TREE + */ + { "rebase", cmd_rebase }, - { "rebase--helper", cmd_rebase__helper, RUN_SETUP | NEED_WORK_TREE }, + { "rebase--interactive", cmd_rebase__interactive, RUN_SETUP | NEED_WORK_TREE }, { "receive-pack", cmd_receive_pack }, { "reflog", cmd_reflog, RUN_SETUP }, { "remote", cmd_remote, RUN_SETUP }, diff --cc sequencer.c index 0c164d5f98,8dd6db5a01..3c86c7694b --- a/sequencer.c +++ b/sequencer.c @@@ -30,7 -30,7 +30,8 @@@ #include "oidset.h" #include "commit-slab.h" #include "alias.h" +#include "commit-reach.h" + #include "rebase-interactive.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" @@@ -903,24 -876,13 +918,13 @@@ static int run_git_commit(const char *d if ((flags & ALLOW_EMPTY)) argv_array_push(&cmd.args, "--allow-empty"); - if (opts->allow_empty_message) + if (!(flags & EDIT_MSG)) argv_array_push(&cmd.args, "--allow-empty-message"); - if (cmd.err == -1) { - /* hide stderr on success */ - struct strbuf buf = STRBUF_INIT; - int rc = pipe_command(&cmd, - NULL, 0, - /* stdout is already redirected */ - NULL, 0, - &buf, 0); - if (rc) - fputs(buf.buf, stderr); - strbuf_release(&buf); - return rc; - } - - return run_command(&cmd); + if (is_rebase_i(opts) && !(flags & EDIT_MSG)) + return run_command_silent_on_success(&cmd); + else + return run_command(&cmd); } static int rest_is_empty(const struct strbuf *sb, int start) @@@ -4587,9 -4515,9 +4690,9 @@@ static int skip_unnecessary_picks(struc if (item->commit->parents->next) break; /* merge commit */ parent_oid = &item->commit->parents->item->object.oid; - if (!oideq(parent_oid, oid)) - if (hashcmp(parent_oid->hash, output_oid->hash)) ++ if (!oideq(parent_oid, output_oid)) break; - oid = &item->commit->object.oid; + oidcpy(output_oid, &item->commit->object.oid); } if (i > 0) { int offset = get_item_line_offset(&todo_list, i); diff --cc sequencer.h index c986bc8251,aab280f276..660cff5050 --- a/sequencer.h +++ b/sequencer.h @@@ -1,13 -1,9 +1,14 @@@ #ifndef SEQUENCER_H #define SEQUENCER_H +#include "cache.h" +#include "strbuf.h" + +struct commit; + 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) diff --cc strbuf.h index bf18fddb5b,66da9822fd..9981f782b2 --- a/strbuf.h +++ b/strbuf.h @@@ -582,14 -574,11 +582,16 @@@ void strbuf_add_unique_abbrev(struct st * run in. If the buffer is NULL the editor is launched as usual but the * file's contents are not read into the buffer upon completion. */ - int launch_editor(const char *path, - struct strbuf *buffer, -extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env); -extern int launch_sequence_editor(const char *path, struct strbuf *buffer, - const char *const *env); ++int launch_editor(const char *path, struct strbuf *buffer, + const char *const *env); + ++int launch_sequence_editor(const char *path, struct strbuf *buffer, ++ const char *const *env); + -extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); +void strbuf_add_lines(struct strbuf *sb, + const char *prefix, + const char *buf, + size_t size); /** * Append s to sb, with the characters '<', '>', '&' and '"' converted