Skip to content

Commit 0da2ba4

Browse files
committed
Merge branch 'lb/rebase-i-short-command-names'
With a configuration variable rebase.abbreviateCommands set, "git rebase -i" produces the todo list with a single-letter command names. * lb/rebase-i-short-command-names: sequencer.c: drop 'const' from function return type t3404: add test case for abbreviated commands rebase -i: learn to abbreviate command names rebase -i -x: add exec commands via the rebase--helper rebase -i: update functions to use a flags parameter rebase -i: replace reference to sha1 with oid rebase -i: refactor transform_todo_ids rebase -i: set commit to null in exec commands Documentation: use preferred name for the 'todo list' script Documentation: move rebase.* configs to new file
2 parents 720b176 + ee5462d commit 0da2ba4

File tree

8 files changed

+186
-126
lines changed

8 files changed

+186
-126
lines changed

Documentation/config.txt

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2736,36 +2736,7 @@ push.recurseSubmodules::
27362736
is retained. You may override this configuration at time of push by
27372737
specifying '--recurse-submodules=check|on-demand|no'.
27382738

2739-
rebase.stat::
2740-
Whether to show a diffstat of what changed upstream since the last
2741-
rebase. False by default.
2742-
2743-
rebase.autoSquash::
2744-
If set to true enable `--autosquash` option by default.
2745-
2746-
rebase.autoStash::
2747-
When set to true, automatically create a temporary stash entry
2748-
before the operation begins, and apply it after the operation
2749-
ends. This means that you can run rebase on a dirty worktree.
2750-
However, use with care: the final stash application after a
2751-
successful rebase might result in non-trivial conflicts.
2752-
Defaults to false.
2753-
2754-
rebase.missingCommitsCheck::
2755-
If set to "warn", git rebase -i will print a warning if some
2756-
commits are removed (e.g. a line was deleted), however the
2757-
rebase will still proceed. If set to "error", it will print
2758-
the previous warning and stop the rebase, 'git rebase
2759-
--edit-todo' can then be used to correct the error. If set to
2760-
"ignore", no checking is done.
2761-
To drop a commit without warning or error, use the `drop`
2762-
command in the todo-list.
2763-
Defaults to "ignore".
2764-
2765-
rebase.instructionFormat::
2766-
A format string, as specified in linkgit:git-log[1], to be used for
2767-
the instruction list during an interactive rebase. The format will automatically
2768-
have the long commit hash prepended to the format.
2739+
include::rebase-config.txt[]
27692740

27702741
receive.advertiseAtomic::
27712742
By default, git-receive-pack will advertise the atomic push

Documentation/git-rebase.txt

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -203,24 +203,7 @@ Alternatively, you can undo the 'git rebase' with
203203
CONFIGURATION
204204
-------------
205205

206-
rebase.stat::
207-
Whether to show a diffstat of what changed upstream since the last
208-
rebase. False by default.
209-
210-
rebase.autoSquash::
211-
If set to true enable `--autosquash` option by default.
212-
213-
rebase.autoStash::
214-
If set to true enable `--autostash` option by default.
215-
216-
rebase.missingCommitsCheck::
217-
If set to "warn", print warnings about removed commits in
218-
interactive mode. If set to "error", print the warnings and
219-
stop the rebase. If set to "ignore", no checking is
220-
done. "ignore" by default.
221-
222-
rebase.instructionFormat::
223-
Custom commit list format to use during an `--interactive` rebase.
206+
include::rebase-config.txt[]
224207

225208
OPTIONS
226209
-------

