shallow: fix leak when unregistering last shallow root
[alt-git.git] / builtin / upload-pack.c
blob3b6c83fbce3684f627e2e86818671e9c0dab30e1
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"
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
20 int cmd_upload_pack(int argc,
21 const char **argv,
22 const char *prefix,
23 struct repository *repo UNUSED)
25 const char *dir;
26 int strict = 0;
27 int advertise_refs = 0;
28 int stateless_rpc = 0;
29 int timeout = 0;
30 struct option options[] = {
31 OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
32 N_("quit after a single request/response exchange")),
33 OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs,
34 N_("serve up the info/refs for git-http-backend")),
35 OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
36 OPT_BOOL(0, "strict", &strict,
37 N_("do not try <directory>/.git/ if <directory> is no Git directory")),
38 OPT_INTEGER(0, "timeout", &timeout,
39 N_("interrupt transfer after <n> seconds of inactivity")),
40 OPT_END()
43 packet_trace_identity("upload-pack");
44 disable_replace_refs();
45 save_commit_buffer = 0;
46 xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 0);
48 argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0);
50 if (argc != 1)
51 usage_with_options(upload_pack_usage, options);
53 setup_path();
55 dir = argv[0];
57 if (!enter_repo(dir, strict))
58 die("'%s' does not appear to be a git repository", dir);
60 switch (determine_protocol_version_server()) {
61 case protocol_v2:
62 if (advertise_refs)
63 protocol_v2_advertise_capabilities();
64 else
65 protocol_v2_serve_loop(stateless_rpc);
66 break;
67 case protocol_v1:
69 * v1 is just the original protocol with a version string,
70 * so just fall through after writing the version string.
72 if (advertise_refs || !stateless_rpc)
73 packet_write_fmt(1, "version 1\n");
75 /* fallthrough */
76 case protocol_v0:
77 upload_pack(advertise_refs, stateless_rpc, timeout);
78 break;
79 case protocol_unknown_version:
80 BUG("unknown protocol version");
83 return 0;