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