Documentation/rebase-config.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
rebase.stat::
2+
Whether to show a diffstat of what changed upstream since the last
3+
rebase. False by default.
4+
5+
rebase.autoSquash::
6+
If set to true enable `--autosquash` option by default.
7+
8+
rebase.autoStash::
9+
When set to true, automatically create a temporary stash entry
10+
before the operation begins, and apply it after the operation
11+
ends. This means that you can run rebase on a dirty worktree.
12+
However, use with care: the final stash application after a
13+
successful rebase might result in non-trivial conflicts.
14+
This option can be overridden by the `--no-autostash` and
15+
`--autostash` options of linkgit:git-rebase[1].
16+
Defaults to false.
17+
18+
rebase.missingCommitsCheck::
19+
If set to "warn", git rebase -i will print a warning if some
20+
commits are removed (e.g. a line was deleted), however the
21+
rebase will still proceed. If set to "error", it will print
22+
the previous warning and stop the rebase, 'git rebase
23+
--edit-todo' can then be used to correct the error. If set to
24+
"ignore", no checking is done.
25+
To drop a commit without warning or error, use the `drop`
26+
command in the todo list.
27+
Defaults to "ignore".
28+
29+
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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ static const char * const builtin_rebase_helper_usage[] = {
1212
int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
1313
{
1414
struct replay_opts opts = REPLAY_OPTS_INIT;
15-
int keep_empty = 0;
15+
unsigned flags = 0, keep_empty = 0;
16+
int abbreviate_commands = 0;
1617
enum {
17-
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
18-
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
18+
CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
19+
CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
20+
ADD_EXEC
1921
} command = 0;
2022
struct option options[] = {
2123
OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -27,19 +29,22 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
2729
OPT_CMDMODE(0, "make-script", &command,
2830
N_("make rebase script"), MAKE_SCRIPT),
2931
OPT_CMDMODE(0, "shorten-ids", &command,
30-
N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),
32+
N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
3133
OPT_CMDMODE(0, "expand-ids", &command,
32-
N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),
34+
N_("expand commit ids in the todo list"), EXPAND_OIDS),
3335
OPT_CMDMODE(0, "check-todo-list", &command,
3436
N_("check the todo list"), CHECK_TODO_LIST),
3537
OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
3638
N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
3739
OPT_CMDMODE(0, "rearrange-squash", &command,
3840
N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
41+
OPT_CMDMODE(0, "add-exec-commands", &command,
42+
N_("insert exec commands in todo list"), ADD_EXEC),
3943
OPT_END()
4044
};
4145

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

4449
opts.action = REPLAY_INTERACTIVE_REBASE;
4550
opts.allow_ff = 1;
@@ -48,21 +53,25 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
4853
argc = parse_options(argc, argv, NULL, options,
4954
builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
5055

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+
5160
if (command == CONTINUE && argc == 1)
5261
return !!sequencer_continue(&opts);
5362
if (command == ABORT && argc == 1)
5463
return !!sequencer_remove_state(&opts);
5564
if (command == MAKE_SCRIPT && argc > 1)
56-
return !!sequencer_make_script(keep_empty, stdout, argc, argv);
57-
if (command == SHORTEN_SHA1S && argc == 1)
58-
return !!transform_todo_ids(1);
59-
if (command == EXPAND_SHA1S && argc == 1)
60-
return !!transform_todo_ids(0);
65+
return !!sequencer_make_script(stdout, argc, argv, flags);
66+
if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
67+
return !!transform_todos(flags);
6168
if (command == CHECK_TODO_LIST && argc == 1)
6269
return !!check_todo_list();
6370
if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
6471
return !!skip_unnecessary_picks();
6572
if (command == REARRANGE_SQUASH && argc == 1)
6673
return !!rearrange_squash();
74+
if (command == ADD_EXEC && argc == 2)
75+
return !!sequencer_add_exec_commands(argv[1]);
6776
usage_with_options(builtin_rebase_helper_usage, options);
6877
}

git-rebase--interactive.sh

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -722,27 +722,6 @@ collapse_todo_ids() {
722722
git rebase--helper --shorten-ids
723723
}
724724

725-
# Add commands after a pick or after a squash/fixup series
726-
# in the todo list.
727-
add_exec_commands () {
728-
{
729-
first=t
730-
while read -r insn rest
731-
do
732-
case $insn in
733-
pick)
734-
test -n "$first" ||
735-
printf "%s" "$cmd"
736-
;;
737-
esac
738-
printf "%s %s\n" "$insn" "$rest"
739-
first=
740-
done
741-
printf "%s" "$cmd"
742-
} <"$1" >"$1.new" &&
743-
mv "$1.new" "$1"
744-
}
745-
746725
# Switch to the branch in $into and notify it in the reflog
747726
checkout_onto () {
748727
GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
@@ -982,7 +961,7 @@ fi
982961

983962
test -s "$todo" || echo noop >> "$todo"
984963
test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
985-
test -n "$cmd" && add_exec_commands "$todo"
964+
test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
986965

987966
todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
988967
todocount=${todocount##* }

0 commit comments

Comments
 (0)