[PATCH v2 3/9] reset: modernize flags passed to `reset_head()`
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Jun 3, 2026, 16:14 UTC
- Message-ID
- <20260603-b4-pks-history-drop-v2-3-742cb5b5176d@pks.im>
- In-Reply-To
- <20260603-b4-pks-history-drop-v2-0-742cb5b5176d@pks.im>
The flags passed to `reset_head()` are declared as defines. This has fallen a bit out of practice nowadays, where we instead prefer to use enums.
Modernize the code accordingly.
Signed-off-by: Patrick Steinhardt <ps@pks.im> --- builtin/rebase.c | 2 +- reset.c | 4 ++-- reset.h | 30 ++++++++++++++++++------------ sequencer.c | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c index fa4f5d9306..6351a3aa32 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1876,7 +1876,7 @@ int cmd_rebase(int argc, options.reflog_action, options.onto_name); ropts.oid = &options.onto->object.oid; ropts.orig_head = &options.orig_head->object.oid; - ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD | + ropts.flags = RESET_HEAD_DETACH | RESET_HEAD_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK; ropts.head_msg = msg.buf; ropts.default_reflog_action = options.reflog_action; diff --git a/reset.c b/reset.c index 3b3cb74dab..9ff14f5ed1 100644 --- a/reset.c +++ b/reset.c @@ -18,7 +18,7 @@ static int update_refs(struct repository *repo, { unsigned detach_head = opts->flags & RESET_HEAD_DETACH; unsigned run_hook = opts->flags & RESET_HEAD_RUN_POST_CHECKOUT_HOOK; - unsigned update_orig_head = opts->flags & RESET_ORIG_HEAD; + unsigned update_orig_head = opts->flags & RESET_HEAD_ORIG_HEAD; const struct object_id *orig_head = opts->orig_head; const char *switch_to_branch = opts->branch; const char *reflog_branch = opts->branch_msg; @@ -91,7 +91,7 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) const char *switch_to_branch = opts->branch; unsigned reset_hard = opts->flags & RESET_HEAD_HARD; unsigned refs_only = opts->flags & RESET_HEAD_REFS_ONLY; - unsigned update_orig_head = opts->flags & RESET_ORIG_HEAD; + unsigned update_orig_head = opts->flags & RESET_HEAD_ORIG_HEAD; struct object_id *head = NULL, head_oid; struct tree_desc desc[2] = { { NULL }, { NULL } }; struct lock_file lock = LOCK_INIT; diff --git a/reset.h b/reset.h index a28f81829d..97ced2601e 100644 --- a/reset.h +++ b/reset.h @@ -6,16 +6,22 @@ #define GIT_REFLOG_ACTION_ENVIRONMENT "GIT_REFLOG_ACTION" -/* Request a detached checkout */ -#define RESET_HEAD_DETACH (1<<0) -/* Request a reset rather than a checkout */ -#define RESET_HEAD_HARD (1<<1) -/* Run the post-checkout hook */ -#define RESET_HEAD_RUN_POST_CHECKOUT_HOOK (1<<2) -/* Only update refs, do not touch the worktree */ -#define RESET_HEAD_REFS_ONLY (1<<3) -/* Update ORIG_HEAD as well as HEAD */ -#define RESET_ORIG_HEAD (1<<4) +enum reset_head_flags { + /* Request a detached checkout */ + RESET_HEAD_DETACH = (1 << 0), + + /* Request a reset rather than a checkout */ + RESET_HEAD_HARD = (1 << 1), + + /* Run the post-checkout hook */ + RESET_HEAD_RUN_POST_CHECKOUT_HOOK = (1 << 2), + + /* Only update refs, do not touch the worktree */ + RESET_HEAD_REFS_ONLY = (1 << 3), + + /* Update ORIG_HEAD as well as HEAD */ + RESET_HEAD_ORIG_HEAD = (1 << 4), +}; struct reset_head_opts { /* @@ -33,7 +39,7 @@ struct reset_head_opts { /* * Flags defined above. */ - unsigned flags; + enum reset_head_flags flags; /* * Optional reflog message for branch, defaults to head_msg. */ @@ -45,7 +51,7 @@ struct reset_head_opts { const char *head_msg; /* * Optional reflog message for ORIG_HEAD, if this omitted and flags - * contains RESET_ORIG_HEAD then default_reflog_action must be given. + * contains RESET_HEAD_ORIG_HEAD then default_reflog_action must be given. */ const char *orig_head_msg; /* diff --git a/sequencer.c b/sequencer.c index 1ee4b2875b..0b89a977b0 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4870,7 +4870,7 @@ static int checkout_onto(struct repository *r, struct replay_opts *opts, struct reset_head_opts ropts = { .oid = onto, .orig_head = orig_head, - .flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD | + .flags = RESET_HEAD_DETACH | RESET_HEAD_ORIG_HEAD | RESET_HEAD_RUN_POST_CHECKOUT_HOOK, .head_msg = reflog_message(opts, "start", "checkout %s", onto_name),
-- 2.54.0.1064.gd145956f57.dirty