sequencer: use an enum to represent result of picking a commit
Rather than using an integer where -1 is an error, 0 is success and 1 indicates 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Phillip Wood committed
Jul 15, 2026 at 16:22 UTC
a7dbb3a462eab29d5ca79c9cba175e0baeff6751
1 file changed
+45
-16
sequencer.c
+45
-16
@@ -2260,10 +2260,16 @@ static const char *reflog_message(struct replay_opts *opts,
2260
return buf.buf;
2261
}
2262
2263
-static int do_pick_commit(struct repository *r,
2264
- struct todo_item *item,
2265
- struct replay_opts *opts,
2266
- int final_fixup, int *check_todo)
2263
+enum pick_result {
2264
+ PICK_RESULT_ERROR = -1,
2265
+ PICK_RESULT_OK,
2266
+ PICK_RESULT_CONFLICTS,
2267
+};
2268
+
2269
+static enum pick_result do_pick_commit(struct repository *r,
2270
+ struct todo_item *item,
2271
+ struct replay_opts *opts,
2272
+ int final_fixup, int *check_todo)
2273
{
2274
struct replay_ctx *ctx = opts->ctx;
2275
unsigned int flags = should_edit(opts) ? EDIT_MSG : 0;
@@ -2564,7 +2570,12 @@ leave:
2570
free(author);
2571
update_abort_safety_file();
2572
2567
- return res;
2573
+ if (res < 0)
2574
+ return PICK_RESULT_ERROR;
2575
+ else if (res > 0)
2576
+ return PICK_RESULT_CONFLICTS;
2577
+ else
2578
+ return PICK_RESULT_OK;
2579
}
2580
2581
static int prepare_revs(struct replay_opts *opts)
@@ -4960,22 +4971,31 @@ static int pick_one_commit(struct repository *r,
4971
struct replay_opts *opts,
4972
int *check_todo, int* reschedule)
4973
{
4963
- int res;
4974
+ enum pick_result pick_res;
4975
struct todo_item *item = todo_list->items + todo_list->current;
4976
const char *arg = todo_item_get_arg(todo_list, item);
4977
4967
- res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
4968
- check_todo);
4978
+ pick_res = do_pick_commit(r, item, opts, is_final_fixup(todo_list),
4979
+ check_todo);
4980
if (!is_rebase_i(opts))
4970
- return res;
4981
+ switch (pick_res) {
4982
+ case PICK_RESULT_ERROR:
4983
+ return -1;
4984
+ case PICK_RESULT_CONFLICTS:
4985
+ return 1;
4986
+ default:
4987
+ return 0;
4988
+ }
4989
4972
- if (res < 0) {
4990
+ if (pick_res == PICK_RESULT_ERROR) {
4991
/* Reschedule */
4992
*reschedule = 1;
4993
return -1;
4994
} else if (item->command == TODO_EDIT) {
4995
struct commit *commit = item->commit;
4978
- if (!res) {
4996
+ int res = pick_res == PICK_RESULT_CONFLICTS;
4997
+
4998
+ if (pick_res == PICK_RESULT_OK) {
4999
if (!opts->verbose)
5000
term_clear_line();
5001
fprintf(stderr, _("Stopped at %s... %.*s\n"),
@@ -4983,14 +5003,15 @@ static int pick_one_commit(struct repository *r,
5003
}
5004
return error_with_patch(r, commit,
5005
arg, item->arg_len, opts, res, !res);
4986
- } else if (!res) {
5006
+ } else if (pick_res == PICK_RESULT_OK) {
5007
record_in_rewritten(&item->commit->object.oid,
5008
peek_command(todo_list, 1));
5009
return 0;
4990
- } else if (res && is_fixup(item->command)) {
5010
+ } else if (pick_res == PICK_RESULT_CONFLICTS &&
5011
+ is_fixup(item->command)) {
5012
return error_failed_squash(r, item->commit, opts,
5013
item->arg_len, arg);
4993
- } else if (res) {
5014
+ } else if (pick_res == PICK_RESULT_CONFLICTS) {
5015
int to_amend = 0;
5016
struct object_id oid;
5017
@@ -5008,7 +5029,7 @@ static int pick_one_commit(struct repository *r,
5029
to_amend = 1;
5030
5031
return error_with_patch(r, item->commit, arg, item->arg_len,
5011
- opts, res, to_amend);
5032
+ opts, 1, to_amend);
5033
}
5034
5035
BUG("Unhandled return value from do_pick_commit()");
@@ -5547,7 +5568,15 @@ static int single_pick(struct repository *r,
5568
TODO_PICK : TODO_REVERT;
5569
item.commit = cmit;
5570
5550
- return do_pick_commit(r, &item, opts, 0, &check_todo);
5571
+ switch (do_pick_commit(r, &item, opts, 0, &check_todo)) {
5572
+ case PICK_RESULT_ERROR:
5573
+ return -1;
5574
+ case PICK_RESULT_CONFLICTS:
5575
+ return 1;
5576
+ default:
5577
+ return 0;
5578
+ }
5579
+
5580
}
5581
5582
int sequencer_pick_revisions(struct repository *r,