Skip to content

Commit d8ae6c8

Browse files
liambeguingitster
authored andcommitted
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 <[email protected]> Signed-off-by: Liam Beguin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0cce4a2 commit d8ae6c8

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

Documentation/rebase-config.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,23 @@ rebase.instructionFormat::
3030
A format string, as specified in linkgit:git-log[1], to be used for the
3131
todo list during an interactive rebase. The format will
3232
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
1313
{
1414
struct replay_opts opts = REPLAY_OPTS_INIT;
1515
unsigned flags = 0, keep_empty = 0;
16+
int abbreviate_commands = 0;
1617
enum {
1718
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
1819
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
@@ -43,6 +44,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
4344
};
4445

4546
git_config(git_default_config, NULL);
47+
git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
4648

4749
opts.action = REPLAY_INTERACTIVE_REBASE;
4850
opts.allow_ff = 1;
@@ -52,6 +54,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
5254
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
5355

5456
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
57+
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
5558
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
5659

5760
if (command == CONTINUE && argc == 1)

sequencer.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command command)
795795
die("Unknown command: %d", command);
796796
}
797797

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+
798805
static int is_noop(const enum todo_command command)
799806
{
800807
return TODO_NOOP <= command;
@@ -2453,6 +2460,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
24532460
struct rev_info revs;
24542461
struct commit *commit;
24552462
int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
2463+
const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
24562464

24572465
init_revisions(&revs, NULL);
24582466
revs.verbose_header = 1;
@@ -2485,7 +2493,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
24852493
strbuf_reset(&buf);
24862494
if (!keep_empty && is_original_commit_empty(commit))
24872495
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));
24892498
pretty_print_commit(&pp, commit, &buf);
24902499
strbuf_addch(&buf, '\n');
24912500
fputs(buf.buf, out);
@@ -2558,7 +2567,10 @@ int transform_todos(unsigned flags)
25582567
}
25592568

25602569
/* 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));
25622574

25632575
/* add commit id */
25642576
if (item->commit) {

sequencer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ int sequencer_remove_state(struct replay_opts *opts);
4747

4848
#define TODO_LIST_KEEP_EMPTY (1U << 0)
4949
#define TODO_LIST_SHORTEN_IDS (1U << 1)
50+
#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
5051
int sequencer_make_script(FILE *out, int argc, const char **argv,
5152
unsigned flags);
5253

0 commit comments

Comments
 (0)