From: Alban Gruin <alban.gruin@gmail.com>
To: git@vger.kernel.org
Cc: Stefan Beller <sbeller@google.com>,
Christian Couder <christian.couder@gmail.com>,
Johannes Schindelin <Johannes.Schindelin@gmx.de>,
phillip.wood@dunelm.org.uk, Alban Gruin <alban.gruin@gmail.com>
Subject: [GSoC][PATCH v3 1/1] rebase--interactive: rewrite append_todo_help() in C
Date: Thu, 7 Jun 2018 12:30:12 +0200 [thread overview]
Message-ID: <20180607103012.22981-2-alban.gruin@gmail.com> (raw)
In-Reply-To: <20180607103012.22981-1-alban.gruin@gmail.com>
This rewrites append_todo_help() from shell to C. It also incorporates
some parts of initiate_action() and complete_action() that also write
help texts to the todo file.
Two flags are added to rebase--helper.c: one to call
append_todo_help() (`--append-todo-help`), and another one to tell
append_todo_help() to write the help text suited for the edit-todo
mode (`--write-edit-todo`).
Finally, append_todo_help() is removed from git-rebase--interactive.sh
to use `rebase--helper --append-todo-help` instead.
Signed-off-by: Alban Gruin <alban.gruin@gmail.com>
---
builtin/rebase--helper.c | 10 ++++++--
git-rebase--interactive.sh | 52 ++--------------------------------------
sequencer.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++
sequencer.h | 1 +
4 files changed, 71 insertions(+), 52 deletions(-)
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index f7c2a5fdc..ded5e291d 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -12,12 +12,12 @@ static const char * const builtin_rebase_helper_usage[] = {
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
{
struct replay_opts opts = REPLAY_OPTS_INIT;
- unsigned flags = 0, keep_empty = 0, rebase_merges = 0;
+ unsigned flags = 0, keep_empty = 0, rebase_merges = 0, write_edit_todo = 0;
int abbreviate_commands = 0, rebase_cousins = -1;
enum {
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
- ADD_EXEC
+ ADD_EXEC, APPEND_TODO_HELP
} command = 0;
struct option options[] = {
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -27,6 +27,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "rebase-merges", &rebase_merges, N_("rebase merge commits")),
OPT_BOOL(0, "rebase-cousins", &rebase_cousins,
N_("keep original branch points of cousins")),
+ OPT_BOOL(0, "write-edit-todo", &write_edit_todo,
+ N_("append the edit-todo message to the todo-list")),
OPT_CMDMODE(0, "continue", &command, N_("continue rebase"),
CONTINUE),
OPT_CMDMODE(0, "abort", &command, N_("abort rebase"),
@@ -45,6 +47,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
OPT_CMDMODE(0, "add-exec-commands", &command,
N_("insert exec commands in todo list"), ADD_EXEC),
+ OPT_CMDMODE(0, "append-todo-help", &command,
+ N_("insert the help in the todo list"), APPEND_TODO_HELP),
OPT_END()
};
@@ -84,5 +88,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
return !!rearrange_squash();
if (command == ADD_EXEC && argc == 2)
return !!sequencer_add_exec_commands(argv[1]);
+ if (command == APPEND_TODO_HELP && argc == 1)
+ return !!append_todo_help(write_edit_todo, keep_empty);
usage_with_options(builtin_rebase_helper_usage, options);
}
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 299ded213..94c23a7af 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -39,38 +39,6 @@ comment_for_reflog () {
esac
}
-append_todo_help () {
- gettext "
-Commands:
-p, pick <commit> = use commit
-r, reword <commit> = use commit, but edit the commit message
-e, edit <commit> = use commit, but stop for amending
-s, squash <commit> = use commit, but meld into previous commit
-f, fixup <commit> = like \"squash\", but discard this commit's log message
-x, exec <command> = run command (the rest of the line) using shell
-d, drop <commit> = remove commit
-l, label <label> = label current HEAD with a name
-t, reset <label> = reset HEAD to a label
-m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
-. create a merge commit using the original merge commit's
-. message (or the oneline, if no original merge commit was
-. specified). Use -c <commit> to reword the commit message.
-
-These lines can be re-ordered; they are executed from top to bottom.
-" | git stripspace --comment-lines >>"$todo"
-
- if test $(get_missing_commit_check_level) = error
- then
- gettext "
-Do not remove any line. Use 'drop' explicitly to remove a commit.
-" | git stripspace --comment-lines >>"$todo"
- else
- gettext "
-If you remove a line here THAT COMMIT WILL BE LOST.
-" | git stripspace --comment-lines >>"$todo"
- fi
-}
-
die_abort () {
apply_autostash
rm -rf "$state_dir"
@@ -143,13 +111,7 @@ initiate_action () {
git stripspace --strip-comments <"$todo" >"$todo".new
mv -f "$todo".new "$todo"
collapse_todo_ids
- append_todo_help
- gettext "
-You are editing the todo file of an ongoing interactive rebase.
-To continue rebase after editing, run:
- git rebase --continue
-
-" | git stripspace --comment-lines >>"$todo"
+ git rebase--helper --append-todo-help --write-edit-todo
git_sequence_editor "$todo" ||
die "$(gettext "Could not execute editor")"
@@ -220,17 +182,7 @@ $comment_char $(eval_ngettext \
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
"$todocount")
EOF
- append_todo_help
- gettext "
- However, if you remove everything, the rebase will be aborted.
-
- " | git stripspace --comment-lines >>"$todo"
-
- if test -z "$keep_empty"
- then
- printf '%s\n' "$comment_char $(gettext "Note that empty commits are commented out")" >>"$todo"
- fi
-
+ git rebase--helper --append-todo-help ${keep_empty:+--keep-empty}
has_action "$todo" ||
return 2
diff --git a/sequencer.c b/sequencer.c
index cca968043..1ffd990f7 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4326,6 +4326,66 @@ int check_todo_list(void)
return res;
}
+int append_todo_help(unsigned edit_todo, unsigned keep_empty)
+{
+ struct strbuf buf = STRBUF_INIT;
+ FILE *todo;
+ int ret;
+ const char *msg = _("\nCommands:\n"
+"p, pick <commit> = use commit\n"
+"r, reword <commit> = use commit, but edit the commit message\n"
+"e, edit <commit> = use commit, but stop for amending\n"
+"s, squash <commit> = use commit, but meld into previous commit\n"
+"f, fixup <commit> = like \"squash\", but discard this commit's log message\n"
+"x, exec <command> = run command (the rest of the line) using shell\n"
+"d, drop <commit> = remove commit\n"
+"l, label <label> = label current HEAD with a name\n"
+"t, reset <label> = reset HEAD to a label\n"
+"m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]\n"
+". create a merge commit using the original merge commit's\n"
+". message (or the oneline, if no original merge commit was\n"
+". specified). Use -c <commit> to reword the commit message.\n"
+"\n"
+"These lines can be re-ordered; they are executed from top to bottom.\n");
+
+ todo = fopen_or_warn(rebase_path_todo(), "a");
+ if (!todo)
+ return 1;
+
+ strbuf_add_commented_lines(&buf, msg, strlen(msg));
+
+ if (get_missing_commit_check_level() == CHECK_ERROR)
+ msg = _("\nDo not remove any line. Use 'drop' "
+ "explicitly to remove a commit.\n");
+ else
+ msg = _("\nIf you remove a line here "
+ "THAT COMMIT WILL BE LOST.\n");
+
+ strbuf_add_commented_lines(&buf, msg, strlen(msg));
+
+ if (edit_todo)
+ msg = _("\nYou are editing the todo file "
+ "of an ongoing interactive rebase.\n"
+ "To continue rebase after editing, run:\n"
+ " git rebase --continue\n\n");
+ else
+ msg = _("\nHowever, if you remove everything, "
+ "the rebase will be aborted.\n\n");
+
+ strbuf_add_commented_lines(&buf, msg, strlen(msg));
+
+ if (!keep_empty) {
+ msg = _("Note that empty commits are commented out");
+ strbuf_add_commented_lines(&buf, msg, strlen(msg));
+ }
+
+ ret = fputs(buf.buf, todo);
+ fclose(todo);
+ strbuf_release(&buf);
+
+ return ret;
+}
+
static int rewrite_file(const char *path, const char *buf, size_t len)
{
int rc = 0;
diff --git a/sequencer.h b/sequencer.h
index c5787c6b5..e14f6590e 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -80,6 +80,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);
int check_todo_list(void);
+int append_todo_help(unsigned edit_todo, unsigned keep_empty);
int skip_unnecessary_picks(void);
int rearrange_squash(void);
--
2.16.4
next prev parent reply other threads:[~2018-06-07 10:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-31 11:01 [GSoC][PATCH 0/2] rebase -i: rewrite append_todo_help() in C Alban Gruin
2018-05-31 11:01 ` [GSoC][PATCH 1/2] rebase--interactive: " Alban Gruin
2018-05-31 11:01 ` [GSoC][PATCH 2/2] sequencer: remove newlines from append_todo_help() messages Alban Gruin
2018-05-31 17:48 ` [GSoC][PATCH 0/2] rebase -i: rewrite append_todo_help() in C Phillip Wood
2018-05-31 18:44 ` Stefan Beller
2018-05-31 19:33 ` Alban Gruin
2018-05-31 19:41 ` Stefan Beller
2018-06-01 9:44 ` Phillip Wood
2018-06-01 19:46 ` Stefan Beller
2018-05-31 19:25 ` Alban Gruin
2018-06-01 9:38 ` Phillip Wood
2018-06-05 12:53 ` [GSoC][PATCH v2 0/1] " Alban Gruin
2018-06-05 12:53 ` [GSoC][PATCH v2 1/1] rebase--interactive: " Alban Gruin
2018-06-07 10:30 ` [GSoC][PATCH v3 0/1] rebase -i: " Alban Gruin
2018-06-07 10:30 ` Alban Gruin [this message]
2018-06-26 16:16 ` [GSoC][PATCH v4 0/2] " Alban Gruin
2018-06-26 16:16 ` [GSoC][PATCH v4 1/2] sequencer: make two functions and an enum from sequencer.c public Alban Gruin
2018-06-26 21:41 ` Johannes Schindelin
2018-06-27 14:54 ` Alban Gruin
2018-06-26 16:16 ` [GSoC][PATCH v4 2/2] rebase--interactive: rewrite append_todo_help() in C Alban Gruin
2018-06-26 21:43 ` Johannes Schindelin
2018-06-26 21:37 ` [GSoC][PATCH v4 0/2] rebase -i: " Johannes Schindelin
2018-06-27 14:54 ` Alban Gruin
2018-06-28 10:04 ` [GSoC][PATCH v5 " Alban Gruin
2018-06-28 10:04 ` [GSoC][PATCH v5 1/2] sequencer: make two functions and an enum from sequencer.c public Alban Gruin
2018-06-28 10:04 ` [GSoC][PATCH v5 2/2] rebase--interactive: rewrite append_todo_help() in C Alban Gruin
2018-06-28 18:05 ` [GSoC][PATCH v5 0/2] rebase -i: " Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180607103012.22981-2-alban.gruin@gmail.com \
--to=alban.gruin@gmail.com \
--cc=Johannes.Schindelin@gmx.de \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
--cc=sbeller@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).