git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Liam Beguin <liambeguin@gmail.com>
Date
Dec 5, 2017, 17:52 UTC
Message-ID
<20171205175235.32319-9-liambeguin@gmail.com>
In-Reply-To
<20171205175235.32319-1-liambeguin@gmail.com>

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

Based-on-patch-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Liam Beguin <liambeguin@gmail.com>
---
 Documentation/rebase-config.txt | 20 ++++++++++++++++++++
 builtin/rebase--helper.c        |  3 +++
 sequencer.c                     | 16 ++++++++++++++--
 sequencer.h                     |  1 +
 4 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/Documentation/rebase-config.txt b/Documentation/rebase-config.txt
index 30ae08cb5a4b..42e1ba757564 100644
--- a/Documentation/rebase-config.txt
+++ b/Documentation/rebase-config.txt
@@ -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.
diff --git a/builtin/rebase--helper.c b/builtin/rebase--helper.c
index 4229ea0dc122..7daee544b7b4 100644
--- a/builtin/rebase--helper.c
+++ b/builtin/rebase--helper.c
@@ -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)
diff --git a/sequencer.c b/sequencer.c
index 892d242f6966..115085d39ca8 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -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) {
diff --git a/sequencer.h b/sequencer.h
index 212426c44548..81f6d7d393fd 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -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);
 
-- 
2.15.1.280.g10402c1f5b5c
Previous: Liam BeguinNext: Liam Beguin
Message 66 of 70 in “rebase -i: add config to abbreviate command names”
  1. 0/5 rebase -i: add config to abbreviate command namesLiam Beguin, Nov 27, 2017
  2. 3/5 rebase -i: add exec commands via the rebase--helperLiam Beguin, Nov 27, 2017
  3. Junio C HamanoNov 27, 2017
  4. Johannes SchindelinNov 27, 2017
  5. Junio C HamanoNov 27, 2017
  6. liam BeguinNov 29, 2017
  7. Johannes SchindelinNov 27, 2017
  8. Junio C HamanoNov 27, 2017
  9. liam BeguinNov 29, 2017
  10. Johannes SchindelinNov 29, 2017
  11. 4/5 rebase -i: learn to abbreviate command namesLiam Beguin, Nov 27, 2017
  12. Junio C HamanoNov 27, 2017
  13. liam BeguinNov 29, 2017
  14. Johannes SchindelinNov 27, 2017
  15. Jeff KingNov 27, 2017
  16. liam BeguinNov 29, 2017
  17. liam BeguinNov 29, 2017
  18. Johannes SchindelinNov 29, 2017
  19. Junio C HamanoDec 3, 2017
  20. 5/5 t3404: add test case for abbreviated commandsLiam Beguin, Nov 27, 2017
  21. Junio C HamanoNov 27, 2017
  22. Johannes SchindelinNov 27, 2017
  23. 2/5 Documentation: use preferred name for the 'todo list' scriptLiam Beguin, Nov 27, 2017
  24. Johannes SchindelinNov 27, 2017
  25. 1/5 Documentation: move rebase.* configs to new fileLiam Beguin, Nov 27, 2017
  26. Johannes SchindelinNov 27, 2017
  27. Junio C HamanoNov 27, 2017
  28. liam BeguinNov 29, 2017
  29. 0/9 rebase -i: add config to abbreviate command namesLiam Beguin, Dec 3, 2017
  30. 1/9 Documentation: move rebase.* configs to new fileLiam Beguin, Dec 3, 2017
  31. 2/9 Documentation: use preferred name for the 'todo list' scriptLiam Beguin, Dec 3, 2017
  32. 5/9 rebase -i: replace reference to sha1 with oidLiam Beguin, Dec 3, 2017
  33. 4/9 rebase -i: refactor transform_todo_idsLiam Beguin, Dec 3, 2017
  34. Johannes SchindelinDec 4, 2017
  35. Junio C HamanoDec 4, 2017
  36. liam BeguinDec 5, 2017
  37. Junio C HamanoDec 5, 2017
  38. liam BeguinDec 5, 2017
  39. 7/9 rebase -i -x: add exec commands via the rebase--helperLiam Beguin, Dec 3, 2017
  40. 6/9 rebase -i: update functions to use a flags parameterLiam Beguin, Dec 3, 2017
  41. Johannes SchindelinDec 4, 2017
  42. Johannes SchindelinDec 4, 2017
  43. liam BeguinDec 5, 2017
  44. Junio C HamanoDec 5, 2017
  45. Kerry, RichardDec 5, 2017
  46. liam BeguinDec 5, 2017
  47. Junio C HamanoDec 5, 2017
  48. Kerry, RichardDec 5, 2017
  49. 3/9 rebase -i: set commit to null in exec commandsLiam Beguin, Dec 3, 2017
  50. 9/9 t3404: add test case for abbreviated commandsLiam Beguin, Dec 3, 2017
  51. 8/9 rebase -i: learn to abbreviate command namesLiam Beguin, Dec 3, 2017
  52. Duy NguyenDec 25, 2017
  53. Liam BeguinDec 25, 2017
  54. Duy NguyenDec 25, 2017
  55. Junio C HamanoDec 27, 2017
  56. Liam BeguinDec 27, 2017
  57. Junio C HamanoDec 28, 2017
  58. Johannes SchindelinDec 4, 2017
  59. 0/9 rebase -i: add config to abbreviate command namesLiam Beguin, Dec 5, 2017
  60. 1/9 Documentation: move rebase.* configs to new fileLiam Beguin, Dec 5, 2017
  61. 2/9 Documentation: use preferred name for the 'todo list' scriptLiam Beguin, Dec 5, 2017
  62. 3/9 rebase -i: set commit to null in exec commandsLiam Beguin, Dec 5, 2017
  63. 4/9 rebase -i: refactor transform_todo_idsLiam Beguin, Dec 5, 2017
  64. 5/9 rebase -i: replace reference to sha1 with oidLiam Beguin, Dec 5, 2017
  65. 7/9 rebase -i -x: add exec commands via the rebase--helperLiam Beguin, Dec 5, 2017
  66. 8/9 rebase -i: learn to abbreviate command namesLiam Beguin, Dec 5, 2017
  67. 6/9 rebase -i: update functions to use a flags parameterLiam Beguin, Dec 5, 2017
  68. 9/9 t3404: add test case for abbreviated commandsLiam Beguin, Dec 5, 2017
  69. Junio C HamanoDec 5, 2017
  70. liam BeguinDec 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.