Skip to contentSkip to conversation

rebase -i: add config to abbreviate command names

PATCH Superseded Liam Beguin 6 participants 70 messages Nov 27, 2017 – Dec 28, 2017 Documentation

lore
Share & tools
lore
#0 lore raw

cover rebase -i: add config to abbreviate command names

Hi everyone,

This series is a respin of something [1] I sent a few months ago. This time, instead of shell, It's based on top of the C implementation of the interactive rebase. I've also tried to address the comments that were left in the last thread.

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Changes since last time:
- Implement abbreviateCommands in rebase--helper
- Add note on the --[no-]autosquash option in rebase.autoSquash
- Add exec commands via the rebase--helper
- Add test case for rebase.abbreviateCommands

Liam Beguin (5):
Documentation: move rebase.* configs to new file
Documentation: use preferred name for the 'todo list' script rebase -i: add exec commands via the rebase--helper rebase -i: learn to abbreviate command names
t3404: add test case for abbreviated commands

 Documentation/config.txt        |  31 +------------
 Documentation/git-rebase.txt    |  19 +-------
 Documentation/rebase-config.txt |  51 ++++++++++++++++++++
 builtin/rebase--helper.c        |  17 +++++--
 git-rebase--interactive.sh      |  23 +--------
 sequencer.c                     | 100 ++++++++++++++++++++++++++++++++++------
 sequencer.h                     |   5 +-
 t/t3404-rebase-interactive.sh   |  32 +++++++++++++
 8 files changed, 186 insertions(+), 92 deletions(-)
 create mode 100644 Documentation/rebase-config.txt

[1] https://public-inbox.org/git/[email protected]/
--
2.15.0.321.g19bf2bb99cee.dirty

#1 lore raw

PATCH 1/5 Documentation: move rebase.* configs to new file

Move all rebase.* configuration variables to a separate file in order to remove duplicates, and include it in config.txt and git-rebase.txt. The new descriptions are mostly taken from config.txt as they are more verbose.

---
 Documentation/config.txt        | 31 +------------------------------
 Documentation/git-rebase.txt    | 19 +------------------
 Documentation/rebase-config.txt | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 48 deletions(-)
 create mode 100644 Documentation/rebase-config.txt
Documentation/config.txt +1 -30
index 531649cb40ea..e424b7de90b5 100644
@@ -2691,36 +2691,7 @@ push.recurseSubmodules::
 	is retained. You may override this configuration at time of push by
 	specifying '--recurse-submodules=check|on-demand|no'.
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	When set to true, automatically create a temporary stash entry
-	before the operation begins, and apply it after the operation
-	ends.  This means that you can run rebase on a dirty worktree.
-	However, use with care: the final stash application after a
-	successful rebase might result in non-trivial conflicts.
-	Defaults to false.
-
-rebase.missingCommitsCheck::
-	If set to "warn", git rebase -i will print a warning if some
-	commits are removed (e.g. a line was deleted), however the
-	rebase will still proceed. If set to "error", it will print
-	the previous warning and stop the rebase, 'git rebase
-	--edit-todo' can then be used to correct the error. If set to
-	"ignore", no checking is done.
-	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
-	Defaults to "ignore".
-
-rebase.instructionFormat::
-	A format string, as specified in linkgit:git-log[1], to be used for
-	the instruction list during an interactive rebase.  The format will automatically
-	have the long commit hash prepended to the format.
+include::rebase-config.txt[]
 
 receive.advertiseAtomic::
 	By default, git-receive-pack will advertise the atomic push
Documentation/git-rebase.txt +1 -18
index 3cedfb0fd22b..8a861c1e0d69 100644
@@ -203,24 +203,7 @@ Alternatively, you can undo the 'git rebase' with
 CONFIGURATION
 -------------
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	If set to true enable `--autostash` option by default.
-
-rebase.missingCommitsCheck::
-	If set to "warn", print warnings about removed commits in
-	interactive mode. If set to "error", print the warnings and
-	stop the rebase. If set to "ignore", no checking is
-	done. "ignore" by default.
-
-rebase.instructionFormat::
-	Custom commit list format to use during an `--interactive` rebase.
+include::rebase-config.txt[]
 
 OPTIONS
 -------
Documentation/rebase-config.txt new file +32 -0
new file mode 100644
index 000000000000..dba088d7c68f
@@ -0,0 +1,32 @@
+rebase.stat::
+	Whether to show a diffstat of what changed upstream since the last
+	rebase. False by default.
+
+rebase.autoSquash::
+	If set to true enable `--autosquash` option by default.
+
+rebase.autoStash::
+	When set to true, automatically create a temporary stash entry
+	before the operation begins, and apply it after the operation
+	ends.  This means that you can run rebase on a dirty worktree.
+	However, use with care: the final stash application after a
+	successful rebase might result in non-trivial conflicts.
+	This option can be overridden by the `--no-autostash` and
+	`--autostash` options of linkgit:git-rebase[1].
+	Defaults to false.
+
+rebase.missingCommitsCheck::
+	If set to "warn", git rebase -i will print a warning if some
+	commits are removed (e.g. a line was deleted), however the
+	rebase will still proceed. If set to "error", it will print
+	the previous warning and stop the rebase, 'git rebase
+	--edit-todo' can then be used to correct the error. If set to
+	"ignore", no checking is done.
+	To drop a commit without warning or error, use the `drop`
+	command in the todo-list.
+	Defaults to "ignore".
+
+rebase.instructionFormat::
+	A format string, as specified in linkgit:git-log[1], to be used for the
+	instruction list during an interactive rebase.  The format will
+	automatically have the long commit hash prepended to the format.
Signature · 1 line
2.15.0.321.g19bf2bb99cee.dirty
#2 lore raw

Re: [PATCH 1/5] Documentation: move rebase.* configs to new file

Hi Liam,

Quoted 1 line · Liam Beguin
 3 files changed, 34 insertions(+), 48 deletions(-)

Very nice!
Johannes

#3 lore raw

PATCH 2/5 Documentation: use preferred name for the 'todo list' script

In reply to Liam Beguin

Use "todo list" instead of "instruction list" or "todo-list" to reduce further confusion regarding the name of this script.

---
 Documentation/rebase-config.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/rebase-config.txt +2 -2
index dba088d7c68f..30ae08cb5a4b 100644
@@ -23,10 +23,10 @@ rebase.missingCommitsCheck::
 	--edit-todo' can then be used to correct the error. If set to
 	"ignore", no checking is done.
 	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
+	command in the todo list.
 	Defaults to "ignore".
 
 rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
-	instruction 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.
Signature · 1 line
2.15.0.321.g19bf2bb99cee.dirty
#4 lore raw

Re: [PATCH 2/5] Documentation: use preferred name for the 'todo list' script

Hi Liam,

Quoted 2 lines · Liam Beguin

Use "todo list" instead of "instruction list" or "todo-list" to reduce further confusion regarding the name of this script.

Makes sense,
Johannes

#5 lore raw

PATCH 3/5 rebase -i: add exec commands via the rebase--helper

In reply to Liam Beguin

Recent work on git-rebase--interactive aim to convert shell code to C. Even if this is most likely not a big performance enhacement, let's convert it too since a comming change to abbreviate command names requires it to be updated.

---
 builtin/rebase--helper.c   |  7 ++++++-
 git-rebase--interactive.sh | 23 +----------------------
 sequencer.c                | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 sequencer.h                |  1 +
 4 files changed, 54 insertions(+), 23 deletions(-)
builtin/rebase--helper.c +6 -1
index f8519363a393..9d94c874c5bb 100644
@@ -15,7 +15,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	int keep_empty = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
-		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
+		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
+		ADD_EXEC
 	} command = 0;
 	struct option options[] = {
 		OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -36,6 +37,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
 		OPT_CMDMODE(0, "rearrange-squash", &command,
 			N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+		OPT_CMDMODE(0, "add-exec", &command,
+			N_("insert exec commands in todo list"), ADD_EXEC),
 		OPT_END()
 	};
 
@@ -64,5 +67,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!skip_unnecessary_picks();
 	if (command == REARRANGE_SQUASH && argc == 1)
 		return !!rearrange_squash();
+	if (command == ADD_EXEC && argc == 2)
+		return !!add_exec_commands(argv[1]);
 	usage_with_options(builtin_rebase_helper_usage, options);
 }
git-rebase--interactive.sh +1 -22
index 437815669f00..760334d3a8b3 100644
@@ -722,27 +722,6 @@ collapse_todo_ids() {
 	git rebase--helper --shorten-ids
 }
 
