refs: add ref_type function
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 97a75f3c3125d6a73e020ee2da73fcb6cce3d13c..58be2595e590b7feff438d18365f8d0cb4bbcae3 100644 (file)
--- 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;