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