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