From: Jialong Wang <jerrywang183@yahoo.com>
To: git@vger.kernel.org
Cc: karthik.188@gmail.com, gitster@pobox.com,
Jialong Wang <jerrywang183@yahoo.com>
Subject: [GSoC PATCH] object-name: turn INTERPRET_BRANCH_* constants into enum values
Date: Tue, 17 Mar 2026 20:39:17 -0400 [thread overview]
Message-ID: <20260318003917.84792-1-jerrywang183@yahoo.com> (raw)
In-Reply-To: 20260318003917.84792-1-jerrywang183.ref@yahoo.com
Replace the INTERPRET_BRANCH_* preprocessor constants with enum values and use the enum type where these flags are stored or passed around.
This keeps the existing bitmask semantics, but gives the branch-name interpretation flags a dedicated type instead of plain unsigned values.
---
builtin/branch.c | 2 +-
object-name.c | 7 +++++--
object-name.h | 11 +++++++----
refs.c | 3 ++-
refs.h | 3 ++-
5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index a1a43380d0..6ef6a7ca0f 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -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_name_allowed allowed_interpret;
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
struct string_list_item *item;
int branch_name_pos;
diff --git a/object-name.c b/object-name.c
index 7b14c3bf9b..fbf7c5dbf0 100644
--- a/object-name.c
+++ b/object-name.c
@@ -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_name_allowed allowed)
{
/* we have extra data, which might need further processing */
struct strbuf tmp = STRBUF_INIT;
@@ -1692,7 +1693,9 @@ 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_name_allowed allowed)
{
if (!allowed)
return 1;
diff --git a/object-name.h b/object-name.h
index cda4934cd5..a544b65235 100644
--- a/object-name.h
+++ b/object-name.h
@@ -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_name_allowed {
+ 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_name_allowed allowed;
/*
* If ^{upstream} or ^{push} (or equivalent) is requested, and the
diff --git a/refs.c b/refs.c
index 6fb8f9d10c..b3b39ce37f 100644
--- 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_name_allowed allowed)
{
int len = strlen(name);
struct interpret_branch_name_options options = {
diff --git a/refs.h b/refs.h
index d98c1fc591..8a5b034f8a 100644
--- 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_name_allowed allowed);
/*
* Like copy_branchname() above, but confirm that the result is
--
2.51.0
next parent reply other threads:[~2026-03-18 1:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260318003917.84792-1-jerrywang183.ref@yahoo.com>
2026-03-18 0:39 ` Jialong Wang [this message]
2026-03-18 16:27 ` [GSoC PATCH] object-name: turn INTERPRET_BRANCH_* constants into enum values Junio C Hamano
2026-03-18 19:09 ` [GSoC PATCH v2] " Jialong Wang
2026-03-20 10:25 ` Karthik Nayak
2026-03-20 20:12 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260318003917.84792-1-jerrywang183@yahoo.com \
--to=jerrywang183@yahoo.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=karthik.188@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.