Skip to content

Commit 266b182

Browse files
dturner-twgitster
authored andcommitted
refs: add ref_type function
Add a function ref_type, which categorizes refs as per-worktree, pseudoref, or normal ref. Later, we will use this in refs.c to treat pseudorefs specially. Alternate ref backends may use it to treat both pseudorefs and per-worktree refs differently. Signed-off-by: David Turner <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2036cb9 commit 266b182

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

refs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,6 +2821,32 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
28212821
return 0;
28222822
}
28232823

2824+
static int is_per_worktree_ref(const char *refname)
2825+
{
2826+
return !strcmp(refname, "HEAD");
2827+
}
2828+
2829+
static int is_pseudoref_syntax(const char *refname)
2830+
{
2831+
const char *c;
2832+
2833+
for (c = refname; *c; c++) {
2834+
if (!isupper(*c) && *c != '-' && *c != '_')
2835+
return 0;
2836+
}
2837+
2838+
return 1;
2839+
}
2840+
2841+
enum ref_type ref_type(const char *refname)
2842+
{
2843+
if (is_per_worktree_ref(refname))
2844+
return REF_TYPE_PER_WORKTREE;
2845+
if (is_pseudoref_syntax(refname))
2846+
return REF_TYPE_PSEUDOREF;
2847+
return REF_TYPE_NORMAL;
2848+
}
2849+
28242850
int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flags)
28252851
{
28262852
struct ref_transaction *transaction;

refs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,14 @@ int update_ref(const char *msg, const char *refname,
380380
extern int parse_hide_refs_config(const char *var, const char *value, const char *);
381381
extern int ref_is_hidden(const char *);
382382

383+
enum ref_type {
384+
REF_TYPE_PER_WORKTREE,
385+
REF_TYPE_PSEUDOREF,
386+
REF_TYPE_NORMAL,
387+
};
388+
389+
enum ref_type ref_type(const char *refname);
390+
383391
enum expire_reflog_flags {
384392
EXPIRE_REFLOGS_DRY_RUN = 1 << 0,
385393
EXPIRE_REFLOGS_UPDATE_REF = 1 << 1,

0 commit comments

Comments
 (0)