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

[PATCH v2 09/10] sequencer: use an enum to represent result of picking a commit

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 13, 2026, 13:17 UTC
Message-ID
<4fb641afb3cb99858ccabd69d4a052a6b19b6148.1783948637.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1783948637.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Rather than using an integer where -1 is an error, 0 is success and 1 means there were conflicts use an enum. This is clearer and lets us add a separate return value for commits that are dropped because they become empty in the next commit.

Note we continue to use "return error(...)" to return errors and take advantage of C's lax typing of enums

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c | 61 +++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 45 insertions(+), 16 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index ff4547d417e..4b89349251b 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2260,10 +2260,16 @@ static const char *reflog_message(struct replay_opts *opts,
 	return buf.buf;
 }
 
-static int do_pick_commit(struct repository *r,
-			  struct todo_item *item,
-			  struct replay_opts *opts,
-			  int final_fixup, int *check_todo)
+enum pick_result {
+	PICK_RESULT_ERROR = -1,
+	PICK_RESULT_OK,
+	PICK_RESULT_CONFLICTS,
+};
+
+static enum pick_result do_pick_commit(struct repository *r,
+				       struct todo_item *item,
+				       struct replay_opts *opts,
+				       int final_fixup, int *check_todo)
 {
 	struct replay_ctx *ctx = opts->ctx;
 	unsigned int flags = should_edit(opts) ? EDIT_MSG : 0;
@@ -2564,7 +2570,12 @@ static int do_pick_commit(struct repository *r,
 	free(author);
 	update_abort_safety_file();
 
-	return res;
+	if (res < 0)
+		return PICK_RESULT_ERROR;
+	else if (res > 0)
+		return PICK_RESULT_CONFLICTS;
+	else
+		return PICK_RESULT_OK;
 }
 
 static int prepare_revs(struct replay_opts *opts)
@@ -4960,37 +4971,47 @@ static int pick_one_commit(struct repository *r,
 			   struct replay_opts *opts,
 			   int *check_todo, int* reschedule)
 {
-	int res;
+	enum pick_result pick_res;
 	struct todo_item *item = todo_list->items + todo_list->current;
 	const char *arg = todo_item_get_arg(todo_list, item);
 
-	res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
-			     check_todo);
+	pick_res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
+				  check_todo);
 	if (!is_rebase_i(opts))
-		return res;
+		switch (pick_res) {
+		case PICK_RESULT_ERROR:
+			return -1;
+		case PICK_RESULT_CONFLICTS:
+			return 1;
+		default:
+			return 0;
+		}
 
