2 * Copyright (c) 2006 Junio C Hamano
9 static const char upload_tar_usage[] = "git-upload-tar <repo>";
11 static int nak(const char *reason)
13 packet_write(1, "NACK %s\n", reason);
18 int cmd_upload_tar(int argc, const char **argv, char **envp)
21 const char *dir = argv[1];
23 unsigned char sha1[20];
30 usage(upload_tar_usage);
31 if (strlen(dir) < sizeof(buf)-1)
32 strcpy(buf, dir); /* enter-repo smudges its argument */
34 packet_write(1, "NACK insanely long repository name %s\n", dir);
35 if (!enter_repo(buf, 0)) {
36 packet_write(1, "NACK not a git archive %s\n", dir);
41 len = packet_read_line(0, buf, sizeof(buf));
42 if (len < 5 || strncmp("want ", buf, 5))
43 return nak("expected want");
44 if (buf[len-1] == '\n')
46 if (get_sha1(buf + 5, sha1))
47 return nak("expected sha1");
48 strcpy(hex, sha1_to_hex(sha1));
50 len = packet_read_line(0, buf, sizeof(buf));
52 if (len < 5 || strncmp("base ", buf, 5))
53 return nak("expected (optional) base");
54 if (buf[len-1] == '\n')
56 base = strdup(buf + 5);
57 len = packet_read_line(0, buf, sizeof(buf));
60 return nak("expected flush");
62 packet_write(1, "ACK\n");
66 av[ac++] = "tar-tree";
72 /* should it return that is an error */