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) - : send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html