-# Add commands after a pick or after a squash/fixup series
-# in the todo list.
-add_exec_commands () {
-	{
-		first=t
-		while read -r insn rest
-		do
-			case $insn in
-			pick)
-				test -n "$first" ||
-				printf "%s" "$cmd"
-				;;
-			esac
-			printf "%s %s\n" "$insn" "$rest"
-			first=
-		done
-		printf "%s" "$cmd"
-	} <"$1" >"$1.new" &&
-	mv "$1.new" "$1"
-}
-
 # Switch to the branch in $into and notify it in the reflog
 checkout_onto () {
 	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
@@ -982,7 +961,7 @@ fi
 
 test -s "$todo" || echo noop >> "$todo"
 test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
-test -n "$cmd" && add_exec_commands "$todo"
+test -n "$cmd" && git rebase--helper --add-exec "$cmd"
 
 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
 todocount=${todocount##* }
sequencer.c +46 -0

52 lines not on this page · raw message

sequencer.h +1 -0
index 6f3d3df82c0a..a2715e6c7589 100644
@@ -48,6 +48,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 int sequencer_make_script(int keep_empty, FILE *out,
 		int argc, const char **argv);
 
+int add_exec_commands(const char *command);
 int transform_todo_ids(int shorten_ids);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
Signature · 1 line
2.15.0.321.g19bf2bb99cee.dirty
#6 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 10 lines · Liam Beguin
sequencer.c +2 -0
index fa94ed652d2c..810b7850748e 100644
@@ -2492,6 +2492,52 @@ int sequencer_make_script(int keep_empty, FILE *out,
 	return 0;
 }
 
+int add_exec_commands(const char *command)
+{

As the name of a public function, it does not feel that this hints it strongly enough that it is from and a part of sequencer.c API.

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2500

Quoted 4 lines
sequencer.c +4 -0
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;

Having had to scan backwards while trying to see what the loop that uses this variable is doing and if it gets affected by things that happened before we entered the loop, I'd rather not to see 'first' initialized here, left unused for quite some time until the loop is entered. It would make it a lot easier to follow if it is declared and left uninitilized here, and set to 1 immediately before the for() loop that uses it.

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2510

Quoted 10 lines
sequencer.c +10 -0
+
+	strbuf_reset(&todo_list.buf);
+	fd = open(todo_file, O_RDONLY);
+	if (fd < 0)
+		return error_errno(_("could not open '%s'"), todo_file);
+	if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
+		close(fd);
+		return error(_("could not read '%s'."), todo_file);
+	}
+	close(fd);

Is this strbuf_read_file() written in longhand?

Quoted 8 lines
sequencer.c +8 -0
+	res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
+	if (res) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}
+
+	out = fopen(todo_file, "w");
+	if (!out) {

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2529

Quoted 10 lines
sequencer.c +10 -0
+		todo_list_release(&todo_list);
+		return error(_("unable to open '%s' for writing"), todo_file);
+	}
+	for (i = 0; i < todo_list.nr; i++) {
+		struct todo_item *item = todo_list.items + i;
+		int bol = item->offset_in_buf;
+		const char *p = todo_list.buf.buf + bol;
+		int eol = i + 1 < todo_list.nr ?
+			todo_list.items[i + 1].offset_in_buf :
+			todo_list.buf.len;

Should bol and eol be of type size_t instead? The values that get assigned to them from other structures are.

#7 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

Hi Junio,

Quoted 10 lines · Junio C Hamano
Quoted 8 lines · Liam Beguin
sequencer.c +0 -0
index fa94ed652d2c..810b7850748e 100644
@@ -2492,6 +2492,52 @@ int sequencer_make_script(int keep_empty, FILE *out,
 	return 0;
 }
 
Quoted 5 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 2 lines
sequencer.c +2 -0
+int add_exec_commands(const char *command)
+{

As the name of a public function, it does not feel that this hints it strongly enough that it is from and a part of sequencer.c API.

How about a "yes, and" instead? As in:

To further improve this patch, let's use the name sequencer_add_exec_commands() for this function because it is defined globally now.

Quoted 5 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2500

Quoted 4 lines
sequencer.c +4 -0
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;
Quoted 7 lines

Having had to scan backwards while trying to see what the loop that uses this variable is doing and if it gets affected by things that happened before we entered the loop, I'd rather not to see 'first' initialized here, left unused for quite some time until the loop is entered. It would make it a lot easier to follow if it is declared and left uninitilized here, and set to 1 immediately before the for() loop that uses it.

Funny, I would have assumed it the other way round: since "first" always has to be initialized with 1, I would have been surprised to see an explicit assignment much later than it is declared.

Quoted 11 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2510

Quoted 9 lines
sequencer.c +9 -0
+	strbuf_reset(&todo_list.buf);
+	fd = open(todo_file, O_RDONLY);
+	if (fd < 0)
+		return error_errno(_("could not open '%s'"), todo_file);
+	if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
+		close(fd);
+		return error(_("could not read '%s'."), todo_file);
+	}
+	close(fd);

Is this strbuf_read_file() written in longhand?

Ah, this is one of the downsides of patch-based review. If it was reviewed in context, you would have easily spotted that Liam was merely copy-editing my code that is still around.

And indeed, I had missed that function when I started to write the rebase--helper patches.

Quoted 13 lines
Quoted 13 lines
sequencer.c +13 -0
+	res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
+	if (res) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}
+
+	out = fopen(todo_file, "w");
+	if (!out) {
+		todo_list_release(&todo_list);
+		return error(_("unable to open '%s' for writing"), todo_file);
+	}
+	for (i = 0; i < todo_list.nr; i++) {
+		struct todo_item *item = todo_list.items + i;
Quoted 8 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2529

Quoted 5 lines
sequencer.c +5 -0
+		int bol = item->offset_in_buf;
+		const char *p = todo_list.buf.buf + bol;
+		int eol = i + 1 < todo_list.nr ?
+			todo_list.items[i + 1].offset_in_buf :
+			todo_list.buf.len;

Should bol and eol be of type size_t instead? The values that get assigned to them from other structures are.

While it won't matter in practice, this would be "more correct" to do, yes.

Ciao,
Dscho

#8 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

Quoted 8 lines · Johannes Schindelin
Quoted 2 lines

As the name of a public function, it does not feel that this hints it strongly enough that it is from and a part of sequencer.c API.

How about a "yes, and" instead? As in:

To further improve this patch, let's use the name sequencer_add_exec_commands() for this function because it is defined globally now.

I would do so when I have a single "this is strictly better" suggestion. In this case, I didn't, but somebody who does not have a "better suggestion" can still have a good sense of smell to tell something is "not right".

Quoted 13 lines
Quoted 5 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2500

Quoted 4 lines
sequencer.c +4 -0
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;
Quoted 7 lines

Having had to scan backwards while trying to see what the loop that uses this variable is doing and if it gets affected by things that happened before we entered the loop, I'd rather not to see 'first' initialized here, left unused for quite some time until the loop is entered. It would make it a lot easier to follow if it is declared and left uninitilized here, and set to 1 immediately before the for() loop that uses it.

Quoted 3 lines

Funny, I would have assumed it the other way round: since "first" always has to be initialized with 1, I would have been surprised to see an explicit assignment much later than it is declared.

Unfortunately that would force readers to see what happens before the loop to see if there are cases where first is incremented, and in this case there is not any.

#9 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

In reply to Junio C Hamano

Hi Junio,

Quoted 16 lines · Junio C Hamano

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 10 lines · Liam Beguin
sequencer.c +2 -0
index fa94ed652d2c..810b7850748e 100644
@@ -2492,6 +2492,52 @@ int sequencer_make_script(int keep_empty, FILE *out,
 	return 0;
 }
 
+int add_exec_commands(const char *command)
+{

As the name of a public function, it does not feel that this hints it strongly enough that it is from and a part of sequencer.c API.

Quoted 13 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2500

Quoted 4 lines
sequencer.c +4 -0
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;

Having had to scan backwards while trying to see what the loop that uses this variable is doing and if it gets affected by things that happened before we entered the loop, I'd rather not to see 'first' initialized here, left unused for quite some time until the loop is entered. It would make it a lot easier to follow if it is declared and left uninitilized here, and set to 1 immediately before the for() loop that uses it.

I agree that moving 'first = 1' just above the for() loop makes it more obvious. I'm not quite fond of how this is implemented, I just 'translated' the shell code and was hoping on maybe a few comments on how to improve it.

Quoted 4 lines
Quoted 4 lines
sequencer.c +4 -0
+
+	strbuf_reset(&todo_list.buf);
+	fd = open(todo_file, O_RDONLY);
+	if (fd < 0)
Quoted 8 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2510

Quoted 6 lines
sequencer.c +6 -0
+		return error_errno(_("could not open '%s'"), todo_file);
+	if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
+		close(fd);
+		return error(_("could not read '%s'."), todo_file);
+	}
+	close(fd);

Is this strbuf_read_file() written in longhand?

Thanks for pointing this out! I'll update. And as Johannes pointed out, I've copied this from surrounding functions, I'll add a preparatory path to update those too.

Quoted 14 lines
Quoted 14 lines
sequencer.c +13 -0
+	res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
+	if (res) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}
+
+	out = fopen(todo_file, "w");
+	if (!out) {
+		todo_list_release(&todo_list);
+		return error(_("unable to open '%s' for writing"), todo_file);
+	}
+	for (i = 0; i < todo_list.nr; i++) {
+		struct todo_item *item = todo_list.items + i;
Quoted 9 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2529

Quoted 5 lines
sequencer.c +5 -0
+		int bol = item->offset_in_buf;
+		const char *p = todo_list.buf.buf + bol;
+		int eol = i + 1 < todo_list.nr ?
+			todo_list.items[i + 1].offset_in_buf :
+			todo_list.buf.len;

Should bol and eol be of type size_t instead? The values that get assigned to them from other structures are.

Will do.
Thanks,

Liam

#10 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

In reply to Liam Beguin

Hi Liam,

could I ask for a favor? I'd like the oneline to start with

	rebase -i -x: ...

(this would help future me to realize what this commit touches already from the concise graph output I favor).

Quoted 4 lines · Liam Beguin

Recent work on git-rebase--interactive aim to convert shell code to C. Even if this is most likely not a big performance enhacement, let's convert it too since a comming change to abbreviate command names requires it to be updated.

Since Junio did not comment on the commit message: could you replace aim by aims, enhacement by enhancement and comming by coming?

builtin/rebase--helper.c int cmd_rebase__helper(int argc, const char **argv, const char *prefix) · line 41

Quoted 6 lines
builtin/rebase--helper.c +2 -0
@@ -36,6 +37,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
 		OPT_CMDMODE(0, "rearrange-squash", &command,
 			N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+		OPT_CMDMODE(0, "add-exec", &command,
+			N_("insert exec commands in todo list"), ADD_EXEC),

Maybe add-exec-commands? I know it is longer to type, but these options do not need to be typed interactively and the longer name would be consistent with the function name.

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2494

Quoted 8 lines
sequencer.c +0 -0
index fa94ed652d2c..810b7850748e 100644
@@ -2492,6 +2492,52 @@ int sequencer_make_script(int keep_empty, FILE *out,
 	return 0;
 }
 

As the code in add_exec_commands() may appear convoluted (why not simply append the command after any pick?), the original comment would be really nice here:

	/*
	 * Add commands after pick and (series of) squash/fixup commands
	 * in the todo list.
	 */

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2502

Quoted 8 lines
sequencer.c +8 -0
+int add_exec_commands(const char *command)
+{
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;
+
+	strbuf_reset(&todo_list.buf);

The todo_list.buf has been initialized already (via TODO_LIST_INIT), no need to reset it again.

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2510

Quoted 8 lines
sequencer.c +8 -0
+	fd = open(todo_file, O_RDONLY);
+	if (fd < 0)
+		return error_errno(_("could not open '%s'"), todo_file);
+	if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
+		close(fd);
+		return error(_("could not read '%s'."), todo_file);
+	}
+	close(fd);

As Junio pointed out so gently: there is a helper function that does this all very conveniently for us:

	if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
		return error_errno(_("could not read '%s'"), todo_file);

And as I realized looking at the surrounding code: you probably just inherited my inelegant code by copy-editing from another function in sequencer.c. Should you decide to add a preparatory patch to your patch series that converts these other callers, or even refactors all that code that reads the git-rebase-todo file and then parses it, I would be quite happy... :-) (although I would understand if you deemed this outside the purpose of your patch series).

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2516

Quoted 5 lines
sequencer.c +5 -0
+	res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
+	if (res) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}

The variable res is not really used here. Let's just put the parse_insn_buffer() call inside the if ().

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2529

Quoted 12 lines
sequencer.c +12 -0
+	out = fopen(todo_file, "w");
+	if (!out) {
+		todo_list_release(&todo_list);
+		return error(_("unable to open '%s' for writing"), todo_file);
+	}
+	for (i = 0; i < todo_list.nr; i++) {
+		struct todo_item *item = todo_list.items + i;
+		int bol = item->offset_in_buf;
+		const char *p = todo_list.buf.buf + bol;
+		int eol = i + 1 < todo_list.nr ?
+			todo_list.items[i + 1].offset_in_buf :
+			todo_list.buf.len;

This smells like another copy-edited snippet that originated from my brain, and I am not at all proud by the complexity I used there.

The function should also check for errors during writing. So how about something like this instead?

	struct strbuf *buf = &todo_list.buf;
	size_t offset = 0, command_len = strlen(command);
	int first = 1, i;
	struct todo_item *item;

	...

	/* insert <command> before every pick except the first one */
	for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++)
		if (item->command == TODO_PICK) {
			if (first)
				first = 0;
			else {
				strbuf_splice(buf,
					      item->offset_in_buf + offset, 0,
					      command, command_len);
				offset += command_len;
			}
		}

	/* append a final <command> */
	strbuf_complete_list(buf);
	strbuf_add(buf, command, command_len);

	i = write_message(buf->buf, buf->len, todo_file, 0);
	todo_list_release(&todo_list);
	return i;

Ciao,
Dscho

#11 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

Quoted 6 lines · Johannes Schindelin

could I ask for a favor? I'd like the oneline to start with

	rebase -i -x: ...

(this would help future me to realize what this commit touches already from the concise graph output I favor).

Excellent.

Quoted 7 lines
Quoted 4 lines

Recent work on git-rebase--interactive aim to convert shell code to C. Even if this is most likely not a big performance enhacement, let's convert it too since a comming change to abbreviate command names requires it to be updated.

Since Junio did not comment on the commit message: could you replace aim by aims, enhacement by enhancement and comming by coming?

Yes, I noticed them but don't mind me ;-) The above are all good fixes.

All suggestions in the remainder looked sensible. Thanks for a review.

#12 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

In reply to Johannes Schindelin

Hi Johannes,

Thanks for taking the time to review this.

Quoted 8 lines · Johannes Schindelin

Hi Liam,

could I ask for a favor? I'd like the oneline to start with

	rebase -i -x: ...

(this would help future me to realize what this commit touches already from the concise graph output I favor).

Sure, I'll update the commit subject.

Quoted 10 lines · Liam Beguin
Quoted 5 lines

Recent work on git-rebase--interactive aim to convert shell code to C. Even if this is most likely not a big performance enhacement, let's convert it too since a comming change to abbreviate command names requires it to be updated.

Since Junio did not comment on the commit message: could you replace aim by aims, enhacement by enhancement and comming by coming?

Ow.. sorry about that! I'll fix those and make sure to proofread better next time!

Quoted 11 lines

builtin/rebase--helper.c int cmd_rebase__helper(int argc, const char **argv, const char *prefix) · line 41

Quoted 7 lines
builtin/rebase--helper.c +2 -0
@@ -36,6 +37,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
 		OPT_CMDMODE(0, "rearrange-squash", &command,
 			N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+		OPT_CMDMODE(0, "add-exec", &command,
+			N_("insert exec commands in todo list"), ADD_EXEC),

Maybe add-exec-commands? I know it is longer to type, but these options do not need to be typed interactively and the longer name would be consistent with the function name.

Makes sense. It'll also be more consistent with the rest of the commands above.

Quoted 14 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2494

Quoted 9 lines
sequencer.c +0 -0
index fa94ed652d2c..810b7850748e 100644
@@ -2492,6 +2492,52 @@ int sequencer_make_script(int keep_empty, FILE *out,
 	return 0;
 }
 

As the code in add_exec_commands() may appear convoluted (why not simply append the command after any pick?), the original comment would be really nice here:

Quoted 5 lines
	/*
	 * Add commands after pick and (series of) squash/fixup commands
	 * in the todo list.
	 */

I'll make sure to include that comment.
The code is a bit convoluted as you say... I wanted to send it "as is" first to get comments and update based on feedback from the list.

I just realized we could maybe add exec instructions only after pick commands if we do add-exec-commands before rearrange-squash. I'll test it out.

Quoted 27 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2502

Quoted 8 lines
sequencer.c +8 -0
+int add_exec_commands(const char *command)
+{
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	int fd, res, i, first = 1;
+	FILE *out;
+
+	strbuf_reset(&todo_list.buf);

The todo_list.buf has been initialized already (via TODO_LIST_INIT), no need to reset it again.

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2510

Quoted 8 lines
sequencer.c +8 -0
+	fd = open(todo_file, O_RDONLY);
+	if (fd < 0)
+		return error_errno(_("could not open '%s'"), todo_file);
+	if (strbuf_read(&todo_list.buf, fd, 0) < 0) {
+		close(fd);
+		return error(_("could not read '%s'."), todo_file);
+	}
+	close(fd);

As Junio pointed out so gently: there is a helper function that does this all very conveniently for us:

	if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
		return error_errno(_("could not read '%s'"), todo_file);
Quoted 8 lines

And as I realized looking at the surrounding code: you probably just inherited my inelegant code by copy-editing from another function in sequencer.c. Should you decide to add a preparatory patch to your patch series that converts these other callers, or even refactors all that code that reads the git-rebase-todo file and then parses it, I would be quite happy... :-) (although I would understand if you deemed this outside the purpose of your patch series).

You guessed well, I mostly did copy-editing... I thought I found this code a little confusing because I'm not used to as much pointer gymnastics but it reassures me a bit to read this :-). I'll see if I can come up with a better solution.

Quoted 9 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2516

Quoted 5 lines
sequencer.c +5 -0
+	res = parse_insn_buffer(todo_list.buf.buf, &todo_list);
+	if (res) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}

The variable res is not really used here. Let's just put the parse_insn_buffer() call inside the if ().

Will do.

Quoted 39 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2529

Quoted 12 lines
sequencer.c +12 -0
+	out = fopen(todo_file, "w");
+	if (!out) {
+		todo_list_release(&todo_list);
+		return error(_("unable to open '%s' for writing"), todo_file);
+	}
+	for (i = 0; i < todo_list.nr; i++) {
+		struct todo_item *item = todo_list.items + i;
+		int bol = item->offset_in_buf;
+		const char *p = todo_list.buf.buf + bol;
+		int eol = i + 1 < todo_list.nr ?
+			todo_list.items[i + 1].offset_in_buf :
+			todo_list.buf.len;

This smells like another copy-edited snippet that originated from my brain, and I am not at all proud by the complexity I used there.

The function should also check for errors during writing. So how about something like this instead?

	struct strbuf *buf = &todo_list.buf;
	size_t offset = 0, command_len = strlen(command);
	int first = 1, i;
	struct todo_item *item;

	...

	/* insert <command> before every pick except the first one */
	for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++)
		if (item->command == TODO_PICK) {
			if (first)
				first = 0;
			else {
				strbuf_splice(buf,
					      item->offset_in_buf + offset, 0,
					      command, command_len);
				offset += command_len;
			}
		}
Quoted 8 lines
	/* append a final <command> */
	strbuf_complete_list(buf);
	strbuf_add(buf, command, command_len);

	i = write_message(buf->buf, buf->len, todo_file, 0);
	todo_list_release(&todo_list);
	return i;

I'll see how I can include this if calling add-exec-commands before rearrange-squash works. But it definitely is lighter to read.

Quoted 3 lines

Ciao,
Dscho

Thanks again,

Liam

#13 lore raw

Re: [PATCH 3/5] rebase -i: add exec commands via the rebase--helper

Hi Liam,

Quoted 2 lines · liam Beguin

I just realized we could maybe add exec instructions only after pick commands if we do add-exec-commands before rearrange-squash.

That won't work, because the squash/fixup commands are pick commands before rearrange-squash. So you'd add one unwanted exec per squash/fixup...

Ciao,
Dscho

#14 lore raw

PATCH 4/5 rebase -i: learn to abbreviate command names

In reply to Liam Beguin

git rebase -i already know how to interpret single-letter command names. Teach it to generate the todo list with these same abbreviated names.

---
 Documentation/rebase-config.txt | 19 +++++++++++++++
 builtin/rebase--helper.c        | 10 +++++---
 sequencer.c                     | 54 +++++++++++++++++++++++++++++------------
 sequencer.h                     |  4 +--
 4 files changed, 66 insertions(+), 21 deletions(-)
Documentation/rebase-config.txt +19 -0
index 30ae08cb5a4b..0820b60f6e12 100644
@@ -30,3 +30,22 @@ rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
 	todo list during an interactive rebase.  The format will
 	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.
builtin/rebase--helper.c +6 -4
index 9d94c874c5bb..7b1fe825a877 100644
@@ -12,7 +12,7 @@ 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;
-	int keep_empty = 0;
+	int keep_empty = 0, abbreviate_commands = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
 		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH,
@@ -43,6 +43,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	};
 
 	git_config(git_default_config, NULL);
+	git_config_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
 
 	opts.action = REPLAY_INTERACTIVE_REBASE;
 	opts.allow_ff = 1;
