5 static const char upload_pack_usage
[] = "git-upload-pack <dir>";
7 static int got_sha1(char *hex
, unsigned char *sha1
)
9 if (get_sha1_hex(hex
, sha1
))
10 die("git-upload-pack: expected SHA1 object, got '%s'", hex
);
11 return has_sha1_file(sha1
);
14 static int get_common_commits(void)
16 static char line
[1000];
17 unsigned char sha1
[20];
21 len
= packet_read_line(0, line
, sizeof(line
));
24 packet_write(1, "NAK\n");
27 if (line
[len
-1] == '\n')
29 if (!strncmp(line
, "have ", 5)) {
30 if (got_sha1(line
+5, sha1
)) {
31 packet_write(1, "ACK %s\n", sha1_to_hex(sha1
));
36 if (!strcmp(line
, "done")) {
37 packet_write(1, "NAK\n");
40 die("git-upload-pack: expected SHA1 list, got '%s'", line
);
44 len
= packet_read_line(0, line
, sizeof(line
));
47 if (!strncmp(line
, "have ", 5)) {
48 got_sha1(line
+5, sha1
);
51 if (!strcmp(line
, "done"))
53 die("git-upload-pack: expected SHA1 list, got '%s'", line
);
58 static int send_ref(const char *refname
, const unsigned char *sha1
)
60 packet_write(1, "%s %s\n", sha1_to_hex(sha1
), refname
);
64 static int upload_pack(void)
66 for_each_ref(send_ref
);
72 int main(int argc
, char **argv
)
76 usage(upload_pack_usage
);
79 die("git-upload-pack unable to chdir to %s", dir
);
81 if (access("objects", X_OK
) || access("refs", X_OK
))
82 die("git-upload-pack: %s doesn't seem to be a git archive", dir
);
83 setenv("GIT_DIR", ".", 1);