]> git.ipfire.org Git - thirdparty/git.git/commitdiff
reset: modernize flags passed to `reset_head()`
authorPatrick Steinhardt <ps@pks.im>
Wed, 3 Jun 2026 16:14:02 +0000 (18:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Jun 2026 00:04:24 +0000 (09:04 +0900)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/rebase.c
reset.c
reset.h
sequencer.c

index fa4f5d9306b856336970bf77b037cd5870aae4de..6351a3aa323c27e20b3982898427b60eddb3b1a6 100644 (file)
@@ -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 3b3cb74dabf164c409c5cba27399975281a88e7b..9ff14f5ed168affacbf45b370a611495056f2ae5 100644 (file)
--- 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 a28f81829d859dc3dfd3817d6449ab7eb195b0d3..97ced2601e35efed5672657333edc6926385a060 100644 (file)
--- 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;
        /*
index 1ee4b2875b25a08f6589314aae11ab5e3f35eecc..0b89a977b0bd2ec2b319cd759c1299438a0ef12d 100644 (file)
@@ -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),