@@ -56,11 +57,12 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	if (command == ABORT && argc == 1)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
+		return !!sequencer_make_script(keep_empty, abbreviate_commands,
+					       stdout, argc, argv);
 	if (command == SHORTEN_SHA1S && argc == 1)
-		return !!transform_todo_ids(1);
+		return !!transform_todo_ids(1, abbreviate_commands);
 	if (command == EXPAND_SHA1S && argc == 1)
-		return !!transform_todo_ids(0);
+		return !!transform_todo_ids(0, abbreviate_commands);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c +39 -15

101 lines not on this page · raw message

sequencer.h +2 -2
index a2715e6c7589..cee8394673de 100644
@@ -45,11 +45,11 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
-int sequencer_make_script(int keep_empty, FILE *out,
+int sequencer_make_script(int keep_empty, int abbreviate_commands, FILE *out,
 		int argc, const char **argv);
 
 int add_exec_commands(const char *command);
-int transform_todo_ids(int shorten_ids);
+int transform_todo_ids(int shorten_ids, int abbreviate_commands);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);
Signature · 1 line
2.15.0.321.g19bf2bb99cee.dirty
#15 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

builtin/rebase--helper.c int cmd_rebase__helper(int argc, const char **argv, const char *prefix) · line 61

Quoted 4 lines · Liam Beguin
builtin/rebase--helper.c +2 -1
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
+		return !!sequencer_make_script(keep_empty, abbreviate_commands,
+					       stdout, argc, argv);

This suggests that a preliminary clean-up to update the parameter list of sequencer_make_script() is in order just before this step. How about making it like so, perhaps:

int sequencer_make_script(FILE *out, int ac, char **av, unsigned flags)

where keep_empty becomes just one bit in that flags word. Then another bit in the same flags word can be used for this option.

Otherwise, every time somebody comes up with a new and shiny feature for the function, we'd end up adding more to its parameter list.

#16 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

Hi Junio,

Quoted 11 lines · Junio C Hamano

builtin/rebase--helper.c int cmd_rebase__helper(int argc, const char **argv, const char *prefix) · line 61

Quoted 4 lines · Liam Beguin
builtin/rebase--helper.c +2 -1
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
+		return !!sequencer_make_script(keep_empty, abbreviate_commands,
+					       stdout, argc, argv);

This suggests that a preliminary clean-up to update the parameter list of sequencer_make_script() is in order just before this step. How about making it like so, perhaps:

Quoted 8 lines

int sequencer_make_script(FILE *out, int ac, char **av, unsigned flags)

where keep_empty becomes just one bit in that flags word. Then another bit in the same flags word can be used for this option.

Otherwise, every time somebody comes up with a new and shiny feature for the function, we'd end up adding more to its parameter list.

Will do.
Thanks,

Liam

#17 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

In reply to Liam Beguin

Hi Liam,

Quoted 8 lines · Liam Beguin
Documentation/rebase-config.txt +0 -0
index 30ae08cb5a4b..0820b60f6e12 100644
@@ -30,3 +30,22 @@ rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
 	todo list during an interactive rebase.  The format will
 	automatically have the long commit hash prepended to the format.

Documentation/rebase-config.txt rebase.instructionFormat:: · line 42

Quoted 10 lines
Documentation/rebase-config.txt +10 -0
+
+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
+	...
+-------------------------------------------

I *think* that AsciiDoc will render this in a different way from what we want, but I am not an AsciiDoc expert. In my hands, I always had to add a single + in an otherwise empty line to start a new indented paragraph *and then continue with non-indented lines*.

sequencer.c static const char *command_to_string(const enum todo_command command) · line 802

Quoted 13 lines
sequencer.c +5 -0
index 810b7850748e..aa01e8bd9280 100644
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command 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 -1;

My initial reaction was: should we return comment_line_char instead of -1 here? Only after reading how this is called did I realize that the idea is to use full command names if there is no abbreviation. Not sure whether this is worth a code comment. What do you think?

Quoted 14 lines
sequencer.c +3 -1
+}
+
 static int is_noop(const enum todo_command command)
 {
 	return TODO_NOOP <= command;
@@ -1242,15 +1249,16 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 		return 0;
 	}
 
-	for (i = 0; i < TODO_COMMENT; i++)
+	for (i = 0; i < TODO_COMMENT; i++) {
 		if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
 			item->command = i;
 			break;

sequencer.c static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) · line 1264

Quoted 10 lines
sequencer.c +2 -1
-		} else if (bol[1] == ' ' && *bol == todo_command_info[i].c) {
+		} else if (bol[1] == ' ' && *bol == command_to_char(i)) {
 			bol++;
 			item->command = i;
 			break;
 		}
+	}
 	if (i >= TODO_COMMENT)
 		return -1;
 

I would prefer this hunk to be skipped, it does not really do anything if I understand correctly.

Quoted 12 lines
sequencer.c +2 -2
@@ -2443,8 +2451,8 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
 	strbuf_release(&sob);
 }
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv)
+int sequencer_make_script(int keep_empty, int abbreviate_commands, FILE *out,
+			  int argc, const char **argv)
 {
 	char *format = NULL;
 	struct pretty_print_context pp = {0};

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 7 lines
sequencer.c +3 -1
@@ -2483,7 +2491,9 @@ int sequencer_make_script(int keep_empty, FILE *out,
 		strbuf_reset(&buf);
 		if (!keep_empty && is_original_commit_empty(commit))
 			strbuf_addf(&buf, "%c ", comment_line_char);
-		strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
+		strbuf_addf(&buf, "%s %s ",
+			    abbreviate_commands ? "p" : "pick",
+			    oid_to_hex(&commit->object.oid));

I guess the compiler will optimize this code so that the conditional is evaluated only once. Not that this is performance critical ;-)

Quoted 42 lines
sequencer.c +14 -10
 		pretty_print_commit(&pp, commit, &buf);
 		strbuf_addch(&buf, '\n');
 		fputs(buf.buf, out);
@@ -2539,7 +2549,7 @@ int add_exec_commands(const char *command)
 	return 0;
 }
 
-int transform_todo_ids(int shorten_ids)
+int transform_todo_ids(int shorten_ids, int abbreviate_commands)
 {
 	const char *todo_file = rebase_path_todo();
 	struct todo_list todo_list = TODO_LIST_INIT;
@@ -2575,19 +2585,33 @@ int transform_todo_ids(int shorten_ids)
 			todo_list.items[i + 1].offset_in_buf :
 			todo_list.buf.len;
 
-		if (item->command >= TODO_EXEC && item->command != TODO_DROP)
-			fwrite(p, eol - bol, 1, out);
-		else {
+		if (item->command >= TODO_EXEC && item->command != TODO_DROP) {
+			if (!abbreviate_commands || command_to_char(item->command) < 0) {
+				fwrite(p, eol - bol, 1, out);
+			} else {
+				const char *end_of_line = strchrnul(p, '\n');
+				p += strspn(p, " \t"); /* skip whitespace */
+				p += strcspn(p, " \t"); /* skip command */
+				fprintf(out, "%c%.*s\n",
+					command_to_char(item->command),
+					(int)(end_of_line - p), p);
+			}
+		} else {
 			const char *id = shorten_ids ?
 				short_commit_name(item->commit) :
 				oid_to_hex(&item->commit->object.oid);
-			int len;
 
-			p += strspn(p, " \t"); /* left-trim command */
-			len = strcspn(p, " \t"); /* length of command */
-
-			fprintf(out, "%.*s %s %.*s\n",
-				len, p, id, item->arg_len, item->arg);
+			if (abbreviate_commands) {

sequencer.c int transform_todo_ids(int shorten_ids) · line 2614

Quoted 10 lines
sequencer.c +10 -0
+				fprintf(out, "%c %s %.*s\n",
+					command_to_char(item->command),
+					id, item->arg_len, item->arg);
+			} else {
+				int len;
+				p += strspn(p, " \t"); /* left-trim command */
+				len = strcspn(p, " \t"); /* length of command */
+				fprintf(out, "%.*s %s %.*s\n",
+					len, p, id, item->arg_len, item->arg);
+			}

This hunk changes indentation quite a bit, therefore it is a bit harder to read than necessary (and the resulting code, too, as it is more smooshed against the 80-column boundary on the right).

How about this instead:

- if (item->command >= TODO_EXEC && item->command != TODO_DROP)
+ if (abbreviate_commands && command_to_char(item->command)) {
+ const char *id = shorten_ids ?
+ short_commit_name(item->commit) :
+ oid_to_hex(&item->commit->object.oid);
+ fprintf(out, "%c %s %.*s\n",
+ command_to_char(item->command),
+ id, item->arg_len, item->arg);
+ } else if (item->command >= TODO_EXEC &&
+ item->command != TODO_DROP)

i.e. test first for the short and sweet case that we want (and can) abbreviate the command, otherwise keep the code as before?

Ciao,
Dscho

#18 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

Quoted 6 lines · Johannes Schindelin
Quoted 6 lines
(quoted diff) +6 -0
+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
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	p fa1afe1 The oneline of the next commit
+	...
+-------------------------------------------

I *think* that AsciiDoc will render this in a different way from what we want, but I am not an AsciiDoc expert. In my hands, I always had to add a single + in an otherwise empty line to start a new indented paragraph *and then continue with non-indented lines*.

Good catch. Interestingly enough, my asciidoc seems to render this as desired for the docbook/roff version, but has screwed-up indentation for the HTML version.

Fixing it as you suggest makes it look good in both (and I think you can never go wrong with "+"-continuation, aside from making the source a bit uglier).

Squashable patch below for convenience, since I did try it.

-Peff

Documentation/rebase-config.txt +6 -5
index 0820b60f6e..42e1ba7575 100644
@@ -34,18 +34,19 @@ rebase.instructionFormat::
 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:
-
++
+instead of:
++
 -------------------------------------------
 	pick deadbee The oneline of the commit
 	pick fa1afe1 The oneline of the next commit
 	...
 -------------------------------------------
-	Defaults to false.
++
+Defaults to false.
#19 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

Hi Peff,

Thanks for taking the time to test this, I'll squash that patch in v2.

Quoted 49 lines · Jeff King
Quoted 6 lines · Johannes Schindelin
Quoted 6 lines
(quoted diff) +6 -0
+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
Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +3 -0
+	p fa1afe1 The oneline of the next commit
+	...
+-------------------------------------------

I *think* that AsciiDoc will render this in a different way from what we want, but I am not an AsciiDoc expert. In my hands, I always had to add a single + in an otherwise empty line to start a new indented paragraph *and then continue with non-indented lines*.

Good catch. Interestingly enough, my asciidoc seems to render this as desired for the docbook/roff version, but has screwed-up indentation for the HTML version.

Fixing it as you suggest makes it look good in both (and I think you can never go wrong with "+"-continuation, aside from making the source a bit uglier).

Squashable patch below for convenience, since I did try it.

(quoted diff) +0 -1
-Peff
Documentation/rebase-config.txt +2 -4
index 0820b60f6e..42e1ba7575 100644
@@ -34,18 +34,19 @@ rebase.instructionFormat::
 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:
-
++

Documentation/rebase-config.txt rebase.instructionFormat:: · line 52

Quoted 10 lines
Documentation/rebase-config.txt +4 -1
+instead of:
++
 -------------------------------------------
 	pick deadbee The oneline of the commit
 	pick fa1afe1 The oneline of the next commit
...
 -------------------------------------------
-	Defaults to false.
++
+Defaults to false.

Liam

#20 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

In reply to Johannes Schindelin

Hi Johannes,

Quoted 36 lines · Johannes Schindelin

Hi Liam,

Quoted 8 lines · Liam Beguin
Documentation/rebase-config.txt +0 -0
index 30ae08cb5a4b..0820b60f6e12 100644
@@ -30,3 +30,22 @@ rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
 	todo list during an interactive rebase.  The format will
 	automatically have the long commit hash prepended to the format.

Documentation/rebase-config.txt rebase.instructionFormat:: · line 42

Quoted 10 lines
Documentation/rebase-config.txt +10 -0
+
+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
+	...
+-------------------------------------------

I *think* that AsciiDoc will render this in a different way from what we want, but I am not an AsciiDoc expert. In my hands, I always had to add a single + in an otherwise empty line to start a new indented paragraph *and then continue with non-indented lines*.

Quoted 8 lines
sequencer.c +0 -0
index 810b7850748e..aa01e8bd9280 100644
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command command)
 	die("Unknown command: %d", command);
 }
 
Quoted 11 lines

sequencer.c static const char *command_to_string(const enum todo_command command) · line 802

Quoted 5 lines
sequencer.c +5 -0
+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 -1;

My initial reaction was: should we return comment_line_char instead of -1 here? Only after reading how this is called did I realize that the idea is to use full command names if there is no abbreviation. Not sure whether this is worth a code comment. What do you think?

I guess it probably deserves a comment!

Quoted 19 lines
Quoted 19 lines
sequencer.c +4 -2
+}
+
 static int is_noop(const enum todo_command command)
 {
 	return TODO_NOOP <= command;
@@ -1242,15 +1249,16 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 		return 0;
 	}
 
-	for (i = 0; i < TODO_COMMENT; i++)
+	for (i = 0; i < TODO_COMMENT; i++) {
 		if (skip_prefix(bol, todo_command_info[i].str, &bol)) {
 			item->command = i;
 			break;
-		} else if (bol[1] == ' ' && *bol == todo_command_info[i].c) {
+		} else if (bol[1] == ' ' && *bol == command_to_char(i)) {
 			bol++;
 			item->command = i;
 			break;
Quoted 8 lines

sequencer.c static int parse_insn_line(struct todo_item *item, const char *bol, char *eol) · line 1264

Quoted 5 lines
sequencer.c +1 -0
 		}
+	}
 	if (i >= TODO_COMMENT)
 		return -1;
 

I would prefer this hunk to be skipped, it does not really do anything if I understand correctly.

Ok, I was not so sure about this but thought it was probably worth it. Will remove.

Quoted 15 lines
Quoted 15 lines
sequencer.c +2 -2
@@ -2443,8 +2451,8 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
 	strbuf_release(&sob);
 }
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv)
+int sequencer_make_script(int keep_empty, int abbreviate_commands, FILE *out,
+			  int argc, const char **argv)
 {
 	char *format = NULL;
 	struct pretty_print_context pp = {0};
@@ -2483,7 +2491,9 @@ int sequencer_make_script(int keep_empty, FILE *out,
 		strbuf_reset(&buf);
 		if (!keep_empty && is_original_commit_empty(commit))
Quoted 8 lines

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 5 lines
sequencer.c +3 -1
 			strbuf_addf(&buf, "%c ", comment_line_char);
-		strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
+		strbuf_addf(&buf, "%s %s ",
+			    abbreviate_commands ? "p" : "pick",
+			    oid_to_hex(&commit->object.oid));

I guess the compiler will optimize this code so that the conditional is evaluated only once. Not that this is performance critical ;-)

Is your guess enough? :-) If not, how could I make sure this is optimized? Should I do that check before the while() loop?

Quoted 71 lines
Quoted 43 lines
sequencer.c +14 -10
 		pretty_print_commit(&pp, commit, &buf);
 		strbuf_addch(&buf, '\n');
 		fputs(buf.buf, out);
@@ -2539,7 +2549,7 @@ int add_exec_commands(const char *command)
 	return 0;
 }
 
