Code

archive: re-allow HEAD:Documentation on a remote invocation
authorCarlos Martín Nieto <cmn@elego.de>
Wed, 11 Jan 2012 12:12:38 +0000 (13:12 +0100)
committerJunio C Hamano <gitster@pobox.com>
Thu, 12 Jan 2012 03:21:22 +0000 (19:21 -0800)
The tightening done in (ee27ca4a: archive: don't let remote clients
get unreachable commits, 2011-11-17) went too far and disallowed
HEAD:Documentation as it would try to find "HEAD:Documentation" as a
ref.

Only DWIM the "HEAD" part to see if it exists as a ref. Once we're
sure that we've been given a valid ref, we follow the normal code
path. This still disallows attempts to access commits which are not
branch tips.

Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive.c

index 5f0a3fc6d2e5cbf6e098fc67e093707bf2915914..a348480b26500f616b9ad6f6bdef7b06d5ffdf7b 100644 (file)
--- a/archive.c
+++ b/archive.c
@@ -260,14 +260,23 @@ static void parse_treeish_arg(const char **argv,
        /* Remotes are only allowed to fetch actual refs */
        if (remote) {
                char *ref = NULL;
-               if (!dwim_ref(name, strlen(name), sha1, &ref))
-                       die("no such ref: %s", name);
+               const char *refname, *colon = NULL;
+
+               colon = strchr(name, ':');
+               if (colon)
+                       refname = xstrndup(name, colon - name);
+               else
+                       refname = name;
+
+               if (!dwim_ref(refname, strlen(refname), sha1, &ref))
+                       die("no such ref: %s", refname);
+               if (refname != name)
+                       free((void *)refname);
                free(ref);
        }
-       else {
-               if (get_sha1(name, sha1))
-                       die("Not a valid object name");
-       }
+
+       if (get_sha1(name, sha1))
+               die("Not a valid object name");
 
        commit = lookup_commit_reference_gently(sha1, 1);
        if (commit) {