summaryrefslogtreecommitdiff
path: root/refs.c
diff options
context:
space:
mode:
authorDavid Turner <dturner@twopensource.com>2015-07-31 02:06:18 -0400
committerJunio C Hamano <gitster@pobox.com>2015-07-31 10:39:04 -0700
commit266b18273a742a33970e634d1858f292befdf943 (patch)
tree11a91064dada002949a634393882489543e12db1 /refs.c
parent2036cb98d00b888262c3dbfad7e14ffd95165028 (diff)
downloadgit-266b18273a742a33970e634d1858f292befdf943.tar.gz
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 <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index 97a75f3c31..58be2595e5 100644
--- a/refs.c
+++ b/refs.c
@@ -2821,6 +2821,32 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
return 0;
}
+static int is_per_worktree_ref(const char *refname)
+{
+ return !strcmp(refname, "HEAD");
+}
+
+static int is_pseudoref_syntax(const char *refname)
+{
+ const char *c;
+
+ for (c = refname; *c; c++) {
+ if (!isupper(*c) && *c != '-' && *c != '_')
+ return 0;
+ }
+
+ return 1;
+}
+
+enum ref_type ref_type(const char *refname)
+{
+ if (is_per_worktree_ref(refname))
+ return REF_TYPE_PER_WORKTREE;
+ if (is_pseudoref_syntax(refname))
+ return REF_TYPE_PSEUDOREF;
+ return REF_TYPE_NORMAL;
+}
+
int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flags)
{
struct ref_transaction *transaction;