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