object-name: turn INTERPRET_BRANCH_* constants into enum values
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>
Jialong Wang committed
Mar 18, 2026 at 15:09 UTC
c5fc44f54595f123c277e5839cbafa1bc9c8c050
5 files changed
+16
-9
builtin/branch.c
+1
-1
@@ -228,7 +228,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
228
int ret = 0;
229
int remote_branch = 0;
230
struct strbuf bname = STRBUF_INIT;
231
- unsigned allowed_interpret;
231
+ enum interpret_branch_kind allowed_interpret;
232
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
233
struct string_list_item *item;
234
int branch_name_pos;
object-name.c
+4
-2
@@ -1660,7 +1660,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
1660
1661
static int reinterpret(struct repository *r,
1662
const char *name, int namelen, int len,
1663
- struct strbuf *buf, unsigned allowed)
1663
+ struct strbuf *buf,
1664
+ enum interpret_branch_kind allowed)
1665
{
1666
/* we have extra data, which might need further processing */
1667
struct strbuf tmp = STRBUF_INIT;
@@ -1692,7 +1693,8 @@ static void set_shortened_ref(struct repository *r, struct strbuf *buf, const ch
1693
free(s);
1694
}
1695
1695
-static int branch_interpret_allowed(const char *refname, unsigned allowed)
1696
+static int branch_interpret_allowed(const char *refname,
1697
+ enum interpret_branch_kind allowed)
1698
{
1699
if (!allowed)
1700
return 1;
object-name.h
+7
-4
@@ -101,9 +101,12 @@ int set_disambiguate_hint_config(const char *var, const char *value);
101
* If the input was ok but there are not N branch switches in the
102
* reflog, it returns 0.
103
*/
104
-#define INTERPRET_BRANCH_LOCAL (1<<0)
105
-#define INTERPRET_BRANCH_REMOTE (1<<1)
106
-#define INTERPRET_BRANCH_HEAD (1<<2)
104
+enum interpret_branch_kind {
105
+ INTERPRET_BRANCH_LOCAL = (1 << 0),
106
+ INTERPRET_BRANCH_REMOTE = (1 << 1),
107
+ INTERPRET_BRANCH_HEAD = (1 << 2),
108
+};
109
+
110
struct interpret_branch_name_options {
111
/*
112
* If "allowed" is non-zero, it is a treated as a bitfield of allowable
@@ -111,7 +114,7 @@ struct interpret_branch_name_options {
114
* ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
115
* allowed, even ones to refs outside of those namespaces.
116
*/
114
- unsigned allowed;
117
+ enum interpret_branch_kind allowed;
118
119
/*
120
* If ^{upstream} or ^{push} (or equivalent) is requested, and the
refs.c
+2
-1
@@ -740,7 +740,8 @@ static char *substitute_branch_name(struct repository *r,
740
return NULL;
741
}
742
743
-void copy_branchname(struct strbuf *sb, const char *name, unsigned allowed)
743
+void copy_branchname(struct strbuf *sb, const char *name,
744
+ enum interpret_branch_kind allowed)
745
{
746
int len = strlen(name);
747
struct interpret_branch_name_options options = {
refs.h
+2
-1
@@ -1,6 +1,7 @@
1
#ifndef REFS_H
2
#define REFS_H
3
4
+#include "object-name.h"
5
#include "commit.h"
6
#include "repository.h"
7
#include "repo-settings.h"
@@ -225,7 +226,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
226
* repo_interpret_branch_name() for details.
227
*/
228
void copy_branchname(struct strbuf *sb, const char *name,
228
- unsigned allowed);
229
+ enum interpret_branch_kind allowed);
230
231
/*
232
* Like copy_branchname() above, but confirm that the result is