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>maint
parent
bd0c0fb790
commit
395b584b57
|
@ -1,3 +1,5 @@
|
||||||
|
#define USE_THE_REPOSITORY_VARIABLE
|
||||||
|
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
#include "exec-cmd.h"
|
#include "exec-cmd.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
|
@ -63,9 +65,9 @@ int cmd_upload_pack(int argc,
|
||||||
switch (determine_protocol_version_server()) {
|
switch (determine_protocol_version_server()) {
|
||||||
case protocol_v2:
|
case protocol_v2:
|
||||||
if (advertise_refs)
|
if (advertise_refs)
|
||||||
protocol_v2_advertise_capabilities();
|
protocol_v2_advertise_capabilities(the_repository);
|
||||||
else
|
else
|
||||||
protocol_v2_serve_loop(stateless_rpc);
|
protocol_v2_serve_loop(the_repository, stateless_rpc);
|
||||||
break;
|
break;
|
||||||
case protocol_v1:
|
case protocol_v1:
|
||||||
/*
|
/*
|
||||||
|
|
36
serve.c
36
serve.c
|
@ -1,5 +1,3 @@
|
||||||
#define USE_THE_REPOSITORY_VARIABLE
|
|
||||||
|
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include "repository.h"
|
#include "repository.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -159,7 +157,7 @@ static struct protocol_capability capabilities[] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
void protocol_v2_advertise_capabilities(void)
|
void protocol_v2_advertise_capabilities(struct repository *r)
|
||||||
{
|
{
|
||||||
struct strbuf capability = STRBUF_INIT;
|
struct strbuf capability = STRBUF_INIT;
|
||||||
struct strbuf value = STRBUF_INIT;
|
struct strbuf value = STRBUF_INIT;
|
||||||
|
@ -170,7 +168,7 @@ void protocol_v2_advertise_capabilities(void)
|
||||||
for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) {
|
for (size_t i = 0; i < ARRAY_SIZE(capabilities); i++) {
|
||||||
struct protocol_capability *c = &capabilities[i];
|
struct protocol_capability *c = &capabilities[i];
|
||||||
|
|
||||||
if (c->advertise(the_repository, &value)) {
|
if (c->advertise(r, &value)) {
|
||||||
strbuf_addstr(&capability, c->name);
|
strbuf_addstr(&capability, c->name);
|
||||||
|
|
||||||
if (value.len) {
|
if (value.len) {
|
||||||
|
@ -214,20 +212,20 @@ static struct protocol_capability *get_capability(const char *key, const char **
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int receive_client_capability(const char *key)
|
static int receive_client_capability(struct repository *r, const char *key)
|
||||||
{
|
{
|
||||||
const char *value;
|
const char *value;
|
||||||
const struct protocol_capability *c = get_capability(key, &value);
|
const struct protocol_capability *c = get_capability(key, &value);
|
||||||
|
|
||||||
if (!c || c->command || !c->advertise(the_repository, NULL))
|
if (!c || c->command || !c->advertise(r, NULL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (c->receive)
|
if (c->receive)
|
||||||
c->receive(the_repository, value);
|
c->receive(r, value);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_command(const char *key, struct protocol_capability **command)
|
static int parse_command(struct repository *r, const char *key, struct protocol_capability **command)
|
||||||
{
|
{
|
||||||
const char *out;
|
const char *out;
|
||||||
|
|
||||||
|
@ -238,7 +236,7 @@ static int parse_command(const char *key, struct protocol_capability **command)
|
||||||
if (*command)
|
if (*command)
|
||||||
die("command '%s' requested after already requesting command '%s'",
|
die("command '%s' requested after already requesting command '%s'",
|
||||||
out, (*command)->name);
|
out, (*command)->name);
|
||||||
if (!cmd || !cmd->advertise(the_repository, NULL) || !cmd->command || value)
|
if (!cmd || !cmd->advertise(r, NULL) || !cmd->command || value)
|
||||||
die("invalid command '%s'", out);
|
die("invalid command '%s'", out);
|
||||||
|
|
||||||
*command = cmd;
|
*command = cmd;
|
||||||
|
@ -253,7 +251,7 @@ enum request_state {
|
||||||
PROCESS_REQUEST_DONE,
|
PROCESS_REQUEST_DONE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int process_request(void)
|
static int process_request(struct repository *r)
|
||||||
{
|
{
|
||||||
enum request_state state = PROCESS_REQUEST_KEYS;
|
enum request_state state = PROCESS_REQUEST_KEYS;
|
||||||
struct packet_reader reader;
|
struct packet_reader reader;
|
||||||
|
@ -278,8 +276,8 @@ static int process_request(void)
|
||||||
case PACKET_READ_EOF:
|
case PACKET_READ_EOF:
|
||||||
BUG("Should have already died when seeing EOF");
|
BUG("Should have already died when seeing EOF");
|
||||||
case PACKET_READ_NORMAL:
|
case PACKET_READ_NORMAL:
|
||||||
if (parse_command(reader.line, &command) ||
|
if (parse_command(r, reader.line, &command) ||
|
||||||
receive_client_capability(reader.line))
|
receive_client_capability(r, reader.line))
|
||||||
seen_capability_or_command = 1;
|
seen_capability_or_command = 1;
|
||||||
else
|
else
|
||||||
die("unknown capability '%s'", reader.line);
|
die("unknown capability '%s'", reader.line);
|
||||||
|
@ -319,30 +317,30 @@ static int process_request(void)
|
||||||
if (!command)
|
if (!command)
|
||||||
die("no command requested");
|
die("no command requested");
|
||||||
|
|
||||||
if (client_hash_algo != hash_algo_by_ptr(the_repository->hash_algo))
|
if (client_hash_algo != hash_algo_by_ptr(r->hash_algo))
|
||||||
die("mismatched object format: server %s; client %s",
|
die("mismatched object format: server %s; client %s",
|
||||||
the_repository->hash_algo->name,
|
r->hash_algo->name,
|
||||||
hash_algos[client_hash_algo].name);
|
hash_algos[client_hash_algo].name);
|
||||||
|
|
||||||
command->command(the_repository, &reader);
|
command->command(r, &reader);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void protocol_v2_serve_loop(int stateless_rpc)
|
void protocol_v2_serve_loop(struct repository *r, int stateless_rpc)
|
||||||
{
|
{
|
||||||
if (!stateless_rpc)
|
if (!stateless_rpc)
|
||||||
protocol_v2_advertise_capabilities();
|
protocol_v2_advertise_capabilities(r);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If stateless-rpc was requested then exit after
|
* If stateless-rpc was requested then exit after
|
||||||
* a single request/response exchange
|
* a single request/response exchange
|
||||||
*/
|
*/
|
||||||
if (stateless_rpc) {
|
if (stateless_rpc) {
|
||||||
process_request();
|
process_request(r);
|
||||||
} else {
|
} else {
|
||||||
for (;;)
|
for (;;)
|
||||||
if (process_request())
|
if (process_request(r))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
serve.h
6
serve.h
|
@ -1,7 +1,9 @@
|
||||||
#ifndef SERVE_H
|
#ifndef SERVE_H
|
||||||
#define SERVE_H
|
#define SERVE_H
|
||||||
|
|
||||||
void protocol_v2_advertise_capabilities(void);
|
struct repository;
|
||||||
void protocol_v2_serve_loop(int stateless_rpc);
|
|
||||||
|
void protocol_v2_advertise_capabilities(struct repository *r);
|
||||||
|
void protocol_v2_serve_loop(struct repository *r, int stateless_rpc);
|
||||||
|
|
||||||
#endif /* SERVE_H */
|
#endif /* SERVE_H */
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
#define USE_THE_REPOSITORY_VARIABLE
|
||||||
|
|
||||||
#include "test-tool.h"
|
#include "test-tool.h"
|
||||||
#include "gettext.h"
|
#include "gettext.h"
|
||||||
#include "parse-options.h"
|
#include "parse-options.h"
|
||||||
|
#include "repository.h"
|
||||||
#include "serve.h"
|
#include "serve.h"
|
||||||
#include "setup.h"
|
#include "setup.h"
|
||||||
|
|
||||||
|
@ -28,9 +31,9 @@ int cmd__serve_v2(int argc, const char **argv)
|
||||||
PARSE_OPT_KEEP_UNKNOWN_OPT);
|
PARSE_OPT_KEEP_UNKNOWN_OPT);
|
||||||
|
|
||||||
if (advertise_capabilities)
|
if (advertise_capabilities)
|
||||||
protocol_v2_advertise_capabilities();
|
protocol_v2_advertise_capabilities(the_repository);
|
||||||
else
|
else
|
||||||
protocol_v2_serve_loop(stateless_rpc);
|
protocol_v2_serve_loop(the_repository, stateless_rpc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue