upload-pack: move use_sideband to upload_pack_data
As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'use_sideband' static variable into this struct. This variable is used by both v0 and v2 protocols. While at it, let's update the comment near the variable definition. 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
f8edd1ca3c02dc8fd1f302e80557fb7eff8b724d
1 file changed
+19
-15
upload-pack.c
+19
-15
@@ -55,10 +55,6 @@ static unsigned int allow_unadvertised_object_request;
55
static int shallow_nr;
56
static struct object_array extra_edge_obj;
57
static int keepalive = 5;
58
-/* 0 for no sideband,
59
- * otherwise maximum packet size (up to 65520 bytes).
60
- */
61
-static int use_sideband;
58
static const char *pack_objects_hook;
59
60
static int filter_capability_requested;
@@ -87,6 +83,9 @@ struct upload_pack_data {
83
84
unsigned int timeout; /* v0 only */
85
86
+ /* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
87
+ int use_sideband;
88
+
89
struct list_objects_filter_options filter_options;
90
91
struct packet_writer writer;
@@ -141,7 +140,8 @@ static void reset_timeout(unsigned int timeout)
140
alarm(timeout);
141
}
142
144
-static void send_client_data(int fd, const char *data, ssize_t sz)
143
+static void send_client_data(int fd, const char *data, ssize_t sz,
144
+ int use_sideband)
145
{
146
if (use_sideband) {
147
send_sideband(1, fd, data, sz, use_sideband);
@@ -290,7 +290,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
290
sz = xread(pack_objects.err, progress,
291
sizeof(progress));
292
if (0 < sz)
293
- send_client_data(2, progress, sz);
293
+ send_client_data(2, progress, sz,
294
+ pack_data->use_sideband);
295
else if (sz == 0) {
296
close(pack_objects.err);
297
pack_objects.err = -1;
@@ -333,7 +334,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
334
}
335
else
336
buffered = -1;
336
- send_client_data(1, data, sz);
337
+ send_client_data(1, data, sz,
338
+ pack_data->use_sideband);
339
}
340
341
/*
@@ -346,7 +348,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
348
* protocol to say anything, so those clients are just out of
349
* luck.
350
*/
349
- if (!ret && use_sideband) {
351
+ if (!ret && pack_data->use_sideband) {
352
static const char buf[] = "0005\1";
353
write_or_die(1, buf, 5);
354
}
@@ -360,15 +362,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
362
/* flush the data */
363
if (0 <= buffered) {
364
data[0] = buffered;
363
- send_client_data(1, data, 1);
365
+ send_client_data(1, data, 1,
366
+ pack_data->use_sideband);
367
fprintf(stderr, "flushed.\n");
368
}
366
- if (use_sideband)
369
+ if (pack_data->use_sideband)
370
packet_flush(1);
371
return;
372
373
fail:
371
- send_client_data(3, abort_msg, sizeof(abort_msg));
374
+ send_client_data(3, abort_msg, sizeof(abort_msg),
375
+ pack_data->use_sideband);
376
die("git upload-pack: %s", abort_msg);
377
}
378
@@ -964,9 +968,9 @@ static void receive_needs(struct upload_pack_data *data,
968
if (parse_feature_request(features, "ofs-delta"))
969
data->use_ofs_delta = 1;
970
if (parse_feature_request(features, "side-band-64k"))
967
- use_sideband = LARGE_PACKET_MAX;
971
+ data->use_sideband = LARGE_PACKET_MAX;
972
else if (parse_feature_request(features, "side-band"))
969
- use_sideband = DEFAULT_PACKET_MAX;
973
+ data->use_sideband = DEFAULT_PACKET_MAX;
974
if (parse_feature_request(features, "no-progress"))
975
data->no_progress = 1;
976
if (parse_feature_request(features, "include-tag"))
@@ -1001,7 +1005,7 @@ static void receive_needs(struct upload_pack_data *data,
1005
if (has_non_tip)
1006
check_non_tip(data);
1007
1004
- if (!use_sideband && data->daemon_mode)
1008
+ if (!data->use_sideband && data->daemon_mode)
1009
data->no_progress = 1;
1010
1011
if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1486,7 +1490,7 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
1490
git_config(upload_pack_config, NULL);
1491
1492
upload_pack_data_init(&data);
1489
- use_sideband = LARGE_PACKET_MAX;
1493
+ data.use_sideband = LARGE_PACKET_MAX;
1494
1495
while (state != FETCH_DONE) {
1496
switch (state) {