-int transform_todo_ids(int shorten_ids)
+int transform_todo_ids(int shorten_ids, int abbreviate_commands)
 {
 	const char *todo_file = rebase_path_todo();
 	struct todo_list todo_list = TODO_LIST_INIT;
@@ -2575,19 +2585,33 @@ int transform_todo_ids(int shorten_ids)
 			todo_list.items[i + 1].offset_in_buf :
 			todo_list.buf.len;
 
-		if (item->command >= TODO_EXEC && item->command != TODO_DROP)
-			fwrite(p, eol - bol, 1, out);
-		else {
+		if (item->command >= TODO_EXEC && item->command != TODO_DROP) {
+			if (!abbreviate_commands || command_to_char(item->command) < 0) {
+				fwrite(p, eol - bol, 1, out);
+			} else {
+				const char *end_of_line = strchrnul(p, '\n');
+				p += strspn(p, " \t"); /* skip whitespace */
+				p += strcspn(p, " \t"); /* skip command */
+				fprintf(out, "%c%.*s\n",
+					command_to_char(item->command),
+					(int)(end_of_line - p), p);
+			}
+		} else {
 			const char *id = shorten_ids ?
 				short_commit_name(item->commit) :
 				oid_to_hex(&item->commit->object.oid);
-			int len;
 
-			p += strspn(p, " \t"); /* left-trim command */
-			len = strcspn(p, " \t"); /* length of command */
-
-			fprintf(out, "%.*s %s %.*s\n",
-				len, p, id, item->arg_len, item->arg);
+			if (abbreviate_commands) {

sequencer.c int transform_todo_ids(int shorten_ids) · line 2614

Quoted 10 lines
sequencer.c +10 -0
+				fprintf(out, "%c %s %.*s\n",
+					command_to_char(item->command),
+					id, item->arg_len, item->arg);
+			} else {
+				int len;
+				p += strspn(p, " \t"); /* left-trim command */
+				len = strcspn(p, " \t"); /* length of command */
+				fprintf(out, "%.*s %s %.*s\n",
+					len, p, id, item->arg_len, item->arg);
+			}

This hunk changes indentation quite a bit, therefore it is a bit harder to read than necessary (and the resulting code, too, as it is more smooshed against the 80-column boundary on the right).

How about this instead:

(quoted diff) +9 -1
-		if (item->command >= TODO_EXEC && item->command != TODO_DROP)
+		if (abbreviate_commands && command_to_char(item->command)) {
+			const char *id = shorten_ids ?
+				short_commit_name(item->commit) :
+				oid_to_hex(&item->commit->object.oid);
+			fprintf(out, "%c %s %.*s\n",
+				command_to_char(item->command),
+				id, item->arg_len, item->arg);
+		} else if (item->command >= TODO_EXEC &&
+			 item->command != TODO_DROP)
Quoted 2 lines

i.e. test first for the short and sweet case that we want (and can) abbreviate the command, otherwise keep the code as before?

That looks quite better! I'll update.

Quoted 4 lines

Ciao,
Dscho

Thanks,
Liam

#21 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

Hi Liam,

Quoted 16 lines · liam Beguin
Quoted 14 lines · Johannes Schindelin

sequencer.c int sequencer_make_script(int keep_empty, FILE *out, · line 2496

Quoted 8 lines · Liam Beguin
sequencer.c +3 -1
@@ -2483,7 +2491,9 @@ int sequencer_make_script(int keep_empty, FILE *out,
 		strbuf_reset(&buf);
 		if (!keep_empty && is_original_commit_empty(commit))
 			strbuf_addf(&buf, "%c ", comment_line_char);
-		strbuf_addf(&buf, "pick %s ", oid_to_hex(&commit->object.oid));
+		strbuf_addf(&buf, "%s %s ",
+			    abbreviate_commands ? "p" : "pick",
+			    oid_to_hex(&commit->object.oid));

I guess the compiler will optimize this code so that the conditional is evaluated only once. Not that this is performance critical ;-)

Quoted 2 lines

Is your guess enough? :-) If not, how could I make sure this is optimized? Should I do that check before the while() loop?

I am a fan of not relying too heavily on compiler optimization and e.g. extract code from loops when it does not need to be evaluated every single iteration. In this case:

	const char *pick = abbreviate_commands ? "p" : "pick";
	...
		strbuf_addf(&buf, "%s %s ", pick,
			    oid_to_hex(&commit->object.oid));

But given Junio's comment that the assignment of first was too far away from the line where it is used for his taste, I guess he will argue (once again) the exact opposite of me.

Ciao,
Dscho

#22 lore raw

Re: [PATCH 4/5] rebase -i: learn to abbreviate command names

Quoted 8 lines · Johannes Schindelin

I am a fan of not relying too heavily on compiler optimization and e.g. extract code from loops when it does not need to be evaluated every single iteration. In this case:

	const char *pick = abbreviate_commands ? "p" : "pick";
	...
		strbuf_addf(&buf, "%s %s ", pick,
			    oid_to_hex(&commit->object.oid));

I would have called that variable "pick_cmd", not just "pick"; this preference is minor enough that I would probably reject a patch to rename from one to the other if the above were already part of the existing codebase.

I find that the code suggested above easier to follow, simply because it expresses clearly the flow of thought and that flow of thought matches how I personally think: we decide how this command is spelled in the output upfront, and then use that same spelling consistently throughout the loop.

I do not think it matters performance-wise either way, but I value how easy it is to follow the code for humans, and it matters much more in the longer run. If a compiler does a poor job, we can eventually notice and help it to produce better code that still does what we wanted it to do (or it may not be performance critical and we may not even notice). If a code is hard to follow, on the other hand, what we wanted it to do in the first place becomes harder to figure out.

#23 lore raw

PATCH 5/5 t3404: add test case for abbreviated commands

In reply to Liam Beguin

Make sure the todo list ends up using single-letter command abbreviations when the rebase.abbreviateCommands is enabled. This configuration options should not change anything else.

---
 t/t3404-rebase-interactive.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
t/t3404-rebase-interactive.sh +32 -0
index 6a82d1ed876d..e460ebde3393 100755
@@ -1260,6 +1260,38 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 	test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'prepare rebase.abbreviateCommands' '
+	reset_rebase &&
+	git checkout -b abbrevcmd master &&
+	test_commit "first" file1.txt "first line" first &&
+	test_commit "second" file1.txt "another line" second &&
+	test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+	test_commit "squash! second" file1.txt "another line here" second_squash
+'
+
+cat >expected <<EOF &&
+p $(git rev-list --abbrev-commit -1 first) first
+f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+x git show HEAD
+p $(git rev-list --abbrev-commit -1 second) second
+s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+x git show HEAD
+EOF
+
+test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
+	test_when_finished "
+		git checkout master &&
+		test_might_fail git branch -D abbrevcmd &&
+		test_might_fail git rebase --abort
+	" &&
+	git checkout abbrevcmd &&
+	set_cat_todo_editor &&
+	test_config rebase.abbreviateCommands true &&
+	test_must_fail git rebase -i --exec "git show HEAD" \
+		--autosquash master >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'static check of bad command' '
 	rebase_setup_and_clean bad-cmd &&
 	set_fake_editor &&
Signature · 1 line
2.15.0.321.g19bf2bb99cee.dirty
#24 lore raw

Re: [PATCH 5/5] t3404: add test case for abbreviated commands

Quoted 24 lines · Liam Beguin

Make sure the todo list ends up using single-letter command abbreviations when the rebase.abbreviateCommands is enabled. This configuration options should not change anything else.

---
 t/t3404-rebase-interactive.sh | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
t/t3404-rebase-interactive.sh +7 -0
index 6a82d1ed876d..e460ebde3393 100755
@@ -1260,6 +1260,38 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 	test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'prepare rebase.abbreviateCommands' '
+	reset_rebase &&
+	git checkout -b abbrevcmd master &&
+	test_commit "first" file1.txt "first line" first &&
+	test_commit "second" file1.txt "another line" second &&
+	test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+	test_commit "squash! second" file1.txt "another line here" second_squash

t/t3404-rebase-interactive.sh test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' · line 1279

Quoted 10 lines
t/t3404-rebase-interactive.sh +10 -0
+'
+
+cat >expected <<EOF &&
+p $(git rev-list --abbrev-commit -1 first) first
+f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+x git show HEAD
+p $(git rev-list --abbrev-commit -1 second) second
+s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+x git show HEAD
+EOF

Please have this cat inside and at the beginning of the next test_expect_success, preferably indented with HT to align with other commands (adding '-' to the opening of your here-document makes the shell strip all leading HTs from the here-document), like this:

	test_expect_success 'respects rebase....' '
		cat expect <<-EOF &&
		p $(git rev-list ...)
		f $(git rev-list ...)
		...
		EOF
		test_when_finished "
                	...
		" &&
		...
		test_cmp expect actual
	'
#25 lore raw

Re: [PATCH 5/5] t3404: add test case for abbreviated commands

In reply to Liam Beguin

Hi Liam,

Quoted 3 lines · Liam Beguin

Make sure the todo list ends up using single-letter command abbreviations when the rebase.abbreviateCommands is enabled. This configuration options should not change anything else.

Makes sense. As to the diff:

Quoted 6 lines
t/t3404-rebase-interactive.sh +0 -0
index 6a82d1ed876d..e460ebde3393 100755
@@ -1260,6 +1260,38 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 	test B = $(git cat-file commit HEAD^ | sed -ne \$p)

t/t3404-rebase-interactive.sh test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' · line 1270

Quoted 10 lines
t/t3404-rebase-interactive.sh +8 -0
 '
 
+test_expect_success 'prepare rebase.abbreviateCommands' '
+	reset_rebase &&
+	git checkout -b abbrevcmd master &&
+	test_commit "first" file1.txt "first line" first &&
+	test_commit "second" file1.txt "another line" second &&
+	test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+	test_commit "squash! second" file1.txt "another line here" second_squash
+'

In addition to Junio's suggestion to include the "expected" block in the next test case, I would be in favor of combining all the new code in a single test case.

Also, I think that the test_commit calls can be simplified to:

	test_commit first &&
	test_commit second &&
	test_commit "fixup! first" first A dummy1 &&
	test_commit "squash! second" second B dummy2 &&

t/t3404-rebase-interactive.sh test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' · line 1273

Quoted 2 lines
t/t3404-rebase-interactive.sh +2 -0
+cat >expected <<EOF &&
+p $(git rev-list --abbrev-commit -1 first) first

Maybe $(git rev-parse --short HEAD~3)?

Quoted 10 lines
t/t3404-rebase-interactive.sh +10 -0
+f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+x git show HEAD
+p $(git rev-list --abbrev-commit -1 second) second
+s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+x git show HEAD
+EOF
+
+test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
+	test_when_finished "
+		git checkout master &&

t/t3404-rebase-interactive.sh test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' ' · line 1293

Quoted 10 lines
t/t3404-rebase-interactive.sh +10 -0
+		test_might_fail git branch -D abbrevcmd &&
+		test_might_fail git rebase --abort
+	" &&
+	git checkout abbrevcmd &&
+	set_cat_todo_editor &&
+	test_config rebase.abbreviateCommands true &&
+	test_must_fail git rebase -i --exec "git show HEAD" \
+		--autosquash master >actual &&
+	test_cmp expected actual
+'

Otherwise, it looks good!

Thank you for staying on the ball and getting this patch series updated.

Ciao,
Dscho

#26 lore raw
In reply to Liam Beguin
Quoted 6 lines · Liam Beguin

Liam Beguin (5):
Documentation: move rebase.* configs to new file
Documentation: use preferred name for the 'todo list' script rebase -i: add exec commands via the rebase--helper rebase -i: learn to abbreviate command names
t3404: add test case for abbreviated commands

I didn't send any comment on [1&2/5] but they both looked good.

#27 lore raw

Hi Junio,

Quoted 11 lines · Junio C Hamano
Quoted 6 lines · Liam Beguin

Liam Beguin (5):
Documentation: move rebase.* configs to new file
Documentation: use preferred name for the 'todo list' script rebase -i: add exec commands via the rebase--helper rebase -i: learn to abbreviate command names
t3404: add test case for abbreviated commands

I didn't send any comment on [1&2/5] but they both looked good.

Thanks for reviewing this. I'll go through your comments and post a v2 shortly.

Thanks,
Liam

PS: I'm very sorry if someone received a few copies of this, I'm having issues with my MUA! Hopefully, I've got it right this time...

#28 lore raw

v2 cover rebase -i: add config to abbreviate command names

In reply to Liam Beguin

Hi everyone,

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Changes in V2:
- Refactor and rename 'transform_todo_ids'
- Replace SHA-1 by OID in rebase--helper.c
- Update todo list related functions to take a generic 'flags' parameter
- Rename 'add_exec_commands' function to 'sequencer_add_exec_commands'
- Rename 'add-exec' option to 'add-exec-commands'
- Use 'strbur_read_file' instead of rewriting it
- Make 'command_to_char' return 'comment_char_line' if no single-letter command name is defined
- Combine both tests into a single test case
- Update commit messages

Liam Beguin (9):
Documentation: move rebase.* configs to new file
Documentation: use preferred name for the 'todo list' script rebase -i: set commit to null in exec commands rebase -i: refactor transform_todo_ids
rebase -i: replace reference to sha1 with oid rebase -i: update functions to use a flags parameter rebase -i -x: add exec commands via the rebase--helper rebase -i: learn to abbreviate command names
t3404: add test case for abbreviated commands

 Documentation/config.txt        |  31 +-------
 Documentation/git-rebase.txt    |  19 +----
 Documentation/rebase-config.txt |  52 +++++++++++++
 builtin/rebase--helper.c        |  29 +++++---
 git-rebase--interactive.sh      |  23 +-----
 sequencer.c                     | 126 +++++++++++++++++++++-----------
 sequencer.h                     |  10 ++-
 t/t3404-rebase-interactive.sh   |  22 ++++++
 8 files changed, 186 insertions(+), 126 deletions(-)
 create mode 100644 Documentation/rebase-config.txt
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#29 lore raw

PATCH v2 1/9 Documentation: move rebase.* configs to new file

Move all rebase.* configuration variables to a separate file in order to remove duplicates, and include it in config.txt and git-rebase.txt. The new descriptions are mostly taken from config.txt as they are more verbose.

---
 Documentation/config.txt        | 31 +------------------------------
 Documentation/git-rebase.txt    | 19 +------------------
 Documentation/rebase-config.txt | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 48 deletions(-)
 create mode 100644 Documentation/rebase-config.txt
Documentation/config.txt +1 -30
index 531649cb40ea..e424b7de90b5 100644
@@ -2691,36 +2691,7 @@ push.recurseSubmodules::
 	is retained. You may override this configuration at time of push by
 	specifying '--recurse-submodules=check|on-demand|no'.
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	When set to true, automatically create a temporary stash entry
-	before the operation begins, and apply it after the operation
-	ends.  This means that you can run rebase on a dirty worktree.
-	However, use with care: the final stash application after a
-	successful rebase might result in non-trivial conflicts.
-	Defaults to false.
-
-rebase.missingCommitsCheck::
-	If set to "warn", git rebase -i will print a warning if some
-	commits are removed (e.g. a line was deleted), however the
-	rebase will still proceed. If set to "error", it will print
-	the previous warning and stop the rebase, 'git rebase
-	--edit-todo' can then be used to correct the error. If set to
-	"ignore", no checking is done.
-	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
-	Defaults to "ignore".
-
-rebase.instructionFormat::
-	A format string, as specified in linkgit:git-log[1], to be used for
-	the instruction list during an interactive rebase.  The format will automatically
-	have the long commit hash prepended to the format.
+include::rebase-config.txt[]
 
 receive.advertiseAtomic::
 	By default, git-receive-pack will advertise the atomic push
Documentation/git-rebase.txt +1 -18
index 3cedfb0fd22b..8a861c1e0d69 100644
@@ -203,24 +203,7 @@ Alternatively, you can undo the 'git rebase' with
 CONFIGURATION
 -------------
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	If set to true enable `--autostash` option by default.
-
-rebase.missingCommitsCheck::
-	If set to "warn", print warnings about removed commits in
-	interactive mode. If set to "error", print the warnings and
-	stop the rebase. If set to "ignore", no checking is
-	done. "ignore" by default.
-
-rebase.instructionFormat::
-	Custom commit list format to use during an `--interactive` rebase.
+include::rebase-config.txt[]
 
 OPTIONS
 -------
Documentation/rebase-config.txt new file +32 -0
new file mode 100644
index 000000000000..dba088d7c68f
@@ -0,0 +1,32 @@
+rebase.stat::
+	Whether to show a diffstat of what changed upstream since the last
+	rebase. False by default.
+
+rebase.autoSquash::
+	If set to true enable `--autosquash` option by default.
+
+rebase.autoStash::
+	When set to true, automatically create a temporary stash entry
+	before the operation begins, and apply it after the operation
+	ends.  This means that you can run rebase on a dirty worktree.
+	However, use with care: the final stash application after a
+	successful rebase might result in non-trivial conflicts.
+	This option can be overridden by the `--no-autostash` and
+	`--autostash` options of linkgit:git-rebase[1].
+	Defaults to false.
+
+rebase.missingCommitsCheck::
+	If set to "warn", git rebase -i will print a warning if some
+	commits are removed (e.g. a line was deleted), however the
+	rebase will still proceed. If set to "error", it will print
+	the previous warning and stop the rebase, 'git rebase
+	--edit-todo' can then be used to correct the error. If set to
+	"ignore", no checking is done.
+	To drop a commit without warning or error, use the `drop`
+	command in the todo-list.
+	Defaults to "ignore".
+
+rebase.instructionFormat::
+	A format string, as specified in linkgit:git-log[1], to be used for the
+	instruction list during an interactive rebase.  The format will
+	automatically have the long commit hash prepended to the format.
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#30 lore raw

PATCH v2 2/9 Documentation: use preferred name for the 'todo list' script

In reply to Liam Beguin

Use "todo list" instead of "instruction list" or "todo-list" to reduce further confusion regarding the name of this script.

---
 Documentation/rebase-config.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/rebase-config.txt +2 -2
index dba088d7c68f..30ae08cb5a4b 100644
@@ -23,10 +23,10 @@ rebase.missingCommitsCheck::
 	--edit-todo' can then be used to correct the error. If set to
 	"ignore", no checking is done.
 	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
+	command in the todo list.
 	Defaults to "ignore".
 
 rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
-	instruction 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.
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#31 lore raw

PATCH v2 3/9 rebase -i: set commit to null in exec commands

In reply to Liam Beguin

Make sure commit is set to NULL when parsing exec instructions from the todo list. If not, we may try to access an uninitialized address later while updating the todo list.

---
 sequencer.c | 1 +
 1 file changed, 1 insertion(+)
sequencer.c +1 -0
index fa94ed652d2c..5033b049d995 100644
@@ -1268,6 +1268,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 	bol += padding;
 
 	if (item->command == TODO_EXEC) {
+		item->commit = NULL;
 		item->arg = bol;
 		item->arg_len = (int)(eol - bol);
 		return 0;
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#32 lore raw

PATCH v2 4/9 rebase -i: refactor transform_todo_ids

In reply to Liam Beguin

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

---
 builtin/rebase--helper.c |  4 +--
 sequencer.c              | 69 ++++++++++++++++++++----------------------------
 sequencer.h              |  2 +-
 3 files changed, 31 insertions(+), 44 deletions(-)
builtin/rebase--helper.c +2 -2
index f8519363a393..7c06a27de821 100644
@@ -55,9 +55,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	if (command == MAKE_SCRIPT && argc > 1)
 		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
 	if (command == SHORTEN_SHA1S && argc == 1)
-		return !!transform_todo_ids(1);
+		return !!transform_todo_insn(1);
 	if (command == EXPAND_SHA1S && argc == 1)
-		return !!transform_todo_ids(0);
+		return !!transform_todo_insn(0);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c +28 -41

88 lines not on this page · raw message

sequencer.h +1 -1
index 6f3d3df82c0a..4e444e3bf1c4 100644
@@ -48,7 +48,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 int sequencer_make_script(int keep_empty, FILE *out,
 		int argc, const char **argv);
 
-int transform_todo_ids(int shorten_ids);
+int transform_todo_insn(int shorten_ids);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#33 lore raw

Re: [PATCH v2 4/9] rebase -i: refactor transform_todo_ids

Hi Liam,

Quoted 4 lines · Liam Beguin

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

I am not really a fan of the new name, and would prefer the old one, but that's only a nit, not a reason to reject the patch.

The rest of it makes the code reads a lot nicer than before. Thank you, Johannes

#34 lore raw

Re: [PATCH v2 4/9] rebase -i: refactor transform_todo_ids

Quoted 9 lines · Johannes Schindelin
Quoted 4 lines · Liam Beguin

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

I am not really a fan of the new name, and would prefer the old one, but that's only a nit, not a reason to reject the patch.

FWIW, I do think the new name goes backwards. The command uses to remember what operations are to be carried out in which order using a thing, and the name of that thing "todo list". We also called it the "instruction sheet", and "insn" was a good term to call one item on that sheet among other items.

But recent commits in the area are pushing us to call it "todo list" consistently. An element in that list should be called "todo".

A "todo" consists of two parts, "what operation is done" part and "using what commit object" part. The original implementation of this function affected only the latter part, and in that light, the original name transform_todo_ids() is understandable. Now you are planning to make it modify both parts, not just "ids", so it is understandable that you would want to rename it. But I do not think "insn" matches the recent trend. It even risks misunderstanding (i.e. xfrm_todo_ids() is about modifying "using what commit" part, so perhaps xfrm_todo_insns() is about modifying "what operation is done" part---but that is different from what you want to do, which is to update _both_ halves).

Calling it just transform_todo() would probably be more in line with the reason why you wanted to rename it in the first place.

#35 lore raw

Re: [PATCH v2 4/9] rebase -i: refactor transform_todo_ids

Hi Junio,

Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Johannes Schindelin
Quoted 4 lines · Liam Beguin

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

Quoted 9 lines
Quoted 2 lines

I am not really a fan of the new name, and would prefer the old one, but that's only a nit, not a reason to reject the patch.

FWIW, I do think the new name goes backwards. The command uses to remember what operations are to be carried out in which order using a thing, and the name of that thing "todo list". We also called it the "instruction sheet", and "insn" was a good term to call one item on that sheet among other items.

Good point on saying this name change is going backwards.

Quoted 15 lines

But recent commits in the area are pushing us to call it "todo list" consistently. An element in that list should be called "todo".

A "todo" consists of two parts, "what operation is done" part and "using what commit object" part. The original implementation of this function affected only the latter part, and in that light, the original name transform_todo_ids() is understandable. Now you are planning to make it modify both parts, not just "ids", so it is understandable that you would want to rename it. But I do not think "insn" matches the recent trend. It even risks misunderstanding (i.e. xfrm_todo_ids() is about modifying "using what commit" part, so perhaps xfrm_todo_insns() is about modifying "what operation is done" part---but that is different from what you want to do, which is to update _both_ halves).

You're right! We do want the name to reflect that we intend to change both halves and not only the command.

Quoted 3 lines

Calling it just transform_todo() would probably be more in line with the reason why you wanted to rename it in the first place.

Good suggestion. Would transform_todos() work too? I'll send an update tomorrow.
Thanks,

Liam

#36 lore raw

Re: [PATCH v2 4/9] rebase -i: refactor transform_todo_ids

Quoted 1 line · liam Beguin

Good suggestion. Would transform_todos() work too?

If the function is about munging multiple of them, then todo"s" would work well; I wasn't focusing on singular vs plural, as I thought the choice between them needs much less thought to make correctly.

#37 lore raw

Re: [PATCH v2 4/9] rebase -i: refactor transform_todo_ids

In reply to Johannes Schindelin

Hi Johannes,

Quoted 4 lines · Johannes Schindelin

Hi Liam,

On Sun, 3 Dec 2017, Liam Beguin wrote:

Quoted 8 lines
Quoted 4 lines

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

I am not really a fan of the new name, and would prefer the old one, but that's only a nit, not a reason to reject the patch.

You're right, it's probably not the best name. I'll change it to transform_todos() as we want the function name to reflect that it changes both parts of the todo.

Quoted 3 lines

The rest of it makes the code reads a lot nicer than before. Thank you, Johannes

Thanks,
Liam

#38 lore raw

PATCH v2 5/9 rebase -i: replace reference to sha1 with oid

In reply to Liam Beguin

Since we are trying to abstract the hash function name elsewhere in the code base, lets use OID instead of SHA-1 in the rebase--helper too.

---
 builtin/rebase--helper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/rebase--helper.c +5 -5
index 7c06a27de821..af0f91164fd0 100644
@@ -14,7 +14,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int keep_empty = 0;
 	enum {
-		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
+		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
 	} command = 0;
 	struct option options[] = {
@@ -27,9 +27,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		OPT_CMDMODE(0, "make-script", &command,
 			N_("make rebase script"), MAKE_SCRIPT),
 		OPT_CMDMODE(0, "shorten-ids", &command,
-			N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),
+			N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
 		OPT_CMDMODE(0, "expand-ids", &command,
-			N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),
+			N_("expand commit ids in the todo list"), EXPAND_OIDS),
 		OPT_CMDMODE(0, "check-todo-list", &command,
 			N_("check the todo list"), CHECK_TODO_LIST),
 		OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
@@ -54,9 +54,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
 		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
-	if (command == SHORTEN_SHA1S && argc == 1)
+	if (command == SHORTEN_OIDS && argc == 1)
 		return !!transform_todo_insn(1);
-	if (command == EXPAND_SHA1S && argc == 1)
+	if (command == EXPAND_OIDS && argc == 1)
 		return !!transform_todo_insn(0);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#39 lore raw

PATCH v2 6/9 rebase -i: update functions to use a flags parameter

In reply to Liam Beguin

Update functions used in the rebase--helper so that they take a generic 'flags' parameter instead of a growing list of options.

---
 builtin/rebase--helper.c | 13 +++++++------
 sequencer.c              |  9 +++++----
 sequencer.h              |  8 +++++---
 3 files changed, 17 insertions(+), 13 deletions(-)
builtin/rebase--helper.c +7 -6
index af0f91164fd0..fe814bf7229e 100644
@@ -12,7 +12,7 @@ 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;
-	int keep_empty = 0;
+	unsigned flags = 0, keep_empty = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
@@ -48,16 +48,17 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, NULL, options,
 			builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
 
+	flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
+	flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTED_IDS : 0;
+
 	if (command == CONTINUE && argc == 1)
 		return !!sequencer_continue(&opts);
 	if (command == ABORT && argc == 1)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
-	if (command == SHORTEN_OIDS && argc == 1)
-		return !!transform_todo_insn(1);
-	if (command == EXPAND_OIDS && argc == 1)
-		return !!transform_todo_insn(0);
+		return !!sequencer_make_script(stdout, argc, argv, flags);
+	if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
+		return !!transform_todo_insn(flags);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c +5 -4
index 0ff3c90e44bf..7d712811e9d1 100644
@@ -2444,14 +2444,15 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
 	strbuf_release(&sob);
 }
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags)
 {
 	char *format = NULL;
 	struct pretty_print_context pp = {0};
 	struct strbuf buf = STRBUF_INIT;
 	struct rev_info revs;
 	struct commit *commit;
+	int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
 
 	init_revisions(&revs, NULL);
 	revs.verbose_header = 1;
@@ -2494,7 +2495,7 @@ int sequencer_make_script(int keep_empty, FILE *out,
 }
 
 
-int transform_todo_insn(int shorten_ids)
+int transform_todo_insn(unsigned flags)
 {
 	const char *todo_file = rebase_path_todo();
 	struct todo_list todo_list = TODO_LIST_INIT;
@@ -2522,7 +2523,7 @@ int transform_todo_insn(int shorten_ids)
 
 		/* add commit id */
 		if (item->commit) {
-			const char *oid = shorten_ids ?
+			const char *oid = flags & TODO_LIST_SHORTED_IDS ?
 					  short_commit_name(item->commit) :
 					  oid_to_hex(&item->commit->object.oid);
 
sequencer.h +5 -3
index 4e444e3bf1c4..3bb6b0658192 100644
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTED_IDS (1U << 1)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags);
 
-int transform_todo_insn(int shorten_ids);
+int transform_todo_insn(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#40 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Hi Liam,

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 49

Quoted 12 lines · Liam Beguin
sequencer.h +2 -2
index 4e444e3bf1c4..3bb6b0658192 100644
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTED_IDS (1U << 1)

Maybe SHORTEN_IDs? And either revert back to transform_todo_ids() or use SHORTEN_INSNS...

Maybe also TRANSFORM_TODO_LIST_* and maybe move the #define's above the transform_todo_ids() function, i.e. one line further down?

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 56

Quoted 8 lines
sequencer.h +3 -1
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags);
 
-int transform_todo_insn(int shorten_ids);
+int transform_todo_insn(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);

Ciao,
Johannes

#41 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Hi Liam,

Quoted 18 lines · Johannes Schindelin

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 49

Quoted 12 lines · Liam Beguin
sequencer.h +2 -2
index 4e444e3bf1c4..3bb6b0658192 100644
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTED_IDS (1U << 1)

Maybe SHORTEN_IDs? And either revert back to transform_todo_ids() or use SHORTEN_INSNS...

Quoted 5 lines

Maybe also TRANSFORM_TODO_LIST_* and maybe move the #define's above the transform_todo_ids() function, i.e. one line further down?

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 51

Quoted 2 lines
sequencer.h +2 -0
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags);

Ah, I just realized that make_script() already takes flags. Sorry for the noise,
Johannes

#42 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

In reply to Johannes Schindelin

Hi Johannes,

Quoted 12 lines · Johannes Schindelin

Hi Liam,

Quoted 8 lines · Liam Beguin
sequencer.h +0 -0
index 4e444e3bf1c4..3bb6b0658192 100644
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
Quoted 8 lines

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 49

Quoted 4 lines
sequencer.h +2 -2
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTED_IDS (1U << 1)

Maybe SHORTEN_IDs? And either revert back to transform_todo_ids() or use SHORTEN_INSNS...

I'll change it to TODO_LIST_SHORTED_IDs. TODO_LIST_SHORTED_INSNS would suggest the flag changes both parts of the todo.

Quoted 6 lines

Maybe also TRANSFORM_TODO_LIST_* and maybe move the #define's above the transform_todo_ids() function, i.e. one line further down?

Quoted 3 lines
sequencer.h +2 -0
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags);
 
Quoted 9 lines

sequencer.h int sequencer_continue(struct replay_opts *opts); · line 56

Quoted 5 lines
sequencer.h +1 -1
-int transform_todo_insn(int shorten_ids);
+int transform_todo_insn(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);

Ciao,
Johannes

Thanks,
Liam

#43 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Quoted 2 lines · liam Beguin

I'll change it to TODO_LIST_SHORTED_IDs. TODO_LIST_SHORTED_INSNS would suggest the flag changes both parts of the todo.

I am not a native speaker, but SHORTED does not sound like a right phrase. When you make something shorter, that thing is "shortened", not "shorted".

#44 lore raw

RE: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

"Shorted" is what happens when you put a piece of wire across the terminals of a battery ... (bang, smoke, etc). It's short for "short-circuited".
Yes, I think you mean "shortened" in this case.

Regards,
Richard.

Richard Kerry
BNCS Engineer, SI SOL Telco & Media Vertical Practice

T: +44 (0)20 3618 2669
M: +44 (0)7812 325518
Lync: +44 (0) 20 3618 0778
Room G300, Stadium House, Wood Lane, London, W12 7TA [email protected]

Quoted 10 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Junio C Hamano
Sent: Tuesday, December 05, 2017 12:37 PM
To: liam Beguin <[email protected]>
Cc: Johannes Schindelin <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Quoted 8 lines
Quoted 1 line · liam Beguin

I'll change it to TODO_LIST_SHORTED_IDs. TODO_LIST_SHORTED_INSNS

would

Quoted 1 line

suggest the flag changes both parts of the todo.

I am not a native speaker, but SHORTED does not sound like a right phrase. When you make something shorter, that thing is "shortened", not "shorted".

Atos, Atos Consulting, Worldline and Canopy The Open Cloud Company are trading names used by the Atos group. The following trading entities are registered in England and Wales: Atos IT Services UK Limited (registered number 01245534), Atos Consulting Limited (registered number 04312380), Atos Worldline UK Limited (registered number 08514184) and Canopy The Open Cloud Company Limited (registration number 08011902). The registered office for each is at 4 Triton Square, Regent’s Place, London, NW1 3HG.The VAT No. for each is: GB232327983.

This e-mail and the documents attached are confidential and intended solely for the addressee, and may contain confidential or privileged information. If you receive this e-mail in error, you are not authorised to copy, disclose, use or retain it. Please notify the sender immediately and delete this email from your systems. As emails may be intercepted, amended or lost, they are not secure. Atos therefore can accept no liability for any errors or their content. Although Atos endeavours to maintain a virus-free network, we do not warrant that this transmission is virus-free and can accept no liability for any damages resulting from any virus transmitted. The risks are deemed to be accepted by everyone who communicates with Atos by email.

#45 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Hi,

Quoted 5 lines · Richard

"Shorted" is what happens when you put a piece of wire across the terminals of a battery ... (bang, smoke, etc). It's short for "short-circuited".
Yes, I think you mean "shortened" in this case.

Thanks for the explanation.
Sorry, my eyes stopped at the lowercase 's' in Johannes message. Will fix.

Quoted 5 lines

Regards,
Richard.

Quoted 10 lines

Richard Kerry
BNCS Engineer, SI SOL Telco & Media Vertical Practice

T: +44 (0)20 3618 2669
M: +44 (0)7812 325518
Lync: +44 (0) 20 3618 0778
Room G300, Stadium House, Wood Lane, London, W12 7TA [email protected]

[...]

Thanks,
Liam

#46 lore raw

Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

In reply to Kerry, Richard
Quoted 2 lines · Richard

"Shorted" is what happens when you put a piece of wire across the terminals of a battery ... (bang, smoke, etc). It's short for "short-circuited".

Or it is what you do to something that you sell and that you yet do not own, expecting that you can later buy it cheaper, allowing you to pocket the difference ;-).

#47 lore raw

RE: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

Indeed so.
In which case it is short for "selling short", or possibly "short selling".

Of course a little searching shows that "shorted" could mean some other things, including possibly the meaning originally suggested. Nevertheless it seems to me that "shortened" is the most appropriate word in modern English.

R.

Richard Kerry
BNCS Engineer, SI SOL Telco & Media Vertical Practice

T: +44 (0)20 3618 2669
M: +44 (0)7812 325518
Lync: +44 (0) 20 3618 0778
Room G300, Stadium House, Wood Lane, London, W12 7TA [email protected]

Quoted 12 lines

-----Original Message-----
From: Junio C Hamano [mailto:[email protected]]
Sent: Tuesday, December 05, 2017 4:06 PM
To: Kerry, Richard <[email protected]>
Cc: [email protected]; Johannes Schindelin <[email protected]>; [email protected]; liam Beguin <[email protected]>
Subject: Re: [PATCH v2 6/9] rebase -i: update functions to use a flags parameter

"Kerry, Richard" <[email protected]> writes:

Quoted 8 lines
Quoted 1 line

"Shorted" is what happens when you put a piece of wire across the

terminals of a battery ... (bang, smoke, etc).

Quoted 1 line

It's short for "short-circuited".

Or it is what you do to something that you sell and that you yet do not own, expecting that you can later buy it cheaper, allowing you to pocket the difference ;-).

