]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/upload-pack.c
Sync with maint
[thirdparty/git.git] / builtin / upload-pack.c
CommitLineData
a3d6b53e
BW
1#include "cache.h"
2#include "builtin.h"
9bfa0f9b 3#include "exec-cmd.h"
a3d6b53e
BW
4#include "pkt-line.h"
5#include "parse-options.h"
6#include "protocol.h"
7#include "upload-pack.h"
e52449b6 8#include "serve.h"
a3d6b53e
BW
9
10static const char * const upload_pack_usage[] = {
11 N_("git upload-pack [<options>] <dir>"),
12 NULL
13};
14
15int cmd_upload_pack(int argc, const char **argv, const char *prefix)
16{
17 const char *dir;
18 int strict = 0;
19 struct upload_pack_options opts = { 0 };
e52449b6 20 struct serve_options serve_opts = SERVE_OPTIONS_INIT;
a3d6b53e
BW
21 struct option options[] = {
22 OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc,
23 N_("quit after a single request/response exchange")),
24 OPT_BOOL(0, "advertise-refs", &opts.advertise_refs,
25 N_("exit immediately after initial ref advertisement")),
26 OPT_BOOL(0, "strict", &strict,
27 N_("do not try <directory>/.git/ if <directory> is no Git directory")),
28 OPT_INTEGER(0, "timeout", &opts.timeout,
29 N_("interrupt transfer after <n> seconds of inactivity")),
30 OPT_END()
31 };
32
33 packet_trace_identity("upload-pack");
6ebd1caf 34 read_replace_refs = 0;
a3d6b53e 35
d64db5b3 36 argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
a3d6b53e
BW
37
38 if (argc != 1)
39 usage_with_options(upload_pack_usage, options);
40
41 if (opts.timeout)
42 opts.daemon_mode = 1;
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()) {
8f6982b4 52 case protocol_v2:
e52449b6
BW
53 serve_opts.advertise_capabilities = opts.advertise_refs;
54 serve_opts.stateless_rpc = opts.stateless_rpc;
55 serve(&serve_opts);
8f6982b4 56 break;
a3d6b53e
BW
57 case protocol_v1:
58 /*
59 * v1 is just the original protocol with a version string,
60 * so just fall through after writing the version string.
61 */
62 if (opts.advertise_refs || !opts.stateless_rpc)
63 packet_write_fmt(1, "version 1\n");
64
65 /* fallthrough */
66 case protocol_v0:
67 upload_pack(&opts);
68 break;
69 case protocol_unknown_version:
70 BUG("unknown protocol version");
71 }
72
73 return 0;
74}