Skip to content

Commit c5fc44f

Browse files
Jialong Wanggitster
authored andcommitted
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>
1 parent ca1db8a commit c5fc44f

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
228228
int ret = 0;
229229
int remote_branch = 0;
230230
struct strbuf bname = STRBUF_INIT;
231-
unsigned allowed_interpret;
231+
enum interpret_branch_kind allowed_interpret;
232232
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
233233
struct string_list_item *item;
234234
int branch_name_pos;

object-name.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,8 @@ static int interpret_empty_at(const char *name, int namelen, int len, struct str
16601660

16611661
static int reinterpret(struct repository *r,
16621662
const char *name, int namelen, int len,
1663-
struct strbuf *buf, unsigned allowed)
1663+
struct strbuf *buf,
1664+
enum interpret_branch_kind allowed)
16641665
{
16651666
/* we have extra data, which might need further processing */
16661667
struct strbuf tmp = STRBUF_INIT;
@@ -1692,7 +1693,8 @@ static void set_shortened_ref(struct repository *r, struct strbuf *buf, const ch
16921693
free(s);
16931694
}
16941695

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)
16961698
{
16971699
if (!allowed)
16981700
return 1;

object-name.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,20 @@ int set_disambiguate_hint_config(const char *var, const char *value);
101101
* If the input was ok but there are not N branch switches in the
102102
* reflog, it returns 0.
103103
*/
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+
107110
struct interpret_branch_name_options {
108111
/*
109112
* If "allowed" is non-zero, it is a treated as a bitfield of allowable
110113
* expansions: local branches ("refs/heads/"), remote branches
111114
* ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
112115
* allowed, even ones to refs outside of those namespaces.
113116
*/
114-
unsigned allowed;
117+
enum interpret_branch_kind allowed;
115118

116119
/*
117120
* If ^{upstream} or ^{push} (or equivalent) is requested, and the

refs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,8 @@ static char *substitute_branch_name(struct repository *r,
740740
return NULL;
741741
}
742742

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)
744745
{
745746
int len = strlen(name);
746747
struct interpret_branch_name_options options = {

refs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef REFS_H
22
#define REFS_H
33

4+
#include "object-name.h"
45
#include "commit.h"
56
#include "repository.h"
67
#include "repo-settings.h"
@@ -225,7 +226,7 @@ char *repo_default_branch_name(struct repository *r, int quiet);
225226
* repo_interpret_branch_name() for details.
226227
*/
227228
void copy_branchname(struct strbuf *sb, const char *name,
228-
unsigned allowed);
229+
enum interpret_branch_kind allowed);
229230

230231
/*
231232
* Like copy_branchname() above, but confirm that the result is

0 commit comments

Comments
 (0)