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

[PATCH v2 5/9] commit: use enum value for multiple cherry-picks

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Dec 6, 2019, 16:06 UTC
Message-ID
<20191206160614.631724-6-phillip.wood123@gmail.com>
In-Reply-To
<20191206160614.631724-1-phillip.wood123@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Add FROM_CHERRY_PICK_MULTI for a sequence of cherry-picks rather than using a separate variable.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/commit.c | 25 +++++++++++--------------
 wt-status.h      |  9 ++++++++-
 2 files changed, 19 insertions(+), 15 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index d85e0ad560..3b463522be 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -122,7 +122,6 @@ static enum commit_msg_cleanup_mode cleanup_mode;
 static const char *cleanup_arg;
 
 static enum commit_whence whence;
-static int sequencer_in_use;
 static int use_editor = 1, include_status = 1;
 static int have_option_m;
 static struct strbuf message = STRBUF_INIT;
@@ -179,11 +178,9 @@ static void determine_whence(struct wt_status *s)
 {
 	if (file_exists(git_path_merge_head(the_repository)))
 		whence = FROM_MERGE;
-	else if (file_exists(git_path_cherry_pick_head(the_repository))) {
-		whence = FROM_CHERRY_PICK;
-		if (file_exists(git_path_seq_dir()))
-			sequencer_in_use = 1;
-	}
+	else if (file_exists(git_path_cherry_pick_head(the_repository)))
+		whence = file_exists(git_path_seq_dir()) ?
+			FROM_CHERRY_PICK_MULTI : FROM_CHERRY_PICK_SINGLE;
 	else
 		whence = FROM_COMMIT;
 	if (s)
@@ -453,7 +450,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
 	if (whence != FROM_COMMIT) {
 		if (whence == FROM_MERGE)
 			die(_("cannot do a partial commit during a merge."));
-		else if (whence == FROM_CHERRY_PICK)
+		else if (is_from_cherry_pick(whence))
 			die(_("cannot do a partial commit during a cherry-pick."));
 	}
 
@@ -771,7 +768,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	 */
 	else if (whence == FROM_MERGE)
 		hook_arg1 = "merge";
-	else if (whence == FROM_CHERRY_PICK) {
+	else if (is_from_cherry_pick(whence)) {
 		hook_arg1 = "commit";
 		hook_arg2 = "CHERRY_PICK_HEAD";
 	}
@@ -948,9 +945,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		run_status(stdout, index_file, prefix, 0, s);
 		if (amend)
 			fputs(_(empty_amend_advice), stderr);
-		else if (whence == FROM_CHERRY_PICK) {
+		else if (is_from_cherry_pick(whence)) {
 			fputs(_(empty_cherry_pick_advice), stderr);
-			if (!sequencer_in_use)
+			if (whence == FROM_CHERRY_PICK_SINGLE)
 				fputs(_(empty_cherry_pick_advice_single), stderr);
 			else
 				fputs(_(empty_cherry_pick_advice_multi), stderr);
@@ -1143,7 +1140,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (amend && whence != FROM_COMMIT) {
 		if (whence == FROM_MERGE)
 			die(_("You are in the middle of a merge -- cannot amend."));
-		else if (whence == FROM_CHERRY_PICK)
+		else if (is_from_cherry_pick(whence))
 			die(_("You are in the middle of a cherry-pick -- cannot amend."));
 	}
 	if (fixup_message && squash_message)
@@ -1166,7 +1163,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
 		use_message = edit_message;
 	if (amend && !use_message && !fixup_message)
 		use_message = "HEAD";
-	if (!use_message && whence != FROM_CHERRY_PICK && renew_authorship)
+	if (!use_message && !is_from_cherry_pick(whence) && renew_authorship)
 		die(_("--reset-author can be used only with -C, -c or --amend."));
 	if (use_message) {
 		use_message_buffer = read_commit_message(use_message);
@@ -1175,7 +1172,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
 			author_message_buffer = use_message_buffer;
 		}
 	}
-	if (whence == FROM_CHERRY_PICK && !renew_authorship) {
+	if (is_from_cherry_pick(whence) && !renew_authorship) {
 		author_message = "CHERRY_PICK_HEAD";
 		author_message_buffer = read_commit_message(author_message);
 	}
@@ -1589,7 +1586,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 			reduce_heads_replace(&parents);
 	} else {
 		if (!reflog_msg)
-			reflog_msg = (whence == FROM_CHERRY_PICK)
+			reflog_msg = is_from_cherry_pick(whence)
 					? "commit (cherry-pick)"
 					: "commit";
 		commit_list_insert(current_head, &parents);
diff --git a/wt-status.h b/wt-status.h
index 64f1ddc9fd..0098fdb0b5 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -39,9 +39,16 @@ enum show_ignored_type {
 enum commit_whence {
 	FROM_COMMIT,     /* normal */
 	FROM_MERGE,      /* commit came from merge */
-	FROM_CHERRY_PICK /* commit came from cherry-pick */
+	FROM_CHERRY_PICK_SINGLE, /* commit came from cherry-pick */
+	FROM_CHERRY_PICK_MULTI /* commit came from a sequence of cherry-picks */
 };
 
+static inline int is_from_cherry_pick(enum commit_whence whence)
+{
+	return whence == FROM_CHERRY_PICK_SINGLE ||
+		whence == FROM_CHERRY_PICK_MULTI;
+}
+
 struct wt_status_change_data {
 	int worktree_status;
 	int index_status;
-- 
2.24.0
Previous: Phillip WoodNext: Junio C Hamano
Message 25 of 31 in “commit: fix advice for empty commits during rebases”
  1. 0/3 commit: fix advice for empty commits during rebasesJohannes Schindelin via GitGitGadget, Oct 22, 2019
  2. 2/3 sequencer: export the function to get the path of `.git/rebase-merge/`Johannes Schindelin via GitGitGadget, Oct 22, 2019
  3. 1/3 cherry-pick: add test for `--skip` advice in `git commit`Johannes Schindelin via GitGitGadget, Oct 22, 2019
  4. 3/3 commit: give correct advice for empty commit during a rebaseJohannes Schindelin via GitGitGadget, Oct 22, 2019
  5. Junio C HamanoOct 23, 2019
  6. Phillip WoodOct 24, 2019
  7. Johannes SchindelinOct 25, 2019
  8. Phillip WoodOct 25, 2019
  9. Junio C HamanoNov 8, 2019
  10. Johannes SchindelinNov 8, 2019
  11. Phillip WoodNov 11, 2019
  12. Junio C HamanoOct 23, 2019
  13. Johannes SchindelinOct 25, 2019
  14. Junio C HamanoOct 29, 2019
  15. Johannes SchindelinOct 29, 2019
  16. 0/9 commit: fix advice for empty commits during rebasesPhillip Wood, Dec 6, 2019
  17. 2/9 cherry-pick: add test for `--skip` advice in `git commit`Phillip Wood, Dec 6, 2019
  18. 4/9 sequencer: write CHERRY_PICK_HEAD for reword and editPhillip Wood, Dec 6, 2019
  19. 3/9 cherry-pick: check commit error messagesPhillip Wood, Dec 6, 2019
  20. 1/9 t3404: use test_cmp_revPhillip Wood, Dec 6, 2019
  21. Junio C HamanoDec 6, 2019
  22. 6/9 commit: encapsulate determine_whence() for sequencerPhillip Wood, Dec 6, 2019
  23. Junio C HamanoDec 6, 2019
  24. Phillip WoodDec 18, 2019
  25. 5/9 commit: use enum value for multiple cherry-picksPhillip Wood, Dec 6, 2019
  26. Junio C HamanoDec 6, 2019
  27. 9/9 [RFC] rebase -i: leave CHERRY_PICK_HEAD when there are conflictsPhillip Wood, Dec 6, 2019
  28. Phillip WoodDec 18, 2019
  29. 7/9 commit: give correct advice for empty commit during a rebasePhillip Wood, Dec 6, 2019
  30. 8/9 [RFC] rebase: fix advice when a fixup creates an empty commitPhillip Wood, Dec 6, 2019
  31. Elijah NewrenFeb 26, 2020

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.