git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:29 UTC

[PATCH v3 7/9] sequencer: simplify pick_one_commit()

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 15, 2026, 15:22 UTC
Message-ID
<7c1642b0a49027a8851aa5985f4020d8e76414d1.1784128921.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1784128921.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Unless we're rebasing, all we do in pick_one_commit() is call do_pick_commit() and return its result. Simplify the code by returning early if we're not rebasing so that we don't have to repeatedly call is_rebase_i() in the rest of the function. Note that there are a couple of conditions that do not call is_rebase_i() but they check for either an "edit" or a "fixup" command, both of which imply we're rebasing.

The only block that does not return early is the one guarded by "!res". Move the return into that block to make it clear that after recording the commit as rewritten, all we do is return from the function.

As the conditional blocks are all mutually exclusive (either the conditions are mutually exclusive, or an earlier conditional block that would match a later one contains a "return" statement) chain them together with "else if" to make that clear.

While we could remove "res" from the conditions below "if (!res)" they are left alone because, when we start using an enum in the next commit, it makes it clear that these clauses are handling cases where there are conflicts.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 sequencer.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/sequencer.c b/sequencer.c
index 8f3eed205e7..9016af9b5d7 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4966,12 +4966,14 @@ static int pick_one_commit(struct repository *r,
 
 	res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
 			     check_todo);
-	if (is_rebase_i(opts) && res < 0) {
+	if (!is_rebase_i(opts))
+		return res;
+
+	if (res < 0) {
 		/* Reschedule */
 		*reschedule = 1;
 		return -1;
-	}
-	if (item->command == TODO_EDIT) {
+	} else if (item->command == TODO_EDIT) {
 		struct commit *commit = item->commit;
 		if (!res) {
 			if (!opts->verbose)
@@ -4981,14 +4983,14 @@ static int pick_one_commit(struct repository *r,
 		}
 		return error_with_patch(r, commit,
 					arg, item->arg_len, opts, res, !res);
-	}
-	if (is_rebase_i(opts) && !res)
+	} else if (!res) {
 		record_in_rewritten(&item->commit->object.oid,
 				    peek_command(todo_list, 1));
-	if (res && is_fixup(item->command)) {
+		return 0;
+	} else if (res && is_fixup(item->command)) {
 		return error_failed_squash(r, item->commit, opts,
 					   item->arg_len, arg);
-	} else if (res && is_rebase_i(opts)) {
+	} else if (res) {
 		int to_amend = 0;
 		struct object_id oid;
 
@@ -5008,7 +5010,8 @@ static int pick_one_commit(struct repository *r,
 		return error_with_patch(r, item->commit, arg, item->arg_len,
 					opts, res, to_amend);
 	}
-	return res;
+
+	BUG("Unhandled return value from do_pick_commit()");
 }
 
 static int pick_commits(struct repository *r,
-- 
2.54.0.200.gfd8d68259e3
Previous: Phillip WoodNext: Phillip Wood
Message 57 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. 09/11 sequencer: return early from pick_one_commit() on successPhillip Wood, Jun 30, 2026
  16. 11/11 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jun 30, 2026
  17. 10/11 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jun 30, 2026
  18. Junio C HamanoJun 30, 2026
  19. Uwe Kleine-KönigJul 1, 2026
  20. Uwe Kleine-KönigJul 1, 2026
  21. Phillip WoodJul 1, 2026
  22. Phillip WoodJul 1, 2026
  23. Phillip WoodJul 1, 2026
  24. Oswald BuddenhagenJul 6, 2026
  25. Oswald BuddenhagenJul 6, 2026
  26. Oswald BuddenhagenJul 6, 2026
  27. Phillip WoodJul 6, 2026
  28. Phillip WoodJul 6, 2026
  29. Junio C HamanoJul 13, 2026
  30. 00/10 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 13, 2026
  31. 01/10 t3400: restore coverage for note copying with apply backendPhillip Wood, Jul 13, 2026
  32. 02/10 sequencer: move definition of is_final_fixup()Phillip Wood, Jul 13, 2026
  33. 03/10 sequencer: be more careful with external mergePhillip Wood, Jul 13, 2026
  34. 04/10 sequencer: never reschedule on failed commitPhillip Wood, Jul 13, 2026
  35. 05/10 sequencer: remove unnecessary "or" in pick_one_commit()Phillip Wood, Jul 13, 2026
  36. 06/10 sequencer: simplify handing of fixup with conflictsPhillip Wood, Jul 13, 2026
  37. 07/10 sequencer: remove unnecessary condition in pick_one_commit()Phillip Wood, Jul 13, 2026
  38. 08/10 sequencer: simplify pick_one_commit()Phillip Wood, Jul 13, 2026
  39. 09/10 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jul 13, 2026
  40. 10/10 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 13, 2026
  41. Oswald BuddenhagenJul 13, 2026
  42. Oswald BuddenhagenJul 13, 2026
  43. Oswald BuddenhagenJul 13, 2026
  44. Junio C HamanoJul 13, 2026
  45. Andrei RybakJul 14, 2026
  46. Phillip WoodJul 15, 2026
  47. Phillip WoodJul 15, 2026
  48. Phillip WoodJul 15, 2026
  49. Phillip WoodJul 15, 2026
  50. 1/9 t3400: restore coverage for note copying with apply backendPhillip Wood, Jul 15, 2026
  51. 0/9 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 15, 2026
  52. 3/9 sequencer: never reschedule on failed commitPhillip Wood, Jul 15, 2026
  53. 2/9 sequencer: be more careful with external mergePhillip Wood, Jul 15, 2026
  54. 4/9 sequencer: remove unnecessary "or" in pick_one_commit()Phillip Wood, Jul 15, 2026
  55. 5/9 sequencer: simplify handling of fixup with conflictsPhillip Wood, Jul 15, 2026
  56. 6/9 sequencer: remove unnecessary condition in pick_one_commit()Phillip Wood, Jul 15, 2026
  57. 7/9 sequencer: simplify pick_one_commit()Phillip Wood, Jul 15, 2026
  58. 8/9 sequencer: use an enum to represent result of picking a commitPhillip Wood, Jul 15, 2026
  59. 9/9 sequencer: do not record dropped commits as rewrittenPhillip Wood, Jul 15, 2026
  60. Junio C HamanoJul 15, 2026
  61. Uwe Kleine-KönigJul 18, 2026
  62. Phillip WoodJul 18, 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.