Atos, Atos Consulting, Worldline and Canopy The Open Cloud Company are trading names used by the Atos group. The following trading entities are registered in England and Wales: Atos IT Services UK Limited (registered number 01245534), Atos Consulting Limited (registered number 04312380), Atos Worldline UK Limited (registered number 08514184) and Canopy The Open Cloud Company Limited (registration number 08011902). The registered office for each is at 4 Triton Square, Regent’s Place, London, NW1 3HG.The VAT No. for each is: GB232327983.

This e-mail and the documents attached are confidential and intended solely for the addressee, and may contain confidential or privileged information. If you receive this e-mail in error, you are not authorised to copy, disclose, use or retain it. Please notify the sender immediately and delete this email from your systems. As emails may be intercepted, amended or lost, they are not secure. Atos therefore can accept no liability for any errors or their content. Although Atos endeavours to maintain a virus-free network, we do not warrant that this transmission is virus-free and can accept no liability for any damages resulting from any virus transmitted. The risks are deemed to be accepted by everyone who communicates with Atos by email.

#48 lore raw

PATCH v2 7/9 rebase -i -x: add exec commands via the rebase--helper

In reply to Liam Beguin

Recent work on git-rebase--interactive aims to convert shell code to C. Even if this is most likely not a big performance enhancement, let's convert it too since a coming change to abbreviate command names requires it to be updated.

