Skip to content

Commit f8edd1c

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d40f04e commit f8edd1c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

upload-pack.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ static unsigned int allow_unadvertised_object_request;
5555
static int shallow_nr;
5656
static struct object_array extra_edge_obj;
5757
static int keepalive = 5;
58-
/* 0 for no sideband,
59-
* otherwise maximum packet size (up to 65520 bytes).
60-
*/
61-
static int use_sideband;
6258
static const char *pack_objects_hook;
6359

6460
static int filter_capability_requested;
@@ -87,6 +83,9 @@ struct upload_pack_data {
8783

8884
unsigned int timeout; /* v0 only */
8985

86+
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
87+
int use_sideband;
88+
9089
struct list_objects_filter_options filter_options;
9190

9291
struct packet_writer writer;
@@ -141,7 +140,8 @@ static void reset_timeout(unsigned int timeout)
141140
alarm(timeout);
142141
}
143142

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)
145145
{
146146
if (use_sideband) {
147147
send_sideband(1, fd, data, sz, use_sideband);
@@ -290,7 +290,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
290290
sz = xread(pack_objects.err, progress,
291291
sizeof(progress));
292292
if (0 < sz)
293-
send_client_data(2, progress, sz);
293+
send_client_data(2, progress, sz,
294+
pack_data->use_sideband);
294295
else if (sz == 0) {
295296
close(pack_objects.err);
296297
pack_objects.err = -1;
@@ -333,7 +334,8 @@ static void create_pack_file(struct upload_pack_data *pack_data)
333334
}
334335
else
335336
buffered = -1;
336-
send_client_data(1, data, sz);
337+
send_client_data(1, data, sz,
338+
pack_data->use_sideband);
337339
}
338340

339341
/*
@@ -346,7 +348,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
346348
* protocol to say anything, so those clients are just out of
347349
* luck.
348350
*/
349-
if (!ret && use_sideband) {
351+
if (!ret && pack_data->use_sideband) {
350352
static const char buf[] = "0005\1";
351353
write_or_die(1, buf, 5);
352354
}
@@ -360,15 +362,17 @@ static void create_pack_file(struct upload_pack_data *pack_data)
360362
/* flush the data */
361363
if (0 <= buffered) {
362364
data[0] = buffered;
363-
send_client_data(1, data, 1);
365+
send_client_data(1, data, 1,
366+
pack_data->use_sideband);
364367
fprintf(stderr, "flushed.\n");
365368
}
366-
if (use_sideband)
369+
if (pack_data->use_sideband)
367370
packet_flush(1);
368371
return;
369372

370373
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);
372376
die("git upload-pack: %s", abort_msg);
373377
}
374378

@@ -964,9 +968,9 @@ static void receive_needs(struct upload_pack_data *data,
964968
if (parse_feature_request(features, "ofs-delta"))
965969
data->use_ofs_delta = 1;
966970
if (parse_feature_request(features, "side-band-64k"))
967-
use_sideband = LARGE_PACKET_MAX;
971+
data->use_sideband = LARGE_PACKET_MAX;
968972
else if (parse_feature_request(features, "side-band"))
969-
use_sideband = DEFAULT_PACKET_MAX;
973+
data->use_sideband = DEFAULT_PACKET_MAX;
970974
if (parse_feature_request(features, "no-progress"))
971975
data->no_progress = 1;
972976
if (parse_feature_request(features, "include-tag"))
@@ -1001,7 +1005,7 @@ static void receive_needs(struct upload_pack_data *data,
10011005
if (has_non_tip)
10021006
check_non_tip(data);
10031007

1004-
if (!use_sideband && data->daemon_mode)
1008+
if (!data->use_sideband && data->daemon_mode)
10051009
data->no_progress = 1;
10061010

10071011
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,
14861490
git_config(upload_pack_config, NULL);
14871491

14881492
upload_pack_data_init(&data);
1489-
use_sideband = LARGE_PACKET_MAX;
1493+
data.use_sideband = LARGE_PACKET_MAX;
14901494

14911495
while (state != FETCH_DONE) {
14921496
switch (state) {

0 commit comments

Comments
 (0)