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