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