1#include"cache.h" 2#include"builtin.h" 3#include"exec_cmd.h" 4#include"pkt-line.h" 5#include"parse-options.h" 6#include"protocol.h" 7#include"upload-pack.h" 8 9static const char*const upload_pack_usage[] = { 10N_("git upload-pack [<options>] <dir>"), 11 NULL 12}; 13 14intcmd_upload_pack(int argc,const char**argv,const char*prefix) 15{ 16const char*dir; 17int strict =0; 18struct upload_pack_options opts = {0}; 19struct option options[] = { 20OPT_BOOL(0,"stateless-rpc", &opts.stateless_rpc, 21N_("quit after a single request/response exchange")), 22OPT_BOOL(0,"advertise-refs", &opts.advertise_refs, 23N_("exit immediately after initial ref advertisement")), 24OPT_BOOL(0,"strict", &strict, 25N_("do not try <directory>/.git/ if <directory> is no Git directory")), 26OPT_INTEGER(0,"timeout", &opts.timeout, 27N_("interrupt transfer after <n> seconds of inactivity")), 28OPT_END() 29}; 30 31packet_trace_identity("upload-pack"); 32 check_replace_refs =0; 33 34 argc =parse_options(argc, argv, NULL, options, upload_pack_usage,0); 35 36if(argc !=1) 37usage_with_options(upload_pack_usage, options); 38 39if(opts.timeout) 40 opts.daemon_mode =1; 41 42setup_path(); 43 44 dir = argv[0]; 45 46if(!enter_repo(dir, strict)) 47die("'%s' does not appear to be a git repository", dir); 48 49switch(determine_protocol_version_server()) { 50case protocol_v2: 51/* 52 * fetch support for protocol v2 has not been implemented yet, 53 * so ignore the request to use v2 and fallback to using v0. 54 */ 55upload_pack(&opts); 56break; 57case protocol_v1: 58/* 59 * v1 is just the original protocol with a version string, 60 * so just fall through after writing the version string. 61 */ 62if(opts.advertise_refs || !opts.stateless_rpc) 63packet_write_fmt(1,"version 1\n"); 64 65/* fallthrough */ 66case protocol_v0: 67upload_pack(&opts); 68break; 69case protocol_unknown_version: 70BUG("unknown protocol version"); 71} 72 73return0; 74}