2 * Copyright (c) 2006 Franck Bui-Huu
10 static const char upload_archive_usage[] =
11 "git-upload-archive <repo>";
14 int cmd_upload_archive(int argc, const char **argv, const char *prefix)
17 const char *sent_argv[MAX_ARGS];
18 const char *arg_cmd = "argument ";
25 usage(upload_archive_usage);
27 if (strlen(argv[1]) > sizeof(buf))
28 die("insanely long repository name");
30 strcpy(buf, argv[1]); /* enter-repo smudges its argument */
32 if (!enter_repo(buf, 0))
33 die("not a git archive");
35 /* put received options in sent_argv[] */
37 sent_argv[0] = "git-upload-archive";
39 /* This will die if not enough free space in buf */
40 len = packet_read_line(0, p, (buf + sizeof buf) - p);
42 break; /* got a flush */
43 if (sent_argc > MAX_ARGS - 2)
44 die("Too many options (>29)");
46 if (p[len-1] == '\n') {
49 if (len < strlen(arg_cmd) ||
50 strncmp(arg_cmd, p, strlen(arg_cmd)))
51 die("'argument' token or flush expected");
53 len -= strlen(arg_cmd);
54 memmove(p, p + strlen(arg_cmd), len);
55 sent_argv[sent_argc++] = p;
59 sent_argv[sent_argc] = NULL;
61 /* parse all options sent by the client */
62 treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar);
64 parse_treeish_arg(sent_argv + treeish_idx, &ar.args, prefix);
65 parse_pathspec_arg(sent_argv + treeish_idx + 1, &ar.args);
67 packet_write(1, "ACK\n");
70 return ar.write_archive(&ar.args);