---
 builtin/rebase--helper.c   |  7 ++++++-
 git-rebase--interactive.sh | 23 +----------------------
 sequencer.c                | 39 +++++++++++++++++++++++++++++++++++++++
 sequencer.h                |  1 +
 4 files changed, 47 insertions(+), 23 deletions(-)
builtin/rebase--helper.c +6 -1
index fe814bf7229e..03337e1484a2 100644
@@ -15,7 +15,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	unsigned flags = 0, keep_empty = 0;
 	enum {
 		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,
+		ADD_EXEC
 	} command = 0;
 	struct option options[] = {
 		OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -36,6 +37,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
 		OPT_CMDMODE(0, "rearrange-squash", &command,
 			N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+		OPT_CMDMODE(0, "add-exec-commands", &command,
+			N_("insert exec commands in todo list"), ADD_EXEC),
 		OPT_END()
 	};
 
@@ -65,5 +68,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!skip_unnecessary_picks();
 	if (command == REARRANGE_SQUASH && argc == 1)
 		return !!rearrange_squash();
+	if (command == ADD_EXEC && argc == 2)
+		return !!sequencer_add_exec_commands(argv[1]);
 	usage_with_options(builtin_rebase_helper_usage, options);
 }
git-rebase--interactive.sh +1 -22
index 437815669f00..e3f5a0abf3c7 100644
@@ -722,27 +722,6 @@ collapse_todo_ids() {
 	git rebase--helper --shorten-ids
 }
 
-# Add commands after a pick or after a squash/fixup series
-# in the todo list.
-add_exec_commands () {
-	{
-		first=t
-		while read -r insn rest
-		do
-			case $insn in
-			pick)
-				test -n "$first" ||
-				printf "%s" "$cmd"
-				;;
-			esac
-			printf "%s %s\n" "$insn" "$rest"
-			first=
-		done
-		printf "%s" "$cmd"
-	} <"$1" >"$1.new" &&
-	mv "$1.new" "$1"
-}
-
 # Switch to the branch in $into and notify it in the reflog
 checkout_onto () {
 	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
@@ -982,7 +961,7 @@ fi
 
 test -s "$todo" || echo noop >> "$todo"
 test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
-test -n "$cmd" && add_exec_commands "$todo"
+test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
 
 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
 todocount=${todocount##* }
sequencer.c +39 -0
index 7d712811e9d1..bd047737082d 100644
@@ -2494,6 +2494,45 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 	return 0;
 }
 
+/*
+ * Add commands after pick and (series of) squash/fixup commands
+ * in the todo list.
+ */
+int sequencer_add_exec_commands(const char *commands)
+{
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	struct todo_item *item;
+	struct strbuf *buf = &todo_list.buf;
+	size_t offset = 0, commands_len = strlen(commands);
+	int i, first;
+
+	if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
+		return error(_("could not read '%s'."), todo_file);
+
+	if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}
+
+	first = 1;
+	/* insert <commands> before every pick except the first one */
+	for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
+		if (item->command == TODO_PICK && !first) {
+			strbuf_insert(buf, item->offset_in_buf + offset,
+				      commands, commands_len);
+			offset += commands_len;
+		}
+		first = 0;
+	}
+
+	/* append final <commands> */
+	strbuf_add(buf, commands, commands_len);
+
+	i = write_message(buf->buf, buf->len, todo_file, 0);
+	todo_list_release(&todo_list);
+	return i;
+}
 
 int transform_todo_insn(unsigned flags)
 {
sequencer.h +1 -0
index 3bb6b0658192..e4a9d2419883 100644
@@ -50,6 +50,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 int sequencer_make_script(FILE *out, int argc, const char **argv,
 			  unsigned flags);
 
+int sequencer_add_exec_commands(const char *command);
 int transform_todo_insn(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#49 lore raw

PATCH v2 8/9 rebase -i: learn to abbreviate command names

In reply to Liam Beguin

git rebase -i already know how to interpret single-letter command names. Teach it to generate the todo list with these same abbreviated names.

---
 Documentation/rebase-config.txt | 20 ++++++++++++++++++++
 builtin/rebase--helper.c        |  3 +++
 sequencer.c                     | 16 ++++++++++++++--
 sequencer.h                     |  1 +
 4 files changed, 38 insertions(+), 2 deletions(-)
Documentation/rebase-config.txt +20 -0
index 30ae08cb5a4b..42e1ba757564 100644
@@ -30,3 +30,23 @@ rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
 	todo list during an interactive rebase.  The format will
 	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.
builtin/rebase--helper.c +3 -0
index 03337e1484a2..2c51ddcfd3dd 100644
@@ -13,6 +13,7 @@ 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;
+	int abbreviate_commands = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		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_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
 
 	opts.action = REPLAY_INTERACTIVE_REBASE;
 	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);
 
 	flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
+	flags |= abbreviate_commands ? TODO_LIST_ABBREVIATE_CMDS : 0;
 	flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTED_IDS : 0;
 
 	if (command == CONTINUE && argc == 1)
sequencer.c +14 -2
index bd047737082d..b752dcc52982 100644
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command 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)
 {
 	return TODO_NOOP <= command;
@@ -2453,6 +2460,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 	struct rev_info revs;
 	struct commit *commit;
 	int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
+	const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
 
 	init_revisions(&revs, NULL);
 	revs.verbose_header = 1;
@@ -2485,7 +2493,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 		strbuf_reset(&buf);
 		if (!keep_empty && is_original_commit_empty(commit))
 			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);
 		strbuf_addch(&buf, '\n');
 		fputs(buf.buf, out);
@@ -2558,7 +2567,10 @@ int transform_todo_insn(unsigned flags)
 		}
 
 		/* 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 */
 		if (item->commit) {
sequencer.h +1 -0
index e4a9d2419883..468ee79fb72d 100644
@@ -47,6 +47,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 
 #define TODO_LIST_KEEP_EMPTY (1U << 0)
 #define TODO_LIST_SHORTED_IDS (1U << 1)
+#define TODO_LIST_ABBREVIATE_CMDS (1U << 2)
 int sequencer_make_script(FILE *out, int argc, const char **argv,
 			  unsigned flags);
 
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#50 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

sequencer.c static const char *command_to_string(const enum todo_command command) · line 803

Quoted 6 lines · Liam Beguin
sequencer.c +6 -0
+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;
+}

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

                   ^

Maybe drop the first const.

Signature · 1 line
Duy
#51 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

Hi Duy,

Quoted 13 lines · On Mon, 25 Dec 2017 at 07:48 Duy Nguyen <[email protected]> wrote:

sequencer.c static const char *command_to_string(const enum todo_command command) · line 803

Quoted 6 lines · Liam Beguin
sequencer.c +6 -0
+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;
+}

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

Quoted 3 lines
                   ^

Maybe drop the first const.

Sorry, that's another copy-edit error I made that slipped through... I'm curious, how did you build to get this error to show? I tried with the DEVELOPER 'flag' but nothing showed and -Wextra gave way too much messages...
Did you just add -Wignored-qualifiers to CFLAGS?

Quoted 2 lines

--
Duy

Thanks,
Liam

#52 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

Quoted 4 lines · Liam Beguin

I'm curious, how did you build to get this error to show? I tried with the DEVELOPER 'flag' but nothing showed and -Wextra gave way too much messages...
Did you just add -Wignored-qualifiers to CFLAGS?

I have a custom CFLAGS, created before DEVELOPER flag was added, which is -Wextra -Werror plus about 5 -Wno-xxx to shut gcc up.

Signature · 1 line
Duy
#53 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

In reply to Duy Nguyen
Quoted 12 lines · Duy Nguyen

Review

Quoted 6 lines · Liam Beguin
(quoted diff) +6 -0
+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;
+}

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

Quoted 3 lines
                   ^

Maybe drop the first const.

Thanks. This topic has been in 'next' for quite some time and I wanted to merge it down to 'master' soonish, so I've added the following before doing so.

-- >8 --
From: Junio C Hamano <[email protected]>
Date: Wed, 27 Dec 2017 11:12:45 -0800
Subject: [PATCH] sequencer.c: drop 'const' from function return type

With -Werror=ignored-qualifiers, a function that claims to return "const char" gets this error:

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

                   ^
---
 sequencer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sequencer.c +1 -1
index 115085d39c..2a407cbe54 100644
@@ -795,7 +795,7 @@ static const char *command_to_string(const enum todo_command command)
 	die("Unknown command: %d", command);
 }
 
