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>
This commit is contained in:

committed by
Junio C Hamano

parent
0cce4a2756
commit
d8ae6c84da
@ -30,3 +30,23 @@ rebase.instructionFormat::
|
|||||||
A format string, as specified in linkgit:git-log[1], to be used for the
|
A format string, as specified in linkgit:git-log[1], to be used for the
|
||||||
todo list during an interactive rebase. The format will
|
todo list during an interactive rebase. The format will
|
||||||
automatically have the long commit hash prepended to the format.
|
automatically have the long commit hash prepended to the format.
|
||||||
|
|
||||||
|
rebase.abbreviateCommands::
|
||||||
|
If set to true, `git rebase` will use abbreviated command names in the
|
||||||
|
todo list resulting in something like this:
|
||||||
|
+
|
||||||
|
-------------------------------------------
|
||||||
|
p deadbee The oneline of the commit
|
||||||
|
p fa1afe1 The oneline of the next commit
|
||||||
|
...
|
||||||
|
-------------------------------------------
|
||||||
|
+
|
||||||
|
instead of:
|
||||||
|
+
|
||||||
|
-------------------------------------------
|
||||||
|
pick deadbee The oneline of the commit
|
||||||
|
pick fa1afe1 The oneline of the next commit
|
||||||
|
...
|
||||||
|
-------------------------------------------
|
||||||
|
+
|
||||||
|
Defaults to false.
|
||||||
|
@ -13,6 +13,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
|||||||
{
|
{
|
||||||
struct replay_opts opts = REPLAY_OPTS_INIT;
|
struct replay_opts opts = REPLAY_OPTS_INIT;
|
||||||
unsigned flags = 0, keep_empty = 0;
|
unsigned flags = 0, keep_empty = 0;
|
||||||
|
int abbreviate_commands = 0;
|
||||||
enum {
|
enum {
|
||||||
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
|
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
|
||||||
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
|
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
|
||||||
@ -43,6 +44,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
|||||||
};
|
};
|
||||||
|
|
||||||
git_config(git_default_config, NULL);
|
git_config(git_default_config, NULL);
|
||||||
|
git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
|
||||||
|
|
||||||
opts.action = REPLAY_INTERACTIVE_REBASE;
|
opts.action = REPLAY_INTERACTIVE_REBASE;
|
||||||
opts.allow_ff = 1;
|
opts.allow_ff = 1;
|
||||||
@ -52,6 +54,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
|
|||||||
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
|
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
|
||||||
|
|
||||||
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
|
flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
|
||||||
|
flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
|
||||||
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
|
flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
|
||||||
|
|
||||||
if (command == CONTINUE && argc == 1)
|
if (command == CONTINUE && argc == 1)
|
||||||
|
16
sequencer.c
16
sequencer.c
@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command command)
|
|||||||
die("Unknown command: %d", command);
|
die("Unknown command: %d", command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char command_to_char(const enum todo_command command)
|
||||||
|
{
|
||||||
|
if (command < TODO_COMMENT && todo_command_info[command].c)
|
||||||
|
return todo_command_info[command].c;
|
||||||
|
return comment_line_char;
|
||||||
|
}
|
||||||
|
|
||||||
static int is_noop(const enum todo_command command)
|
static int is_noop(const enum todo_command command)
|
||||||
{
|
{
|
||||||
return TODO_NOOP <= command;
|
return TODO_NOOP <= command;
|
||||||
@ -2453,6 +2460,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
|
|||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
struct commit *commit;
|
struct commit *commit;
|
||||||
int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
|
int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
|
||||||
|
const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
|
||||||
|
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
revs.verbose_header = 1;
|
revs.verbose_header = 1;
|
||||||
@ -2485,7 +2493,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
|
|||||||
strbuf_reset(&buf);
|
strbuf_reset(&buf);
|
||||||
if (!keep_empty && is_original_commit_empty(commit))
|
if (!keep_empty && is_original_commit_empty(commit))
|
||||||
strbuf_addf(&buf, "%c ", comment_line_char);
|
strbuf_addf(&buf, "%c ", comment_line_char);
|
||||||
strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
|
strbuf_addf(&buf, "%s %s ", insn,
|
||||||
|
oid_to_hex(&commit->object.oid));
|
||||||
pretty_print_commit(&pp, commit, &buf);
|
pretty_print_commit(&pp, commit, &buf);
|
||||||
strbuf_addch(&buf, '\n');
|
strbuf_addch(&buf, '\n');
|
||||||
fputs(buf.buf, out);
|
fputs(buf.buf, out);
|
||||||
@ -2558,7 +2567,10 @@ int transform_todos(unsigned flags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* add command to the buffer */
|
/* add command to the buffer */
|
||||||
strbuf_addstr(&buf, command_to_string(item->command));
|
if (flags & TODO_LIST_ABBREVIATE_CMDS)
|
||||||
|
strbuf_addch(&buf, command_to_char(item->command));
|
||||||
|
else
|
||||||
|
strbuf_addstr(&buf, command_to_string(item->command));
|
||||||
|
|
||||||
/* add commit id */
|
/* add commit id */
|
||||||
if (item->commit) {
|
if (item->commit) {
|
||||||
|
@ -47,6 +47,7 @@ int sequencer_remove_state(struct replay_opts *opts);
|
|||||||
|
|
||||||
#define TODO_LIST_KEEP_EMPTY (1U << 0)
|
#define TODO_LIST_KEEP_EMPTY (1U << 0)
|
||||||
#define TODO_LIST_SHORTEN_IDS (1U << 1)
|
#define TODO_LIST_SHORTEN_IDS (1U << 1)
|
||||||
|
#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
|
||||||
int sequencer_make_script(FILE *out, int argc, const char **argv,
|
int sequencer_make_script(FILE *out, int argc, const char **argv,
|
||||||
unsigned flags);
|
unsigned flags);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user