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