Merge branch 'jk/maint-upload-archive' into maint
authorJunio C Hamano <gitster@pobox.com>
Wed, 21 Dec 2011 19:42:44 +0000 (11:42 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 21 Dec 2011 19:42:44 +0000 (11:42 -0800)
* jk/maint-upload-archive:
archive: don't let remote clients get unreachable commits

1  2 
archive.c
diff --combined archive.c
index 2ae740a71e6d43ee81afdeddcb53f983f10a8fff,5f0a3fc6d2e5cbf6e098fc67e093707bf2915914..164bbd014a82feac48886db6f27ba85d61a059ac
+++ b/archive.c
@@@ -247,7 -247,8 +247,8 @@@ static void parse_pathspec_arg(const ch
  }
  
  static void parse_treeish_arg(const char **argv,
-               struct archiver_args *ar_args, const char *prefix)
+               struct archiver_args *ar_args, const char *prefix,
+               int remote)
  {
        const char *name = argv[0];
        const unsigned char *commit_sha1;
        const struct commit *commit;
        unsigned char sha1[20];
  
-       if (get_sha1(name, sha1))
-               die("Not a valid object name");
+       /* 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);
+               free(ref);
+       }
+       else {
+               if (get_sha1(name, sha1))
+                       die("Not a valid object name");
+       }
  
        commit = lookup_commit_reference_gently(sha1, 1);
        if (commit) {
@@@ -318,7 -328,7 +328,7 @@@ static int parse_archive_args(int argc
                        "prepend prefix to each pathname in the archive"),
                OPT_STRING('o', "output", &output, "file",
                        "write the archive to this file"),
 -              OPT_BOOLEAN(0, "worktree-attributes", &worktree_attributes,
 +              OPT_BOOL(0, "worktree-attributes", &worktree_attributes,
                        "read .gitattributes in working directory"),
                OPT__VERBOSE(&verbose, "report archived files on stderr"),
                OPT__COMPR('0', &compression_level, "store only", 0),
                OPT__COMPR_HIDDEN('8', &compression_level, 8),
                OPT__COMPR('9', &compression_level, "compress better", 9),
                OPT_GROUP(""),
 -              OPT_BOOLEAN('l', "list", &list,
 +              OPT_BOOL('l', "list", &list,
                        "list supported archive formats"),
                OPT_GROUP(""),
                OPT_STRING(0, "remote", &remote, "repo",
@@@ -414,7 -424,7 +424,7 @@@ int write_archive(int argc, const char 
                setup_git_directory();
        }
  
-       parse_treeish_arg(argv, &args, prefix);
+       parse_treeish_arg(argv, &args, prefix, remote);
        parse_pathspec_arg(argv + 1, &args);
  
        return ar->write_archive(ar, &args);