rebase -i: learn to abbreviate command names

`git rebase -i` already know how to interpret single-letter command names. Teach it to generate the todo list with these same abbreviated names. Based-on-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Liam Beguin <liambeguin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Liam Beguin committed Dec 5, 2017 at 12:52 UTC d8ae6c84da52a210e84b3734bb93c575638236d3
4 files changed +38 -2
Documentation/rebase-config.txt
+20
@@ -30,3 +30,23 @@ rebase.instructionFormat::
30 A format string, as specified in linkgit:git-log[1], to be used for the
31 todo list during an interactive rebase. The format will
32 automatically have the long commit hash prepended to the format.
33 +
34 +rebase.abbreviateCommands::
35 + If set to true, `git rebase` will use abbreviated command names in the
36 + todo list resulting in something like this:
37 ++
38 +-------------------------------------------
39 + p deadbee The oneline of the commit
40 + p fa1afe1 The oneline of the next commit
41 + ...
42 +-------------------------------------------
43 ++
44 +instead of:
45 ++
46 +-------------------------------------------
47 + pick deadbee The oneline of the commit
48 + pick fa1afe1 The oneline of the next commit
49 + ...
50 +-------------------------------------------
51 ++
52 +Defaults to false.
builtin/rebase--helper.c
+3
@@ -13,6 +13,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
13 {
14 struct replay_opts opts = REPLAY_OPTS_INIT;
15 unsigned flags = 0, keep_empty = 0;
16 + int abbreviate_commands = 0;
17 enum {
18 CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
19 CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
@@ -43,6 +44,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
44 };
45
46 git_config(git_default_config, NULL);
47 + git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
48
49 opts.action = REPLAY_INTERACTIVE_REBASE;
50 opts.allow_ff = 1;
@@ -52,6 +54,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
54 builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
55
56 flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
57 + flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
58 flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
59
60 if (command == CONTINUE && argc == 1)
sequencer.c
+14 -2
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command command)
795 die("Unknown command: %d", command);
796 }
797
798 +static const char command_to_char(const enum todo_command command)
799 +{
800 + if (command < TODO_COMMENT && todo_command_info[command].c)
801 + return todo_command_info[command].c;
802 + return comment_line_char;
803 +}
804 +
805 static int is_noop(const enum todo_command command)
806 {
807 return TODO_NOOP <= command;
@@ -2453,6 +2460,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
2460 struct rev_info revs;
2461 struct commit *commit;
2462 int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
2463 + const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
2464
2465 init_revisions(&revs, NULL);
2466 revs.verbose_header = 1;
@@ -2485,7 +2493,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
2493 strbuf_reset(&buf);
2494 if (!keep_empty && is_original_commit_empty(commit))
2495 strbuf_addf(&buf, "%c ", comment_line_char);
2488 - strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
2496 + strbuf_addf(&buf, "%s %s ", insn,
2497 + oid_to_hex(&commit->object.oid));
2498 pretty_print_commit(&pp, commit, &buf);
2499 strbuf_addch(&buf, '\n');
2500 fputs(buf.buf, out);
@@ -2558,7 +2567,10 @@ int transform_todos(unsigned flags)
2567 }
2568
2569 /* add command to the buffer */
2561 - strbuf_addstr(&buf, command_to_string(item->command));
2570 + if (flags & TODO_LIST_ABBREVIATE_CMDS)
2571 + strbuf_addch(&buf, command_to_char(item->command));
2572 + else
2573 + strbuf_addstr(&buf, command_to_string(item->command));
2574
2575 /* add commit id */
2576 if (item->commit) {
sequencer.h
+1
@@ -47,6 +47,7 @@ int sequencer_remove_state(struct replay_opts *opts);
47
48 #define TODO_LIST_KEEP_EMPTY (1U << 0)
49 #define TODO_LIST_SHORTEN_IDS (1U << 1)
50 +#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
51 int sequencer_make_script(FILE *out, int argc, const char **argv,
52 unsigned flags);
53