{"thread":{"id":"3943","subject":"[RFC] Suffix /HEAD everywhere.","startedAt":"2006-04-22T05:55:47Z","lastAt":"2006-04-22T05:55:47Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18992","messageId":"7vhd4mnogs.fsf@assigned-by-dhcp.cox.net","threadId":"3943","inReplyTo":null,"subject":"[RFC] Suffix /HEAD everywhere.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-04-22T05:55:47Z","receivedAt":"2006-04-22T05:55:47Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This is another throw-away idea, but people doing Porcelain\nmight be interested.\n\nWe currently allow \"origin\" to mean $GIT_DIR/refs/remotes/origin/HEAD,\nto give consistent \"git fetch origin\" semantics for repositories\ncloned with the --use-separate-remote option.\n\nWhy not extend this to places other than \"refs/remotes/*\"?  \n\nWith this patch, I could arrange the refs like this:\n\n\t$GIT_DIR/refs/heads/master/\n        $GIT_DIR/refs/heads/master/HEAD (symref points at somewhere)\n\t$GIT_DIR/refs/heads/master/master (perhaps here)\n        $GIT_DIR/refs/heads/master/topic1 (topic branched from \"master\")\n        $GIT_DIR/refs/heads/master/topic2 (another)\n\nand I can just say \"master\" to mean refs/heads/master/master,\nand say \"master/topic1\", \"master/topic1\" to name the topic\nbranches.\n\nThis patch only does the reading side, and when somebody tries\nto implement creation/update side, some unsurmountable problems\nmay be discovered, but it just seemed an interesting idea.  I do\nnot know how useful it is, tho.\n\n-jc\n\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 345935b..ab2eaf7 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -237,13 +237,15 @@ static int ambiguous_path(const char *pa\n static int get_sha1_basic(const char *str, int len, unsigned char *sha1)\n {\n \tstatic const char *fmt[] = {\n-\t\t\"%.*s\",\n-\t\t\"refs/%.*s\",\n-\t\t\"refs/tags/%.*s\",\n-\t\t\"refs/heads/%.*s\",\n-\t\t\"refs/remotes/%.*s\",\n-\t\t\"refs/remotes/%.*s/HEAD\",\n-\t\tNULL\n+\t\t\"%.*s%s\",\n+\t\t\"refs/%.*s%s\",\n+\t\t\"refs/tags/%.*s%s\",\n+\t\t\"refs/heads/%.*s%s\",\n+\t\t\"refs/remotes/%.*s%s\",\n+\t};\n+\tstatic const char *sfx[] = {\n+\t\t\"\",\n+\t\t\"/HEAD\",\n \t};\n \tconst char **p;\n \tconst char *warning = \"warning: refname '%.*s' is ambiguous.\\n\";\n@@ -259,17 +261,21 @@ static int get_sha1_basic(const char *st\n \tif (ambiguous_path(str, len))\n \t\treturn -1;\n \n-\tfor (p = fmt; *p; p++) {\n-\t\tthis_result = already_found ? sha1_from_ref : sha1;\n-\t\tpathname = git_path(*p, len, str);\n-\t\tif (!read_ref(pathname, this_result)) {\n-\t\t\tif (warn_ambiguous_refs) {\n-\t\t\t\tif (already_found)\n-\t\t\t\t\tfprintf(stderr, warning, len, str);\n-\t\t\t\talready_found++;\n+\tfor (p = fmt; p < fmt + ARRAY_SIZE(fmt); p++) {\n+\t\tconst char **s;\n+\t\tfor (s = sfx; s < sfx + ARRAY_SIZE(sfx); s++) {\n+\t\t\tthis_result = already_found ? sha1_from_ref : sha1;\n+\t\t\tpathname = git_path(*p, len, str, *s);\n+\t\t\tif (!read_ref(pathname, this_result)) {\n+\t\t\t\tif (warn_ambiguous_refs) {\n+\t\t\t\t\tif (already_found)\n+\t\t\t\t\t\tfprintf(stderr, warning,\n+\t\t\t\t\t\t\tlen, str);\n+\t\t\t\t\talready_found++;\n+\t\t\t\t}\n+\t\t\t\telse\n+\t\t\t\t\treturn 0;\n \t\t\t}\n-\t\t\telse\n-\t\t\t\treturn 0;\n \t\t}\n \t}\n \tif (already_found)\n"}]}