Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/builtin/upload-pack.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / builtin / upload-pack.c` 106 lines ยท 3094 bytes Raw Blame History 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 "protocol.h" 9 #include "replace-object.h" 10 #include "upload-pack.h" 11 #include "serve.h" 12 #include "setup.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=] [--stateless-rpc]\n" 18 " [--advertise-refs] "), 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 /.git/ if is no Git directory")), 40 OPT_INTEGER(0, "timeout", &timeout, 41 N_("interrupt transfer after 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 50 argc = parse_options(argc, argv, prefix, options, upload_pack_usage, 0); 51 52 if (argc != 1) 53 usage_with_options(upload_pack_usage, options); 54 55 setup_path(); 56 57 dir = argv[0]; 58 59 if (strict) 60 enter_repo_flags |= ENTER_REPO_STRICT; 61 if (!enter_repo(the_repository, dir, enter_repo_flags)) 62 die("'%s' does not appear to be a git repository", dir); 63 64 /* 65 * Lazily fetching while serving a client would run `git fetch`, 66 * which may execute arbitrary commands from the configuration 67 * and hooks of the served repo, so we disable it by default as 68 * we trust nobody. There are two ways for a server operator to 69 * allow it though: 70 * 71 * - if GIT_NO_LAZY_FETCH is already set, we leave it alone and 72 * honor whatever the operator put there, 73 * 74 * - otherwise, if the served repo is in the 75 * "uploadpack.lazyFetchTrusted" protected allowlist, we 76 * don't disable lazy fetching. 77 */ 78 if (!getenv(NO_LAZY_FETCH_ENVIRONMENT) && 79 !upload_pack_lazy_fetch_trusted(the_repository)) 80 xsetenv(NO_LAZY_FETCH_ENVIRONMENT, "1", 1); 81 82 switch (determine_protocol_version_server()) { 83 case protocol_v2: 84 if (advertise_refs) 85 protocol_v2_advertise_capabilities(the_repository); 86 else 87 protocol_v2_serve_loop(the_repository, stateless_rpc); 88 break; 89 case protocol_v1: 90 /* 91 * v1 is just the original protocol with a version string, 92 * so just fall through after writing the version string. 93 */ 94 if (advertise_refs || !stateless_rpc) 95 packet_write_fmt(1, "version 1\n"); 96 97 /* fallthrough */ 98 case protocol_v0: 99 upload_pack(advertise_refs, stateless_rpc, timeout); 100 break; 101 case protocol_unknown_version: 102 BUG("unknown protocol version"); 103 } 104 105 return 0; 106 }