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