1 #define USE_THE_REPOSITORY_VARIABLE
7 #include "parse-options.h"
10 #include "replace-object.h"
11 #include "upload-pack.h"
14 #include "environment.h"
16 static const char * const upload_pack_usage
[] = {
17 N_("git-upload-pack [--[no-]strict] [--timeout=<n>] [--stateless-rpc]\n"
18 " [--advertise-refs] <directory>"),
22 int cmd_upload_pack(int argc
,
25 struct repository
*repo UNUSED
)
29 int advertise_refs
= 0;
30 int stateless_rpc
= 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")),
44 unsigned enter_repo_flags
= ENTER_REPO_ANY_OWNER_OK
;
46 packet_trace_identity("upload-pack");
47 disable_replace_refs();
48 save_commit_buffer
= 0;
49 xsetenv(NO_LAZY_FETCH_ENVIRONMENT
, "1", 0);
51 argc
= parse_options(argc
, argv
, prefix
, options
, upload_pack_usage
, 0);
54 usage_with_options(upload_pack_usage
, options
);
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
);
65 switch (determine_protocol_version_server()) {
68 protocol_v2_advertise_capabilities(the_repository
);
70 protocol_v2_serve_loop(the_repository
, stateless_rpc
);
74 * v1 is just the original protocol with a version string,
75 * so just fall through after writing the version string.
77 if (advertise_refs
|| !stateless_rpc
)
78 packet_write_fmt(1, "version 1\n");
82 upload_pack(advertise_refs
, stateless_rpc
, timeout
);
84 case protocol_unknown_version
:
85 BUG("unknown protocol version");