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>
Christian Couder committed
Jun 4, 2020 at 19:54 UTC
d40f04e0b0f8fe60328fb28c366d53ef4501fbce
1 file changed
+14
-14
upload-pack.c
+14
-14
@@ -45,8 +45,6 @@
45
static timestamp_t oldest_have;
46
47
static int multi_ack;
48
-static int no_done;
49
-static int daemon_mode;
48
/* Allow specifying sha1 if it is a ref tip. */
49
#define ALLOW_TIP_SHA1 01
50
/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -56,7 +54,6 @@ static int daemon_mode;
54
static unsigned int allow_unadvertised_object_request;
55
static int shallow_nr;
56
static struct object_array extra_edge_obj;
59
-static unsigned int timeout;
57
static int keepalive = 5;
58
/* 0 for no sideband,
59
* otherwise maximum packet size (up to 65520 bytes).
@@ -88,11 +85,15 @@ struct upload_pack_data {
85
int deepen_rev_list;
86
int deepen_relative;
87
88
+ unsigned int timeout; /* v0 only */
89
+
90
struct list_objects_filter_options filter_options;
91
92
struct packet_writer writer;
93
94
unsigned stateless_rpc : 1; /* v0 only */
95
+ unsigned no_done : 1; /* v0 only */
96
+ unsigned daemon_mode : 1; /* v0 only */
97
98
unsigned use_thin_pack : 1;
99
unsigned use_ofs_delta : 1;
@@ -135,7 +136,7 @@ static void upload_pack_data_clear(struct upload_pack_data *data)
136
list_objects_filter_release(&data->filter_options);
137
}
138
138
-static void reset_timeout(void)
139
+static void reset_timeout(unsigned int timeout)
140
{
141
alarm(timeout);
142
}
@@ -251,7 +252,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
252
int pe, pu, pollsize;
253
int ret;
254
254
- reset_timeout();
255
+ reset_timeout(pack_data->timeout);
256
257
pollsize = 0;
258
pe = pu = -1;
@@ -433,7 +434,7 @@ static int get_common_commits(struct upload_pack_data *data,
434
for (;;) {
435
const char *arg;
436
436
- reset_timeout();
437
+ reset_timeout(data->timeout);
438
439
if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
440
if (multi_ack == 2
@@ -446,7 +447,7 @@ static int get_common_commits(struct upload_pack_data *data,
447
if (data->have_obj.nr == 0 || multi_ack)
448
packet_write_fmt(1, "NAK\n");
449
449
- if (no_done && sent_ready) {
450
+ if (data->no_done && sent_ready) {
451
packet_write_fmt(1, "ACK %s\n", last_hex);
452
return 0;
453
}
@@ -924,7 +925,7 @@ static void receive_needs(struct upload_pack_data *data,
925
struct object_id oid_buf;
926
const char *arg;
927
927
- reset_timeout();
928
+ reset_timeout(data->timeout);
929
if (packet_reader_read(reader) != PACKET_READ_NORMAL)
930
break;
931
@@ -957,7 +958,7 @@ static void receive_needs(struct upload_pack_data *data,
958
else if (parse_feature_request(features, "multi_ack"))
959
multi_ack = 1;
960
if (parse_feature_request(features, "no-done"))
960
- no_done = 1;
961
+ data->no_done = 1;
962
if (parse_feature_request(features, "thin-pack"))
963
data->use_thin_pack = 1;
964
if (parse_feature_request(features, "ofs-delta"))
@@ -1000,7 +1001,7 @@ static void receive_needs(struct upload_pack_data *data,
1001
if (has_non_tip)
1002
check_non_tip(data);
1003
1003
- if (!use_sideband && daemon_mode)
1004
+ if (!use_sideband && data->daemon_mode)
1005
data->no_progress = 1;
1006
1007
if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1149,19 +1150,18 @@ void upload_pack(struct upload_pack_options *options)
1150
struct packet_reader reader;
1151
struct upload_pack_data data;
1152
1152
- timeout = options->timeout;
1153
- daemon_mode = options->daemon_mode;
1154
-
1153
git_config(upload_pack_config, NULL);
1154
1155
upload_pack_data_init(&data);
1156
1157
data.stateless_rpc = options->stateless_rpc;
1158
+ data.daemon_mode = options->daemon_mode;
1159
+ data.timeout = options->timeout;
1160
1161
head_ref_namespaced(find_symref, &data.symref);
1162
1163
if (options->advertise_refs || !data.stateless_rpc) {
1164
- reset_timeout();
1164
+ reset_timeout(data.timeout);
1165
head_ref_namespaced(send_ref, &data);
1166
for_each_namespaced_ref(send_ref, &data);
1167
advertise_shallow_grafts(1);