The fourth batch
[git/debian.git] / builtin / upload-pack.c
blob125af53885f89fbd4b691f5d9463774b12a66559
1 #include "cache.h"
2 #include "builtin.h"
3 #include "exec-cmd.h"
4 #include "pkt-line.h"
5 #include "parse-options.h"
6 #include "protocol.h"
7 #include "upload-pack.h"
8 #include "serve.h"
10 static const char * const upload_pack_usage[] = {
11 N_("git upload-pack [<options>] <dir>"),
12 NULL
15 int cmd_upload_pack(int argc, const char **argv, const char *prefix)
17 const char *dir;
18 int strict = 0;
19 int advertise_refs = 0;
20 int stateless_rpc = 0;
21 int timeout = 0;
22 struct option options[] = {
23 OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
24 N_("quit after a single request/response exchange")),
25 OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs,
26 N_("serve up the info/refs for git-http-backend")),
27 OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
28 OPT_BOOL(0, "strict", &strict,
29 N_("do not try <directory>/.git/ if <directory> is no Git directory")),
30 OPT_INTEGER(0, "timeout", &timeout,
31 N_("interrupt transfer after <n> seconds of inactivity")),
32 OPT_END()
35 packet_trace_identity("upload-pack");
36 read_replace_refs = 0;
38 argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
40 if (argc != 1)
41 usage_with_options(upload_pack_usage, options);
43 setup_path();
45 dir = argv[0];
47 if (!enter_repo(dir, strict))
48 die("'%s' does not appear to be a git repository", dir);
50 switch (determine_protocol_version_server()) {
51 case protocol_v2:
52 if (advertise_refs)
53 protocol_v2_advertise_capabilities();
54 else
55 protocol_v2_serve_loop(stateless_rpc);
56 break;
57 case protocol_v1:
59 * v1 is just the original protocol with a version string,
60 * so just fall through after writing the version string.
62 if (advertise_refs || !stateless_rpc)
63 packet_write_fmt(1, "version 1\n");
65 /* fallthrough */
66 case protocol_v0:
67 upload_pack(advertise_refs, stateless_rpc, timeout);
68 break;
69 case protocol_unknown_version:
70 BUG("unknown protocol version");
73 return 0;