aboutsummaryrefslogtreecommitdiffstats
path: root/refs.c
diff options
context:
space:
mode:
authorDerrick Stolee <derrickstolee@github.com>2022-08-05 17:58:36 +0000
committerJunio C Hamano <gitster@pobox.com>2022-08-05 14:13:12 -0700
commitb9342b3fd6308c351f53075c9c4339913b73451f (patch)
treeef50c609adb612e0ddb04f3ef0e72bfd8f3490c2 /refs.c
parent5797b13919f8073108e58ab5cea39f4e6bbfa1c9 (diff)
downloadgit-b9342b3fd6308c351f53075c9c4339913b73451f.tar.gz
refs: add array of ref namespaces
Git interprets different meanings to different refs based on their names. Some meanings are cosmetic, like how refs in 'refs/remotes/*' are colored differently from refs in 'refs/heads/*'. Others are more critical, such as how replace refs are interpreted. Before making behavior changes based on ref namespaces, collect all known ref namespaces into a array of ref_namespace_info structs. This array is indexed by the new ref_namespace enum for quick access. As of this change, this array is purely documentation. Future changes will add dependencies on this array. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r--refs.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/refs.c b/refs.c
index 3fdfa86a5b..65decf25d0 100644
--- a/refs.c
+++ b/refs.c
@@ -20,6 +20,7 @@
#include "repository.h"
#include "sigchain.h"
#include "date.h"
+#include "commit.h"
/*
* List of all available backends
@@ -56,6 +57,88 @@ static unsigned char refname_disposition[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 4, 4
};
+struct ref_namespace_info ref_namespace[] = {
+ [NAMESPACE_HEAD] = {
+ .ref = "HEAD",
+ .decoration = DECORATION_REF_HEAD,
+ .exact = 1,
+ },
+ [NAMESPACE_BRANCHES] = {
+ .ref = "refs/heads/",
+ .decoration = DECORATION_REF_LOCAL,
+ },
+ [NAMESPACE_TAGS] = {
+ .ref = "refs/tags/",
+ .decoration = DECORATION_REF_TAG,
+ },
+ [NAMESPACE_REMOTE_REFS] = {
+ /*
+ * The default refspec for new remotes copies refs from
+ * refs/heads/ on the remote into refs/remotes/<remote>/.
+ * As such, "refs/remotes/" has special handling.
+ */
+ .ref = "refs/remotes/",
+ .decoration = DECORATION_REF_REMOTE,
+ },
+ [NAMESPACE_STASH] = {
+ /*
+ * The single ref "refs/stash" stores the latest stash.
+ * Older stashes can be found in the reflog.
+ */
+ .ref = "refs/stash",
+ .exact = 1,
+ .decoration = DECORATION_REF_STASH,
+ },
+ [NAMESPACE_REPLACE] = {
+ /*
+ * This namespace allows Git to act as if one object ID
+ * points to the content of another. Unlike the other
+ * ref namespaces, this one can be changed by the
+ * GIT_REPLACE_REF_BASE environment variable. This
+ * .namespace value will be overwritten in setup_git_env().
+ */
+ .ref = "refs/replace/",
+ .decoration = DECORATION_GRAFTED,
+ },
+ [NAMESPACE_NOTES] = {
+ /*
+ * The refs/notes/commit ref points to the tip of a
+ * parallel commit history that adds metadata to commits
+ * in the normal history. This ref can be overwritten
+ * by the core.notesRef config variable or the
+ * GIT_NOTES_REFS environment variable.
+ */
+ .ref = "refs/notes/commit",
+ .exact = 1,
+ },
+ [NAMESPACE_PREFETCH] = {
+ /*
+ * Prefetch refs are written by the background 'fetch'
+ * maintenance task. It allows faster foreground fetches
+ * by advertising these previously-downloaded tips without
+ * updating refs/remotes/ without user intervention.
+ */
+ .ref = "refs/prefetch/",
+ },
+ [NAMESPACE_REWRITTEN] = {
+ /*
+ * Rewritten refs are used by the 'label' command in the
+ * sequencer. These are particularly useful during an
+ * interactive rebase that uses the 'merge' command.
+ */
+ .ref = "refs/rewritten/",
+ },
+};
+
+void update_ref_namespace(enum ref_namespace namespace, char *ref)
+{
+ struct ref_namespace_info *info = &ref_namespace[namespace];
+ if (info->ref_updated)
+ free(info->ref);
+ info->ref = ref;
+ info->ref_updated = 1;
+}
+
/*
* Try to read one refname component from the front of refname.
* Return the length of the component found, or -1 if the component is