-static const char command_to_char(const enum todo_command command)
+static char command_to_char(const enum todo_command command)
 {
 	if (command < TODO_COMMENT && todo_command_info[command].c)
 		return todo_command_info[command].c;
Signature · 1 line
2.15.1-597-g62d91a8972
#54 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

Hi Junio,

Quoted 16 lines · Junio C Hamano
Quoted 14 lines · Duy Nguyen

Review

Quoted 6 lines · Liam Beguin
(quoted diff) +6 -0
+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;
+}

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

                   ^
Quoted 5 lines
Quoted 1 line

Maybe drop the first const.

Thanks. This topic has been in 'next' for quite some time and I wanted to merge it down to 'master' soonish, so I've added the following before doing so.

Thanks for taking the time. I had prepared the patch but was waiting to get home to send it.
Only comment I have, maybe s/sequencer.c/rebase -i/ in the subject line so it matches with the rest.

Since this came up, would it be a good thing to add -Wignored-qualifiers to the DEVELOPER flags?

Quoted 35 lines

-- >8 --
From: Junio C Hamano <[email protected]>
Date: Wed, 27 Dec 2017 11:12:45 -0800
Subject: [PATCH] sequencer.c: drop 'const' from function return type

With -Werror=ignored-qualifiers, a function that claims to return "const char" gets this error:

CC sequencer.o
sequencer.c:798:19: error: type qualifiers ignored on function return type [-Werror=ignored-qualifiers]
static const char command_to_char(const enum todo_command command)

                   ^
---
 sequencer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sequencer.c +1 -2
index 115085d39c..2a407cbe54 100644
@@ -795,7 +795,7 @@ static const char *command_to_string(const enum todo_command command)
        die("Unknown command: %d", command);
 }
 