-	if (res < 0) {
+	if (pick_res == PICK_RESULT_ERROR) {
 		/* Reschedule */
 		*reschedule = 1;
 		return -1;
 	} else if (item->command == TODO_EDIT) {
 		struct commit *commit = item->commit;
-		if (!res) {
+		int res = pick_res == PICK_RESULT_CONFLICTS;
+
+		if (pick_res == PICK_RESULT_OK) {
 			if (!opts->verbose)
 				term_clear_line();
 			fprintf(stderr, _("Stopped at %s...  %.*s\n"),
 				short_commit_name(r, commit), item->arg_len, arg);
 		}
 		return error_with_patch(r, commit,
 					arg, item->arg_len, opts, res, !res);
-	} else if (!res) {
+	} else if (pick_res == PICK_RESULT_OK) {
 		record_in_rewritten(&item->commit->object.oid,
 				    peek_command(todo_list, 1));
 		return 0;
-	} else if (res && is_fixup(item->command)) {
+	} else if (pick_res == PICK_RESULT_CONFLICTS &&
+		   is_fixup(item->command)) {
 		return error_failed_squash(r, item->commit, opts,
 					   item->arg_len, arg);
-	} else if (res) {
+	} else if (pick_res == PICK_RESULT_CONFLICTS) {
 		int to_amend = 0;
 		struct object_id oid;
 
@@ -5008,7 +5029,7 @@ static int pick_one_commit(struct repository *r,
 			to_amend = 1;
 
 		return error_with_patch(r, item->commit, arg, item->arg_len,
-					opts, res, to_amend);
+					opts, 1, to_amend);
 	}
 
 	BUG("Unhandled return value from do_pick_commit()");
@@ -5547,7 +5568,15 @@ static int single_pick(struct repository *r,
 			TODO_PICK : TODO_REVERT;
 	item.commit = cmit;
 
-	return do_pick_commit(r, &item, opts, 0, &check_todo);
+	switch (do_pick_commit(r, &item, opts, 0, &check_todo)) {
+	case PICK_RESULT_ERROR:
+		return -1;
+	case PICK_RESULT_CONFLICTS:
+		return 1;
+	default:
+		return 0;
+	}
+
 }
 
 int sequencer_pick_revisions(struct repository *r,
-- 
2.54.0.200.gfd8d68259e3
Previous: Phillip WoodNext: Phillip Wood
Message 50 of 67 in “sequencer: Skip copying notes for commits that disappear during rebase”
  1. sequencer: Skip copying notes for commits that disappear during rebaseUwe Kleine-König, Jun 16, 2026
  2. Junio C HamanoJun 17, 2026
  3. Uwe Kleine-KönigJun 17, 2026
  4. Phillip WoodJun 19, 2026
  5. Uwe Kleine-KönigJun 19, 2026
  6. 00/11 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jun 30, 2026
  7. 01/11 t3400: restore coverage for note copying with apply backendPhillip Wood, Jun 30, 2026
  8. 02/11 sequencer: move definition of is_final_fixup()Phillip Wood, Jun 30, 2026
  9. 03/11 sequencer: be more careful with external mergePhillip Wood, Jun 30, 2026
  10. 04/11 sequencer: never reschedule on failed commitPhillip Wood, Jun 30, 2026
  11. 05/11 sequencer: remove unnecessary "or" in pick_one_commit()Phillip Wood, Jun 30, 2026
  12. 06/11 sequencer: simplify handing of fixup with conflictsPhillip Wood, Jun 30, 2026
  13. 07/11 sequencer: remove unnecessary condition in pick_one_commit()Phillip Wood, Jun 30, 2026
  14. 08/11 sequencer: simplify pick_one_commit()Phillip Wood, Jun 30, 2026
  15. Oswald BuddenhagenJul 6, 2026
  16. Phillip WoodJul 6, 2026
  17. 09/11 sequencer: return early from pick_one_commit() on successPhillip Wood, Jun 30, 2026
  18. Oswald BuddenhagenJul 6, 2026
  19. 11/11 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jun 30, 2026
  20. 10/11 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jun 30, 2026
  21. Oswald BuddenhagenJul 6, 2026
  22. Phillip WoodJul 6, 2026
  23. Junio C HamanoJun 30, 2026
  24. Uwe Kleine-KönigJul 1, 2026
  25. Phillip WoodJul 1, 2026
  26. Phillip WoodJul 1, 2026
  27. Junio C HamanoJul 13, 2026
  28. Uwe Kleine-KönigJul 1, 2026
  29. Phillip WoodJul 1, 2026
  30. Uwe Kleine-KönigJul 18, 2026
  31. Phillip WoodJul 18, 2026
  32. 00/10 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 13, 2026
  33. 01/10 t3400: restore coverage for note copying with apply backendPhillip Wood, Jul 13, 2026
  34. Oswald BuddenhagenJul 13, 2026
  35. 02/10 sequencer: move definition of is_final_fixup()Phillip Wood, Jul 13, 2026
  36. Andrei RybakJul 14, 2026
  37. Phillip WoodJul 15, 2026
  38. 03/10 sequencer: be more careful with external mergePhillip Wood, Jul 13, 2026
  39. Oswald BuddenhagenJul 13, 2026
  40. Phillip WoodJul 15, 2026
  41. Phillip WoodJul 15, 2026
  42. Junio C HamanoJul 15, 2026
  43. 04/10 sequencer: never reschedule on failed commitPhillip Wood, Jul 13, 2026
  44. 05/10 sequencer: remove unnecessary "or" in pick_one_commit()Phillip Wood, Jul 13, 2026
  45. 06/10 sequencer: simplify handing of fixup with conflictsPhillip Wood, Jul 13, 2026
  46. Oswald BuddenhagenJul 13, 2026
  47. Phillip WoodJul 15, 2026
  48. 07/10 sequencer: remove unnecessary condition in pick_one_commit()Phillip Wood, Jul 13, 2026
  49. 08/10 sequencer: simplify pick_one_commit()Phillip Wood, Jul 13, 2026
  50. 09/10 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jul 13, 2026
  51. 10/10 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 13, 2026
  52. Junio C HamanoJul 13, 2026
  53. 0/9 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 15, 2026
  54. 1/9 t3400: restore coverage for note copying with apply backendPhillip Wood, Jul 15, 2026
  55. 3/9 sequencer: never reschedule on failed commitPhillip Wood, Jul 15, 2026
  56. 2/9 sequencer: be more careful with external mergePhillip Wood, Jul 15, 2026
  57. 4/9 sequencer: remove unnecessary "or" in pick_one_commit()Phillip Wood, Jul 15, 2026
  58. 5/9 sequencer: simplify handling of fixup with conflictsPhillip Wood, Jul 15, 2026
  59. 6/9 sequencer: remove unnecessary condition in pick_one_commit()Phillip Wood, Jul 15, 2026
  60. 7/9 sequencer: simplify pick_one_commit()Phillip Wood, Jul 15, 2026
  61. 8/9 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jul 15, 2026
  62. 9/9 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 15, 2026
  63. Junio C HamanoJul 19, 2026
  64. Oswald BuddenhagenJul 20, 2026
  65. Junio C HamanoJul 20, 2026
  66. gerrit code review once more (was: Re: [PATCH v3 0/9] sequencer: do not record dropped commits as) rewrittenOswald Buddenhagen, Jul 20, 2026
  67. Phillip WoodJul 22, 2026

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.