upload-pack: move static vars to upload_pack_data

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
more thoroughly, let's move the 'no_done', 'daemon_mode' and
'timeout' variables into this struct.

They are only used by protocol v0 code since protocol v2 assumes
certain baseline capabilities, but rolling them into
upload_pack_data and just letting v2 code ignore them as it does
now is more coherent and cleaner.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Christian Couder 2020-06-04 19:54:40 +02:00 committed by Junio C Hamano
parent a849728821
commit d40f04e0b0

View File

@ -45,8 +45,6 @@
static timestamp_t oldest_have; static timestamp_t oldest_have;
static int multi_ack; static int multi_ack;
static int no_done;
static int daemon_mode;
/* Allow specifying sha1 if it is a ref tip. */ /* Allow specifying sha1 if it is a ref tip. */
#define ALLOW_TIP_SHA1 01 #define ALLOW_TIP_SHA1 01
/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */ /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@ -56,7 +54,6 @@ static int daemon_mode;
static unsigned int allow_unadvertised_object_request; static unsigned int allow_unadvertised_object_request;
static int shallow_nr; static int shallow_nr;
static struct object_array extra_edge_obj; static struct object_array extra_edge_obj;
static unsigned int timeout;
static int keepalive = 5; static int keepalive = 5;
/* 0 for no sideband, /* 0 for no sideband,
* otherwise maximum packet size (up to 65520 bytes). * otherwise maximum packet size (up to 65520 bytes).
@ -88,11 +85,15 @@ struct upload_pack_data {
int deepen_rev_list; int deepen_rev_list;
int deepen_relative; int deepen_relative;
unsigned int timeout; /* v0 only */
struct list_objects_filter_options filter_options; struct list_objects_filter_options filter_options;
struct packet_writer writer; struct packet_writer writer;
unsigned stateless_rpc : 1; /* v0 only */ unsigned stateless_rpc : 1; /* v0 only */
unsigned no_done : 1; /* v0 only */
unsigned daemon_mode : 1; /* v0 only */
unsigned use_thin_pack : 1; unsigned use_thin_pack : 1;
unsigned use_ofs_delta : 1; unsigned use_ofs_delta : 1;
@ -135,7 +136,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
list_objects_filter_release(&data->filter_options); list_objects_filter_release(&data->filter_options);
} }
static void reset_timeout(void) static void reset_timeout(unsigned int timeout)
{ {
alarm(timeout); alarm(timeout);
} }
@ -251,7 +252,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
int pe, pu, pollsize; int pe, pu, pollsize;
int ret; int ret;
reset_timeout(); reset_timeout(pack_data->timeout);
pollsize = 0; pollsize = 0;
pe = pu = -1; pe = pu = -1;
@ -433,7 +434,7 @@ static int get_common_commits(struct upload_pack_data *data,
for (;;) { for (;;) {
const char *arg; const char *arg;
reset_timeout(); reset_timeout(data->timeout);
if (packet_reader_read(reader) != PACKET_READ_NORMAL) { if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
if (multi_ack == 2 if (multi_ack == 2
@ -446,7 +447,7 @@ static int get_common_commits(struct upload_pack_data *data,
if (data->have_obj.nr == 0 || multi_ack) if (data->have_obj.nr == 0 || multi_ack)
packet_write_fmt(1, "NAK\n"); packet_write_fmt(1, "NAK\n");
if (no_done && sent_ready) { if (data->no_done && sent_ready) {
packet_write_fmt(1, "ACK %s\n", last_hex); packet_write_fmt(1, "ACK %s\n", last_hex);
return 0; return 0;
} }
@ -924,7 +925,7 @@ static void receive_needs(struct upload_pack_data *data,
struct object_id oid_buf; struct object_id oid_buf;
const char *arg; const char *arg;
reset_timeout(); reset_timeout(data->timeout);
if (packet_reader_read(reader) != PACKET_READ_NORMAL) if (packet_reader_read(reader) != PACKET_READ_NORMAL)
break; break;
@ -957,7 +958,7 @@ static void receive_needs(struct upload_pack_data *data,
else if (parse_feature_request(features, "multi_ack")) else if (parse_feature_request(features, "multi_ack"))
multi_ack = 1; multi_ack = 1;
if (parse_feature_request(features, "no-done")) if (parse_feature_request(features, "no-done"))
no_done = 1; data->no_done = 1;
if (parse_feature_request(features, "thin-pack")) if (parse_feature_request(features, "thin-pack"))
data->use_thin_pack = 1; data->use_thin_pack = 1;
if (parse_feature_request(features, "ofs-delta")) if (parse_feature_request(features, "ofs-delta"))
@ -1000,7 +1001,7 @@ static void receive_needs(struct upload_pack_data *data,
if (has_non_tip) if (has_non_tip)
check_non_tip(data); check_non_tip(data);
if (!use_sideband && daemon_mode) if (!use_sideband && data->daemon_mode)
data->no_progress = 1; data->no_progress = 1;
if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0) if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@ -1149,19 +1150,18 @@ void upload_pack(struct upload_pack_options *options)
struct packet_reader reader; struct packet_reader reader;
struct upload_pack_data data; struct upload_pack_data data;
timeout = options->timeout;
daemon_mode = options->daemon_mode;
git_config(upload_pack_config, NULL); git_config(upload_pack_config, NULL);
upload_pack_data_init(&data); upload_pack_data_init(&data);
data.stateless_rpc = options->stateless_rpc; data.stateless_rpc = options->stateless_rpc;
data.daemon_mode = options->daemon_mode;
data.timeout = options->timeout;
head_ref_namespaced(find_symref, &data.symref); head_ref_namespaced(find_symref, &data.symref);
if (options->advertise_refs || !data.stateless_rpc) { if (options->advertise_refs || !data.stateless_rpc) {
reset_timeout(); reset_timeout(data.timeout);
head_ref_namespaced(send_ref, &data); head_ref_namespaced(send_ref, &data);
for_each_namespaced_ref(send_ref, &data); for_each_namespaced_ref(send_ref, &data);
advertise_shallow_grafts(1); advertise_shallow_grafts(1);