-static const char command_to_char(const enum todo_command command)
+static char command_to_char(const enum todo_command command)
 {
        if (command < TODO_COMMENT && todo_command_info[command].c)
                return todo_command_info[command].c;
--
Quoted 2 lines

2.15.1-597-g62d91a8972

Thanks,
Liam

#55 lore raw

Re: [PATCH v2 8/9] rebase -i: learn to abbreviate command names

Quoted 2 lines · Liam Beguin

Since this came up, would it be a good thing to add -Wignored-qualifiers to the DEVELOPER flags?

Quite frankly, I am not sure if catching that particular warning violation buys us much. As a return value from a function is never an lvalue, what triggers the warning may certainly be an indication of a sloppy coding, but otherwise I do not see it as diagnosing a potential error. "The programmer thought that the returned value will only be assigned to a const variable and will never be modified, but the language does not guarantee such a behaviour out of the caller"---does such an incorrect expectation lead to an error in the codepath that involves such a function?

#56 lore raw

PATCH v2 9/9 t3404: add test case for abbreviated commands

In reply to Liam Beguin

Make sure the todo list ends up using single-letter command abbreviations when the rebase.abbreviateCommands is enabled. This configuration option should not change anything else.

---
 t/t3404-rebase-interactive.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
t/t3404-rebase-interactive.sh +22 -0
index 6a82d1ed876d..481a3500900d 100755
@@ -1260,6 +1260,28 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 	test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
+	rebase_setup_and_clean abbrevcmd &&
+	test_commit "first" file1.txt "first line" first &&
+	test_commit "second" file1.txt "another line" second &&
+	test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+	test_commit "squash! second" file1.txt "another line here" second_squash &&
+	cat >expected <<-EOF &&
+	p $(git rev-list --abbrev-commit -1 first) first
+	f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+	x git show HEAD
+	p $(git rev-list --abbrev-commit -1 second) second
+	s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+	x git show HEAD
+	EOF
+	git checkout abbrevcmd &&
+	set_cat_todo_editor &&
+	test_config rebase.abbreviateCommands true &&
+	test_must_fail git rebase -i --exec "git show HEAD" \
+		--autosquash master >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'static check of bad command' '
 	rebase_setup_and_clean bad-cmd &&
 	set_fake_editor &&
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#57 lore raw
In reply to Liam Beguin

Hi Liam,

Quoted 11 lines · Liam Beguin

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Quoted 11 lines

Changes in V2:
- Refactor and rename 'transform_todo_ids'
- Replace SHA-1 by OID in rebase--helper.c
- Update todo list related functions to take a generic 'flags' parameter
- Rename 'add_exec_commands' function to 'sequencer_add_exec_commands'
- Rename 'add-exec' option to 'add-exec-commands'
- Use 'strbur_read_file' instead of rewriting it
- Make 'command_to_char' return 'comment_char_line' if no single-letter command name is defined
- Combine both tests into a single test case
- Update commit messages

Looks very nice already! I offered a couple of comments/suggestions, but nothing major.

Thank you,
Johannes

#58 lore raw

v2 cover rebase -i: add config to abbreviate command names

In reply to Liam Beguin

Hi everyone,

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Changes in V2:
- Refactor and rename 'transform_todo_ids'
- Replace SHA-1 by OID in rebase--helper.c
- Update todo list related functions to take a generic 'flags' parameter
- Rename 'add_exec_commands' function to 'sequencer_add_exec_commands'
- Rename 'add-exec' option to 'add-exec-commands'
- Use 'strbur_read_file' instead of rewriting it
- Make 'command_to_char' return 'comment_char_line' if no single-letter command name is defined
- Combine both tests into a single test case
- Update commit messages

Changes in V2:
- Rename 'transform_todo_insn' to 'transform_todos'
- Fix flag name TODO_LIST_SHORTE{D,N}_IDS

Liam Beguin (9):
Documentation: move rebase.* configs to new file
Documentation: use preferred name for the 'todo list' script rebase -i: set commit to null in exec commands rebase -i: refactor transform_todo_ids
rebase -i: replace reference to sha1 with oid rebase -i: update functions to use a flags parameter rebase -i -x: add exec commands via the rebase--helper rebase -i: learn to abbreviate command names
t3404: add test case for abbreviated commands

 Documentation/config.txt        |  31 +-------
 Documentation/git-rebase.txt    |  19 +----
 Documentation/rebase-config.txt |  52 +++++++++++++
 builtin/rebase--helper.c        |  29 +++++---
 git-rebase--interactive.sh      |  23 +-----
 sequencer.c                     | 126 +++++++++++++++++++++-----------
 sequencer.h                     |  10 ++-
 t/t3404-rebase-interactive.sh   |  22 ++++++
 8 files changed, 186 insertions(+), 126 deletions(-)
 create mode 100644 Documentation/rebase-config.txt
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#59 lore raw

PATCH v3 1/9 Documentation: move rebase.* configs to new file

Move all rebase.* configuration variables to a separate file in order to remove duplicates, and include it in config.txt and git-rebase.txt. The new descriptions are mostly taken from config.txt as they are more verbose.

---
 Documentation/config.txt        | 31 +------------------------------
 Documentation/git-rebase.txt    | 19 +------------------
 Documentation/rebase-config.txt | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 48 deletions(-)
Documentation/config.txt +1 -30
index 531649cb40ea..e424b7de90b5 100644
@@ -2691,36 +2691,7 @@ push.recurseSubmodules::
 	is retained. You may override this configuration at time of push by
 	specifying '--recurse-submodules=check|on-demand|no'.
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	When set to true, automatically create a temporary stash entry
-	before the operation begins, and apply it after the operation
-	ends.  This means that you can run rebase on a dirty worktree.
-	However, use with care: the final stash application after a
-	successful rebase might result in non-trivial conflicts.
-	Defaults to false.
-
-rebase.missingCommitsCheck::
-	If set to "warn", git rebase -i will print a warning if some
-	commits are removed (e.g. a line was deleted), however the
-	rebase will still proceed. If set to "error", it will print
-	the previous warning and stop the rebase, 'git rebase
-	--edit-todo' can then be used to correct the error. If set to
-	"ignore", no checking is done.
-	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
-	Defaults to "ignore".
-
-rebase.instructionFormat::
-	A format string, as specified in linkgit:git-log[1], to be used for
-	the instruction list during an interactive rebase.  The format will automatically
-	have the long commit hash prepended to the format.
+include::rebase-config.txt[]
 
 receive.advertiseAtomic::
 	By default, git-receive-pack will advertise the atomic push
Documentation/git-rebase.txt +1 -18
index 3cedfb0fd22b..8a861c1e0d69 100644
@@ -203,24 +203,7 @@ Alternatively, you can undo the 'git rebase' with
 CONFIGURATION
 -------------
 
-rebase.stat::
-	Whether to show a diffstat of what changed upstream since the last
-	rebase. False by default.
-
-rebase.autoSquash::
-	If set to true enable `--autosquash` option by default.
-
-rebase.autoStash::
-	If set to true enable `--autostash` option by default.
-
-rebase.missingCommitsCheck::
-	If set to "warn", print warnings about removed commits in
-	interactive mode. If set to "error", print the warnings and
-	stop the rebase. If set to "ignore", no checking is
-	done. "ignore" by default.
-
-rebase.instructionFormat::
-	Custom commit list format to use during an `--interactive` rebase.
+include::rebase-config.txt[]
 
 OPTIONS
 -------
Documentation/rebase-config.txt new file +32 -0
new file mode 100644
index 000000000000..dba088d7c68f
@@ -0,0 +1,32 @@
+rebase.stat::
+	Whether to show a diffstat of what changed upstream since the last
+	rebase. False by default.
+
+rebase.autoSquash::
+	If set to true enable `--autosquash` option by default.
+
+rebase.autoStash::
+	When set to true, automatically create a temporary stash entry
+	before the operation begins, and apply it after the operation
+	ends.  This means that you can run rebase on a dirty worktree.
+	However, use with care: the final stash application after a
+	successful rebase might result in non-trivial conflicts.
+	This option can be overridden by the `--no-autostash` and
+	`--autostash` options of linkgit:git-rebase[1].
+	Defaults to false.
+
+rebase.missingCommitsCheck::
+	If set to "warn", git rebase -i will print a warning if some
+	commits are removed (e.g. a line was deleted), however the
+	rebase will still proceed. If set to "error", it will print
+	the previous warning and stop the rebase, 'git rebase
+	--edit-todo' can then be used to correct the error. If set to
+	"ignore", no checking is done.
+	To drop a commit without warning or error, use the `drop`
+	command in the todo-list.
+	Defaults to "ignore".
+
+rebase.instructionFormat::
+	A format string, as specified in linkgit:git-log[1], to be used for the
+	instruction list during an interactive rebase.  The format will
+	automatically have the long commit hash prepended to the format.
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#60 lore raw

PATCH v3 2/9 Documentation: use preferred name for the 'todo list' script

In reply to Liam Beguin

Use "todo list" instead of "instruction list" or "todo-list" to reduce further confusion regarding the name of this script.

---
 Documentation/rebase-config.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Documentation/rebase-config.txt +2 -2
index dba088d7c68f..30ae08cb5a4b 100644
@@ -23,10 +23,10 @@ rebase.missingCommitsCheck::
 	--edit-todo' can then be used to correct the error. If set to
 	"ignore", no checking is done.
 	To drop a commit without warning or error, use the `drop`
-	command in the todo-list.
+	command in the todo list.
 	Defaults to "ignore".
 
 rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
-	instruction 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.
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#61 lore raw

PATCH v3 3/9 rebase -i: set commit to null in exec commands

In reply to Liam Beguin

Make sure commit is set to NULL when parsing exec instructions from the todo list. If not, we may try to access an uninitialized address later while updating the todo list.

---
 sequencer.c | 1 +
 1 file changed, 1 insertion(+)
sequencer.c +1 -0
index fa94ed652d2c..5033b049d995 100644
@@ -1268,6 +1268,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 	bol += padding;
 
 	if (item->command == TODO_EXEC) {
+		item->commit = NULL;
 		item->arg = bol;
 		item->arg_len = (int)(eol - bol);
 		return 0;
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#62 lore raw

PATCH v3 4/9 rebase -i: refactor transform_todo_ids

In reply to Liam Beguin

The transform_todo_ids function is a little hard to read. Lets try to make it easier by using more of the strbuf API. Also, since we'll soon be adding command abbreviations, let's rename the function so it's name reflects that change.

---
 builtin/rebase--helper.c |  4 +--
 sequencer.c              | 69 ++++++++++++++++------------------------
 sequencer.h              |  2 +-
 3 files changed, 31 insertions(+), 44 deletions(-)
builtin/rebase--helper.c +2 -2
index f8519363a393..8ad4779d1650 100644
@@ -55,9 +55,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	if (command == MAKE_SCRIPT && argc > 1)
 		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
 	if (command == SHORTEN_SHA1S && argc == 1)
-		return !!transform_todo_ids(1);
+		return !!transform_todos(1);
 	if (command == EXPAND_SHA1S && argc == 1)
-		return !!transform_todo_ids(0);
+		return !!transform_todos(0);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c +28 -41

88 lines not on this page · raw message

sequencer.h +1 -1
index 6f3d3df82c0a..4f7f2c93f83e 100644
@@ -48,7 +48,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 int sequencer_make_script(int keep_empty, FILE *out,
 		int argc, const char **argv);
 
-int transform_todo_ids(int shorten_ids);
+int transform_todos(int shorten_ids);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#63 lore raw

PATCH v3 5/9 rebase -i: replace reference to sha1 with oid

In reply to Liam Beguin

Since we are trying to abstract the hash function name elsewhere in the code base, lets use OID instead of SHA-1 in the rebase--helper too.

---
 builtin/rebase--helper.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/rebase--helper.c +5 -5
index 8ad4779d1650..c3b8e4d401f8 100644
@@ -14,7 +14,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	struct replay_opts opts = REPLAY_OPTS_INIT;
 	int keep_empty = 0;
 	enum {
-		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_SHA1S, EXPAND_SHA1S,
+		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
 	} command = 0;
 	struct option options[] = {
@@ -27,9 +27,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		OPT_CMDMODE(0, "make-script", &command,
 			N_("make rebase script"), MAKE_SCRIPT),
 		OPT_CMDMODE(0, "shorten-ids", &command,
-			N_("shorten SHA-1s in the todo list"), SHORTEN_SHA1S),
+			N_("shorten commit ids in the todo list"), SHORTEN_OIDS),
 		OPT_CMDMODE(0, "expand-ids", &command,
-			N_("expand SHA-1s in the todo list"), EXPAND_SHA1S),
+			N_("expand commit ids in the todo list"), EXPAND_OIDS),
 		OPT_CMDMODE(0, "check-todo-list", &command,
 			N_("check the todo list"), CHECK_TODO_LIST),
 		OPT_CMDMODE(0, "skip-unnecessary-picks", &command,
@@ -54,9 +54,9 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
 		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
-	if (command == SHORTEN_SHA1S && argc == 1)
+	if (command == SHORTEN_OIDS && argc == 1)
 		return !!transform_todos(1);
-	if (command == EXPAND_SHA1S && argc == 1)
+	if (command == EXPAND_OIDS && argc == 1)
 		return !!transform_todos(0);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#64 lore raw

PATCH v3 6/9 rebase -i: update functions to use a flags parameter

In reply to Liam Beguin

Update functions used in the rebase--helper so that they take a generic 'flags' parameter instead of a growing list of options.

---
 builtin/rebase--helper.c | 13 +++++++------
 sequencer.c              |  9 +++++----
 sequencer.h              |  8 +++++---
 3 files changed, 17 insertions(+), 13 deletions(-)
builtin/rebase--helper.c +7 -6
index c3b8e4d401f8..1102ecb43b67 100644
@@ -12,7 +12,7 @@ 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;
-	int keep_empty = 0;
+	unsigned flags = 0, keep_empty = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		CHECK_TODO_LIST, SKIP_UNNECESSARY_PICKS, REARRANGE_SQUASH
@@ -48,16 +48,17 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	argc = parse_options(argc, argv, NULL, options,
 			builtin_rebase_helper_usage, PARSE_OPT_KEEP_ARGV0);
 
+	flags |= keep_empty ? TODO_LIST_KEEP_EMPTY : 0;
+	flags |= command == SHORTEN_OIDS ? TODO_LIST_SHORTEN_IDS : 0;
+
 	if (command == CONTINUE && argc == 1)
 		return !!sequencer_continue(&opts);
 	if (command == ABORT && argc == 1)
 		return !!sequencer_remove_state(&opts);
 	if (command == MAKE_SCRIPT && argc > 1)
-		return !!sequencer_make_script(keep_empty, stdout, argc, argv);
-	if (command == SHORTEN_OIDS && argc == 1)
-		return !!transform_todos(1);
-	if (command == EXPAND_OIDS && argc == 1)
-		return !!transform_todos(0);
+		return !!sequencer_make_script(stdout, argc, argv, flags);
+	if ((command == SHORTEN_OIDS || command == EXPAND_OIDS) && argc == 1)
+		return !!transform_todos(flags);
 	if (command == CHECK_TODO_LIST && argc == 1)
 		return !!check_todo_list();
 	if (command == SKIP_UNNECESSARY_PICKS && argc == 1)
sequencer.c +5 -4
index c9a661a8c4bd..8b0dd610c881 100644
@@ -2444,14 +2444,15 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
 	strbuf_release(&sob);
 }
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags)
 {
 	char *format = NULL;
 	struct pretty_print_context pp = {0};
 	struct strbuf buf = STRBUF_INIT;
 	struct rev_info revs;
 	struct commit *commit;
+	int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
 
 	init_revisions(&revs, NULL);
 	revs.verbose_header = 1;
@@ -2494,7 +2495,7 @@ int sequencer_make_script(int keep_empty, FILE *out,
 }
 
 
-int transform_todos(int shorten_ids)
+int transform_todos(unsigned flags)
 {
 	const char *todo_file = rebase_path_todo();
 	struct todo_list todo_list = TODO_LIST_INIT;
@@ -2522,7 +2523,7 @@ int transform_todos(int shorten_ids)
 
 		/* add commit id */
 		if (item->commit) {
-			const char *oid = shorten_ids ?
+			const char *oid = flags & TODO_LIST_SHORTEN_IDS ?
 					  short_commit_name(item->commit) :
 					  oid_to_hex(&item->commit->object.oid);
 
sequencer.h +5 -3
index 4f7f2c93f83e..68284e9762c8 100644
@@ -45,10 +45,12 @@ int sequencer_continue(struct replay_opts *opts);
 int sequencer_rollback(struct replay_opts *opts);
 int sequencer_remove_state(struct replay_opts *opts);
 
-int sequencer_make_script(int keep_empty, FILE *out,
-		int argc, const char **argv);
+#define TODO_LIST_KEEP_EMPTY (1U << 0)
+#define TODO_LIST_SHORTEN_IDS (1U << 1)
+int sequencer_make_script(FILE *out, int argc, const char **argv,
+			  unsigned flags);
 
-int transform_todos(int shorten_ids);
+int transform_todos(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
 int rearrange_squash(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#65 lore raw

PATCH v3 7/9 rebase -i -x: add exec commands via the rebase--helper

In reply to Liam Beguin

Recent work on git-rebase--interactive aims to convert shell code to C. Even if this is most likely not a big performance enhancement, let's convert it too since a coming change to abbreviate command names requires it to be updated.

---
 builtin/rebase--helper.c   |  7 ++++++-
 git-rebase--interactive.sh | 23 +---------------------
 sequencer.c                | 39 ++++++++++++++++++++++++++++++++++++++
 sequencer.h                |  1 +
 4 files changed, 47 insertions(+), 23 deletions(-)
builtin/rebase--helper.c +6 -1
index 1102ecb43b67..4229ea0dc122 100644
@@ -15,7 +15,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 	unsigned flags = 0, keep_empty = 0;
 	enum {
 		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,
+		ADD_EXEC
 	} command = 0;
 	struct option options[] = {
 		OPT_BOOL(0, "ff", &opts.allow_ff, N_("allow fast-forward")),
@@ -36,6 +37,8 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 			N_("skip unnecessary picks"), SKIP_UNNECESSARY_PICKS),
 		OPT_CMDMODE(0, "rearrange-squash", &command,
 			N_("rearrange fixup/squash lines"), REARRANGE_SQUASH),
+		OPT_CMDMODE(0, "add-exec-commands", &command,
+			N_("insert exec commands in todo list"), ADD_EXEC),
 		OPT_END()
 	};
 
@@ -65,5 +68,7 @@ int cmd_rebase__helper(int argc, const char **argv, const char *prefix)
 		return !!skip_unnecessary_picks();
 	if (command == REARRANGE_SQUASH && argc == 1)
 		return !!rearrange_squash();
+	if (command == ADD_EXEC && argc == 2)
+		return !!sequencer_add_exec_commands(argv[1]);
 	usage_with_options(builtin_rebase_helper_usage, options);
 }
git-rebase--interactive.sh +1 -22
index 437815669f00..e3f5a0abf3c7 100644
@@ -722,27 +722,6 @@ collapse_todo_ids() {
 	git rebase--helper --shorten-ids
 }
 
-# Add commands after a pick or after a squash/fixup series
-# in the todo list.
-add_exec_commands () {
-	{
-		first=t
-		while read -r insn rest
-		do
-			case $insn in
-			pick)
-				test -n "$first" ||
-				printf "%s" "$cmd"
-				;;
-			esac
-			printf "%s %s\n" "$insn" "$rest"
-			first=
-		done
-		printf "%s" "$cmd"
-	} <"$1" >"$1.new" &&
-	mv "$1.new" "$1"
-}
-
 # Switch to the branch in $into and notify it in the reflog
 checkout_onto () {
 	GIT_REFLOG_ACTION="$GIT_REFLOG_ACTION: checkout $onto_name"
@@ -982,7 +961,7 @@ fi
 
 test -s "$todo" || echo noop >> "$todo"
 test -z "$autosquash" || git rebase--helper --rearrange-squash || exit
-test -n "$cmd" && add_exec_commands "$todo"
+test -n "$cmd" && git rebase--helper --add-exec-commands "$cmd"
 
 todocount=$(git stripspace --strip-comments <"$todo" | wc -l)
 todocount=${todocount##* }
sequencer.c +39 -0
index 8b0dd610c881..892d242f6966 100644
@@ -2494,6 +2494,45 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 	return 0;
 }
 
+/*
+ * Add commands after pick and (series of) squash/fixup commands
+ * in the todo list.
+ */
+int sequencer_add_exec_commands(const char *commands)
+{
+	const char *todo_file = rebase_path_todo();
+	struct todo_list todo_list = TODO_LIST_INIT;
+	struct todo_item *item;
+	struct strbuf *buf = &todo_list.buf;
+	size_t offset = 0, commands_len = strlen(commands);
+	int i, first;
+
+	if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
+		return error(_("could not read '%s'."), todo_file);
+
+	if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
+		todo_list_release(&todo_list);
+		return error(_("unusable todo list: '%s'"), todo_file);
+	}
+
+	first = 1;
+	/* insert <commands> before every pick except the first one */
+	for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
+		if (item->command == TODO_PICK && !first) {
+			strbuf_insert(buf, item->offset_in_buf + offset,
+				      commands, commands_len);
+			offset += commands_len;
+		}
+		first = 0;
+	}
+
+	/* append final <commands> */
+	strbuf_add(buf, commands, commands_len);
+
+	i = write_message(buf->buf, buf->len, todo_file, 0);
+	todo_list_release(&todo_list);
+	return i;
+}
 
 int transform_todos(unsigned flags)
 {
sequencer.h +1 -0
index 68284e9762c8..212426c44548 100644
@@ -50,6 +50,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 int sequencer_make_script(FILE *out, int argc, const char **argv,
 			  unsigned flags);
 
+int sequencer_add_exec_commands(const char *command);
 int transform_todos(unsigned flags);
 int check_todo_list(void);
 int skip_unnecessary_picks(void);
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#66 lore raw

PATCH v3 8/9 rebase -i: learn to abbreviate command names

In reply to Liam Beguin

git rebase -i already know how to interpret single-letter command names. Teach it to generate the todo list with these same abbreviated names.

---
 Documentation/rebase-config.txt | 20 ++++++++++++++++++++
 builtin/rebase--helper.c        |  3 +++
 sequencer.c                     | 16 ++++++++++++++--
 sequencer.h                     |  1 +
 4 files changed, 38 insertions(+), 2 deletions(-)
Documentation/rebase-config.txt +20 -0
index 30ae08cb5a4b..42e1ba757564 100644
@@ -30,3 +30,23 @@ rebase.instructionFormat::
 	A format string, as specified in linkgit:git-log[1], to be used for the
 	todo list during an interactive rebase.  The format will
 	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.
builtin/rebase--helper.c +3 -0
index 4229ea0dc122..7daee544b7b4 100644
@@ -13,6 +13,7 @@ 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;
+	int abbreviate_commands = 0;
 	enum {
 		CONTINUE = 1, ABORT, MAKE_SCRIPT, SHORTEN_OIDS, EXPAND_OIDS,
 		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_get_bool("rebase.abbreviatecommands", &abbreviate_commands);
 
 	opts.action = REPLAY_INTERACTIVE_REBASE;
 	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);
 
 	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;
 
 	if (command == CONTINUE && argc == 1)
sequencer.c +14 -2
index 892d242f6966..115085d39ca8 100644
@@ -795,6 +795,13 @@ static const char *command_to_string(const enum todo_command 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)
 {
 	return TODO_NOOP <= command;
@@ -2453,6 +2460,7 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 	struct rev_info revs;
 	struct commit *commit;
 	int keep_empty = flags & TODO_LIST_KEEP_EMPTY;
+	const char *insn = flags & TODO_LIST_ABBREVIATE_CMDS ? "p" : "pick";
 
 	init_revisions(&revs, NULL);
 	revs.verbose_header = 1;
@@ -2485,7 +2493,8 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
 		strbuf_reset(&buf);
 		if (!keep_empty && is_original_commit_empty(commit))
 			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);
 		strbuf_addch(&buf, '\n');
 		fputs(buf.buf, out);
@@ -2558,7 +2567,10 @@ int transform_todos(unsigned flags)
 		}
 
 		/* 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 */
 		if (item->commit) {
sequencer.h +1 -0
index 212426c44548..81f6d7d393fd 100644
@@ -47,6 +47,7 @@ int sequencer_remove_state(struct replay_opts *opts);
 
 #define TODO_LIST_KEEP_EMPTY (1U << 0)
 #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,
 			  unsigned flags);
 
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#67 lore raw

PATCH v3 9/9 t3404: add test case for abbreviated commands

In reply to Liam Beguin

Make sure the todo list ends up using single-letter command abbreviations when the rebase.abbreviateCommands is enabled. This configuration option should not change anything else.

---
 t/t3404-rebase-interactive.sh | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
t/t3404-rebase-interactive.sh +22 -0
index 6a82d1ed876d..481a3500900d 100755
@@ -1260,6 +1260,28 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
 	test B = $(git cat-file commit HEAD^ | sed -ne \$p)
 '
 
+test_expect_success 'respects rebase.abbreviateCommands with fixup, squash and exec' '
+	rebase_setup_and_clean abbrevcmd &&
+	test_commit "first" file1.txt "first line" first &&
+	test_commit "second" file1.txt "another line" second &&
+	test_commit "fixup! first" file2.txt "first line again" first_fixup &&
+	test_commit "squash! second" file1.txt "another line here" second_squash &&
+	cat >expected <<-EOF &&
+	p $(git rev-list --abbrev-commit -1 first) first
+	f $(git rev-list --abbrev-commit -1 first_fixup) fixup! first
+	x git show HEAD
+	p $(git rev-list --abbrev-commit -1 second) second
+	s $(git rev-list --abbrev-commit -1 second_squash) squash! second
+	x git show HEAD
+	EOF
+	git checkout abbrevcmd &&
+	set_cat_todo_editor &&
+	test_config rebase.abbreviateCommands true &&
+	test_must_fail git rebase -i --exec "git show HEAD" \
+		--autosquash master >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'static check of bad command' '
 	rebase_setup_and_clean bad-cmd &&
 	set_fake_editor &&
Signature · 1 line
2.15.1.280.g10402c1f5b5c
#68 lore raw
In reply to Liam Beguin
Quoted 23 lines · Liam Beguin

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Changes in V2:
- Refactor and rename 'transform_todo_ids'
- Replace SHA-1 by OID in rebase--helper.c
- Update todo list related functions to take a generic 'flags' parameter
- Rename 'add_exec_commands' function to 'sequencer_add_exec_commands'
- Rename 'add-exec' option to 'add-exec-commands'
- Use 'strbur_read_file' instead of rewriting it
- Make 'command_to_char' return 'comment_char_line' if no single-letter command name is defined
- Combine both tests into a single test case
- Update commit messages

Quoted 3 lines

Changes in V2:
- Rename 'transform_todo_insn' to 'transform_todos'
- Fix flag name TODO_LIST_SHORTE{D,N}_IDS

I've replaced this series and pushed out the result.

Thanks.

#69 lore raw
Quoted 25 lines · Junio C Hamano
Quoted 23 lines · Liam Beguin

This series will add the 'rebase.abbreviateCommands' configuration option to allow git rebase -i to default to the single-letter command names when generating the todo list.

Using single-letter command names can present two benefits. First, it makes it easier to change the action since you only need to replace a single character (i.e.: in vim "r<character>" instead of "ciw<character>"). Second, using this with a large enough value of 'core.abbrev' enables the lines of the todo list to remain aligned making the files easier to read.

Changes in V2:
- Refactor and rename 'transform_todo_ids'
- Replace SHA-1 by OID in rebase--helper.c
- Update todo list related functions to take a generic 'flags' parameter
- Rename 'add_exec_commands' function to 'sequencer_add_exec_commands'
- Rename 'add-exec' option to 'add-exec-commands'
- Use 'strbur_read_file' instead of rewriting it
- Make 'command_to_char' return 'comment_char_line' if no single-letter command name is defined
- Combine both tests into a single test case
- Update commit messages

Quoted 5 lines
Quoted 3 lines

Changes in V2:
- Rename 'transform_todo_insn' to 'transform_todos'
- Fix flag name TODO_LIST_SHORTE{D,N}_IDS

I've replaced this series and pushed out the result.

Great! Thanks again,

Quoted 3 lines

Thanks.

Liam