return ref_kind[i].kind;
}
- if (is_root_ref(get_main_ref_store(the_repository), refname))
+ if (is_root_ref(refname))
return FILTER_REFS_PSEUDOREFS;
return FILTER_REFS_OTHERS;
return 1;
}
-int is_root_ref(struct ref_store *refs, const char *refname)
+int is_root_ref(const char *refname)
{
static const char *const irregular_root_refs[] = {
"AUTO_MERGE",
"NOTES_MERGE_REF",
"MERGE_AUTOSTASH",
};
- struct object_id oid;
size_t i;
if (!is_root_ref_syntax(refname))
return 0;
- if (ends_with(refname, "_HEAD")) {
- refs_resolve_ref_unsafe(refs, refname,
- RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- &oid, NULL);
- return !is_null_oid(&oid);
- }
+ if (ends_with(refname, "_HEAD"))
+ return 1;
for (i = 0; i < ARRAY_SIZE(irregular_root_refs); i++)
- if (!strcmp(refname, irregular_root_refs[i])) {
- refs_resolve_ref_unsafe(refs, refname,
- RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
- &oid, NULL);
- return !is_null_oid(&oid);
- }
+ if (!strcmp(refname, irregular_root_refs[i]))
+ return 1;
return 0;
}
void update_ref_namespace(enum ref_namespace namespace, char *ref);
/*
- * Check whether the reference is an existing root reference.
+ * Check whether the provided name names a root reference. This function only
+ * performs a syntactic check.
*
* A root ref is a reference that lives in the root of the reference hierarchy.
* These references must conform to special syntax:
*
* - MERGE_AUTOSTASH
*/
-int is_root_ref(struct ref_store *refs, const char *refname);
+int is_root_ref(const char *refname);
int is_headref(struct ref_store *refs, const char *refname);
strbuf_addstr(&refname, de->d_name);
dtype = get_dtype(de, &path, 1);
- if (dtype == DT_REG && (is_root_ref(ref_store, de->d_name) ||
- is_headref(ref_store, de->d_name)))
+ if (dtype == DT_REG && (is_root_ref(de->d_name) ||
+ is_headref(ref_store, de->d_name)))
loose_fill_ref_dir_regular_file(refs, refname.buf, dir);
strbuf_setlen(&refname, dirnamelen);
*/
if (!starts_with(iter->ref.refname, "refs/") &&
!(iter->flags & DO_FOR_EACH_INCLUDE_ROOT_REFS &&
- (is_root_ref(&iter->refs->base, iter->ref.refname) ||
+ (is_root_ref(iter->ref.refname) ||
is_headref(&iter->refs->base, iter->ref.refname)))) {
continue;
}
test_cmp expect actual
'
+test_expect_success '--include-root-refs omits dangling symrefs' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+ test_commit initial &&
+ git symbolic-ref DANGLING_HEAD refs/heads/missing &&
+ cat >expect <<-EOF &&
+ HEAD
+ $(git symbolic-ref HEAD)
+ refs/tags/initial
+ EOF
+ git for-each-ref --format="%(refname)" --include-root-refs >actual &&
+ test_cmp expect actual
+ )
+'
+
test_expect_success 'filtering with --points-at' '
cat >expect <<-\EOF &&
refs/heads/main