aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-02 10:17:37 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-02 09:43:57 -0700
commit9c50fa3c8fbcc4cf7a3d528409d49bde950986de (patch)
tree055d216a535c6150a0472829704e25b090190235
parent7a1a577a354cccc1e9db6e0b2dbace1b742f3ce2 (diff)
downloadgit-9c50fa3c8fbcc4cf7a3d528409d49bde950986de.tar.gz
refs: classify HEAD as a root ref
Notice: this object is not reachable from any branch.
Root refs are those refs that live in the root of the ref hierarchy. Our old and venerable "HEAD" reference falls into this category, but we don't yet classify it as such in `is_root_ref()`. Adapt the function to also treat "HEAD" as a root ref. This change is safe to do for all current callers: - `ref_kind_from_refname()` already handles "HEAD" explicitly before calling `is_root_ref()`. - The "files" and "reftable" backends explicitly called both `is_root_ref()` and `is_headref()`. This change should thus essentially be a no-op. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Notice: this object is not reachable from any branch.
-rw-r--r--refs.c2
-rw-r--r--refs.h6
-rw-r--r--refs/files-backend.c3
-rw-r--r--refs/reftable-backend.c3
4 files changed, 9 insertions, 5 deletions
diff --git a/refs.c b/refs.c
index 6266f77474..5b89e83ad7 100644
--- a/refs.c
+++ b/refs.c
@@ -874,6 +874,8 @@ int is_root_ref(struct ref_store *refs, const char *refname)
if (!is_root_ref_syntax(refname))
return 0;
+ if (is_headref(refs, refname))
+ return 1;
if (ends_with(refname, "_HEAD")) {
refs_resolve_ref_unsafe(refs, refname,
diff --git a/refs.h b/refs.h
index d0374c3275..4ac454b0c3 100644
--- a/refs.h
+++ b/refs.h
@@ -1059,7 +1059,8 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref);
*
* - Their name must be all-uppercase or underscores ("_").
*
- * - Their name must end with "_HEAD".
+ * - Their name must end with "_HEAD". As a special rule, "HEAD" is a root
+ * ref, as well.
*
* - Their name may not contain a slash.
*
@@ -1078,6 +1079,9 @@ void update_ref_namespace(enum ref_namespace namespace, char *ref);
*/
int is_root_ref(struct ref_store *refs, const char *refname);
+/*
+ * Check whether the reference is "HEAD" and whether it exists.
+ */
int is_headref(struct ref_store *refs, const char *refname);
#endif /* REFS_H */
diff --git a/refs/files-backend.c b/refs/files-backend.c
index 0fcb601444..ea927c516d 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -351,8 +351,7 @@ static void add_pseudoref_and_head_entries(struct ref_store *ref_store,
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(ref_store, de->d_name))
loose_fill_ref_dir_regular_file(refs, refname.buf, dir);
strbuf_setlen(&refname, dirnamelen);
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c
index 5a5e64fe69..41555fcf64 100644
--- a/refs/reftable-backend.c
+++ b/refs/reftable-backend.c
@@ -356,8 +356,7 @@ static int reftable_ref_iterator_advance(struct ref_iterator *ref_iterator)
*/
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_headref(&iter->refs->base, iter->ref.refname)))) {
+ is_root_ref(&iter->refs->base, iter->ref.refname))) {
continue;
}