git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC] Suffix /HEAD everywhere.

From
Junio C Hamano <junkio@cox.net>
Date
Apr 22, 2006, 05:55 UTC
Message-ID
<7vhd4mnogs.fsf@assigned-by-dhcp.cox.net>

This is another throw-away idea, but people doing Porcelain might be interested.

We currently allow "origin" to mean $GIT_DIR/refs/remotes/origin/HEAD, to give consistent "git fetch origin" semantics for repositories cloned with the --use-separate-remote option.

Why not extend this to places other than "refs/remotes/*"?  
With this patch, I could arrange the refs like this:
	$GIT_DIR/refs/heads/master/
        $GIT_DIR/refs/heads/master/HEAD (symref points at somewhere)
	$GIT_DIR/refs/heads/master/master (perhaps here)
        $GIT_DIR/refs/heads/master/topic1 (topic branched from "master")
        $GIT_DIR/refs/heads/master/topic2 (another)

and I can just say "master" to mean refs/heads/master/master, and say "master/topic1", "master/topic1" to name the topic branches.

This patch only does the reading side, and when somebody tries to implement creation/update side, some unsurmountable problems may be discovered, but it just seemed an interesting idea. I do not know how useful it is, tho.

-jc
diff --git a/sha1_name.c b/sha1_name.c
index 345935b..ab2eaf7 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -237,13 +237,15 @@ static int ambiguous_path(const char *pa
 static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
 {
 	static const char *fmt[] = {
-		"%.*s",
-		"refs/%.*s",
-		"refs/tags/%.*s",
-		"refs/heads/%.*s",
-		"refs/remotes/%.*s",
-		"refs/remotes/%.*s/HEAD",
-		NULL
+		"%.*s%s",
+		"refs/%.*s%s",
+		"refs/tags/%.*s%s",
+		"refs/heads/%.*s%s",
+		"refs/remotes/%.*s%s",
+	};
+	static const char *sfx[] = {
+		"",
+		"/HEAD",
 	};
 	const char **p;
 	const char *warning = "warning: refname '%.*s' is ambiguous.\n";
@@ -259,17 +261,21 @@ static int get_sha1_basic(const char *st
 	if (ambiguous_path(str, len))
 		return -1;
 
-	for (p = fmt; *p; p++) {
-		this_result = already_found ? sha1_from_ref : sha1;
-		pathname = git_path(*p, len, str);
-		if (!read_ref(pathname, this_result)) {
-			if (warn_ambiguous_refs) {
-				if (already_found)
-					fprintf(stderr, warning, len, str);
-				already_found++;
+	for (p = fmt; p < fmt + ARRAY_SIZE(fmt); p++) {
+		const char **s;
+		for (s = sfx; s < sfx + ARRAY_SIZE(sfx); s++) {
+			this_result = already_found ? sha1_from_ref : sha1;
+			pathname = git_path(*p, len, str, *s);
+			if (!read_ref(pathname, this_result)) {
+				if (warn_ambiguous_refs) {
+					if (already_found)
+						fprintf(stderr, warning,
+							len, str);
+					already_found++;
+				}
+				else
+					return 0;
 			}
-			else
-				return 0;
 		}
 	}
 	if (already_found)
Message 1 of 1 in “[RFC] Suffix /HEAD everywhere.”
  1. Junio C HamanoApr 22, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.