Git fork

serve: stop using `the_repository`

Stop using `the_repository` in the "serve" subsystem by passing in a
repository when advertising capabilities or serving requests.

Adjust callers accordingly by using `the_repository`. While there may be
some callers that have a repository available in their context, this
trivial conversion allows for easier verification and bubbles up the use
of `the_repository` by one level.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
395b584b bd0c0fb7

+30 -25
+4 -2
builtin/upload-pack.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "builtin.h" 2 4 #include "exec-cmd.h" 3 5 #include "gettext.h" ··· 63 65 switch (determine_protocol_version_server()) { 64 66 case protocol_v2: 65 67 if (advertise_refs) 66 - protocol_v2_advertise_capabilities(); 68 + protocol_v2_advertise_capabilities(the_repository); 67 69 else 68 - protocol_v2_serve_loop(stateless_rpc); 70 + protocol_v2_serve_loop(the_repository, stateless_rpc); 69 71 break; 70 72 case protocol_v1: 71 73 /*
+17 -19
serve.c
··· 1 - #define USE_THE_REPOSITORY_VARIABLE 2 - 3 1 #include "git-compat-util.h" 4 2 #include "repository.h" 5 3 #include "config.h" ··· 159 157 }, 160 158 }; 161 159 162 - void protocol_v2_advertise_capabilities(void) 160 + void protocol_v2_advertise_capabilities(struct repository *r) 163 161 { 164 162 struct strbuf capability = STRBUF_INIT; 165 163 struct strbuf value = STRBUF_INIT; ··· 170 168 for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) { 171 169 struct protocol_capability *c = &capabilities[i]; 172 170 173 - if (c->advertise(the_repository, &value)) { 171 + if (c->advertise(r, &value)) { 174 172 strbuf_addstr(&capability, c->name); 175 173 176 174 if (value.len) { ··· 214 212 return NULL; 215 213 } 216 214 217 - static int receive_client_capability(const char *key) 215 + static int receive_client_capability(struct repository *r, const char *key) 218 216 { 219 217 const char *value; 220 218 const struct protocol_capability *c = get_capability(key, &value); 221 219 222 - if (!c || c->command || !c->advertise(the_repository, NULL)) 220 + if (!c || c->command || !c->advertise(r, NULL)) 223 221 return 0; 224 222 225 223 if (c->receive) 226 - c->receive(the_repository, value); 224 + c->receive(r, value); 227 225 return 1; 228 226 } 229 227 230 - static int parse_command(const char *key, struct protocol_capability **command) 228 + static int parse_command(struct repository *r, const char *key, struct protocol_capability **command) 231 229 { 232 230 const char *out; 233 231 ··· 238 236 if (*command) 239 237 die("command '%s' requested after already requesting command '%s'", 240 238 out, (*command)->name); 241 - if (!cmd || !cmd->advertise(the_repository, NULL) || !cmd->command || value) 239 + if (!cmd || !cmd->advertise(r, NULL) || !cmd->command || value) 242 240 die("invalid command '%s'", out); 243 241 244 242 *command = cmd; ··· 253 251 PROCESS_REQUEST_DONE, 254 252 }; 255 253 256 - static int process_request(void) 254 + static int process_request(struct repository *r) 257 255 { 258 256 enum request_state state = PROCESS_REQUEST_KEYS; 259 257 struct packet_reader reader; ··· 278 276 case PACKET_READ_EOF: 279 277 BUG("Should have already died when seeing EOF"); 280 278 case PACKET_READ_NORMAL: 281 - if (parse_command(reader.line, &command) || 282 - receive_client_capability(reader.line)) 279 + if (parse_command(r, reader.line, &command) || 280 + receive_client_capability(r, reader.line)) 283 281 seen_capability_or_command = 1; 284 282 else 285 283 die("unknown capability '%s'", reader.line); ··· 319 317 if (!command) 320 318 die("no command requested"); 321 319 322 - if (client_hash_algo != hash_algo_by_ptr(the_repository->hash_algo)) 320 + if (client_hash_algo != hash_algo_by_ptr(r->hash_algo)) 323 321 die("mismatched object format: server %s; client %s", 324 - the_repository->hash_algo->name, 322 + r->hash_algo->name, 325 323 hash_algos[client_hash_algo].name); 326 324 327 - command->command(the_repository, &reader); 325 + command->command(r, &reader); 328 326 329 327 return 0; 330 328 } 331 329 332 - void protocol_v2_serve_loop(int stateless_rpc) 330 + void protocol_v2_serve_loop(struct repository *r, int stateless_rpc) 333 331 { 334 332 if (!stateless_rpc) 335 - protocol_v2_advertise_capabilities(); 333 + protocol_v2_advertise_capabilities(r); 336 334 337 335 /* 338 336 * If stateless-rpc was requested then exit after 339 337 * a single request/response exchange 340 338 */ 341 339 if (stateless_rpc) { 342 - process_request(); 340 + process_request(r); 343 341 } else { 344 342 for (;;) 345 - if (process_request()) 343 + if (process_request(r)) 346 344 break; 347 345 } 348 346 }
+4 -2
serve.h
··· 1 1 #ifndef SERVE_H 2 2 #define SERVE_H 3 3 4 - void protocol_v2_advertise_capabilities(void); 5 - void protocol_v2_serve_loop(int stateless_rpc); 4 + struct repository; 5 + 6 + void protocol_v2_advertise_capabilities(struct repository *r); 7 + void protocol_v2_serve_loop(struct repository *r, int stateless_rpc); 6 8 7 9 #endif /* SERVE_H */
+5 -2
t/helper/test-serve-v2.c
··· 1 + #define USE_THE_REPOSITORY_VARIABLE 2 + 1 3 #include "test-tool.h" 2 4 #include "gettext.h" 3 5 #include "parse-options.h" 6 + #include "repository.h" 4 7 #include "serve.h" 5 8 #include "setup.h" 6 9 ··· 28 31 PARSE_OPT_KEEP_UNKNOWN_OPT); 29 32 30 33 if (advertise_capabilities) 31 - protocol_v2_advertise_capabilities(); 34 + protocol_v2_advertise_capabilities(the_repository); 32 35 else 33 - protocol_v2_serve_loop(stateless_rpc); 36 + protocol_v2_serve_loop(the_repository, stateless_rpc); 34 37 35 38 return 0; 36 39 }