]> Kevux Git Server - rit/commitdiff
object-name: turn INTERPRET_BRANCH_* constants into enum values
authorJialong Wang <jerrywang183@yahoo.com>
Wed, 18 Mar 2026 19:09:42 +0000 (15:09 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Mar 2026 19:52:29 +0000 (12:52 -0700)
Replace the INTERPRET_BRANCH_* preprocessor constants with enum
values and use that type where these flags are stored or passed
around.

These flags describe which kinds of branches may be considered during
branch-name interpretation, so represent them as an enum describing
branch kinds while keeping the existing bitmask semantics and
INTERPRET_BRANCH_* element names.

Signed-off-by: Jialong Wang <jerrywang183@yahoo.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/branch.c
object-name.c
object-name.h
refs.c
refs.h

index a1a4338..1572a4f 100644 (file)
@@ -228,7 +228,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
        int ret = 0;
        int remote_branch = 0;
        struct strbuf bname = STRBUF_INIT;
-       unsigned allowed_interpret;
+       enum interpret_branch_kind allowed_interpret;
        struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
        struct string_list_item *item;
        int branch_name_pos;
index 7b14c3b..2b2a043 100644 (file)
@@ -1660,7 +1660,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
 
 static int reinterpret(struct repository *r,
                       const char *name, int namelen, int len,
-                      struct strbuf *buf, unsigned allowed)
+                      struct strbuf *buf,
+                      enum interpret_branch_kind allowed)
 {
        /* we have extra data, which might need further processing */
        struct strbuf tmp = STRBUF_INIT;
@@ -1692,7 +1693,8 @@ static void set_shortened_ref(struct repository *r, struct strbuf *buf, const ch
        free(s);
 }
 
-static int branch_interpret_allowed(const char *refname, unsigned allowed)
+static int branch_interpret_allowed(const char *refname,
+                                   enum interpret_branch_kind allowed)
 {
        if (!allowed)
                return 1;
index cda4934..167a915 100644 (file)
@@ -101,9 +101,12 @@ int set_disambiguate_hint_config(const char *var, const char *value);
  * If the input was ok but there are not N branch switches in the
  * reflog, it returns 0.
  */
-#define INTERPRET_BRANCH_LOCAL (1<<0)
-#define INTERPRET_BRANCH_REMOTE (1<<1)
-#define INTERPRET_BRANCH_HEAD (1<<2)
+enum interpret_branch_kind {
+       INTERPRET_BRANCH_LOCAL = (1 << 0),
+       INTERPRET_BRANCH_REMOTE = (1 << 1),
+       INTERPRET_BRANCH_HEAD = (1 << 2),
+};
+
 struct interpret_branch_name_options {
        /*
         * If "allowed" is non-zero, it is a treated as a bitfield of allowable
@@ -111,7 +114,7 @@ struct interpret_branch_name_options {
         * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
         * allowed, even ones to refs outside of those namespaces.
         */
-       unsigned allowed;
+       enum interpret_branch_kind allowed;
 
        /*
         * If ^{upstream} or ^{push} (or equivalent) is requested, and the
diff --git a/refs.c b/refs.c
index 6fb8f9d..18b28db 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -740,7 +740,8 @@ static char *substitute_branch_name(struct repository *r,
        return NULL;
 }
 
-void copy_branchname(struct strbuf *sb, const char *name, unsigned allowed)
+void copy_branchname(struct strbuf *sb, const char *name,
+                    enum interpret_branch_kind allowed)
 {
        int len = strlen(name);
        struct interpret_branch_name_options options = {
diff --git a/refs.h b/refs.h
index d98c1fc..d65de6a 100644 (file)
--- a/refs.h
+++ b/refs.h
@@ -1,6 +1,7 @@
 #ifndef REFS_H
 #define REFS_H
 
+#include "object-name.h"
 #include "commit.h"
 #include "repository.h"
 #include "repo-settings.h"
@@ -225,7 +226,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
  * repo_interpret_branch_name() for details.
  */
 void copy_branchname(struct strbuf *sb, const char *name,
-                      unsigned allowed);
+                    enum interpret_branch_kind allowed);
 
 /*
  * Like copy_branchname() above, but confirm that the result is