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