diff mbox series

[03/12] upload-pack: move use_sideband to upload_pack_data

Message ID 20200527164742.23067-4-chriscool@tuxfamily.org (mailing list archive)
State New, archived
Headers show
Series upload-pack: use 'struct upload_pack_data' thoroughly, part 2 | expand

Commit Message

Christian Couder May 27, 2020, 4:47 p.m. UTC
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>
---
 upload-pack.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

Comments

Jeff King May 27, 2020, 6:07 p.m. UTC | #1
On Wed, May 27, 2020 at 06:47:33PM +0200, Christian Couder wrote:

> 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.

Yep, looks good. I was surprised for a moment by "used by v2", which
always does sideband. But of course we still _use_ the variable, we just
set it unconditionally in the v2 code-path.

-Peff
diff mbox series

Patch

diff --git a/upload-pack.c b/upload-pack.c
index c83c5a619b..a5a9750890 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -55,10 +55,6 @@  static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
 static int keepalive = 5;
-/* 0 for no sideband,
- * otherwise maximum packet size (up to 65520 bytes).
- */
-static int use_sideband;
 static const char *pack_objects_hook;
 
 static int filter_capability_requested;
@@ -82,6 +78,9 @@  struct upload_pack_data {
 	int deepen_relative;
 	int timeout;
 
+	/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
+	int use_sideband;
+
 	struct list_objects_filter_options filter_options;
 
 	struct packet_writer writer;
@@ -135,7 +134,8 @@  static void reset_timeout(int timeout)
 	alarm(timeout);
 }
 
-static void send_client_data(int fd, const char *data, ssize_t sz)
+static void send_client_data(int fd, const char *data, ssize_t sz,
+			     int use_sideband)
 {
 	if (use_sideband) {
 		send_sideband(1, fd, data, sz, use_sideband);
@@ -284,7 +284,8 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 			sz = xread(pack_objects.err, progress,
 				  sizeof(progress));
 			if (0 < sz)
-				send_client_data(2, progress, sz);
+				send_client_data(2, progress, sz,
+						 pack_data->use_sideband);
 			else if (sz == 0) {
 				close(pack_objects.err);
 				pack_objects.err = -1;
@@ -327,7 +328,8 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 			}
 			else
 				buffered = -1;
-			send_client_data(1, data, sz);
+			send_client_data(1, data, sz,
+					 pack_data->use_sideband);
 		}
 
 		/*
@@ -340,7 +342,7 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 		 * protocol to say anything, so those clients are just out of
 		 * luck.
 		 */
-		if (!ret && use_sideband) {
+		if (!ret && pack_data->use_sideband) {
 			static const char buf[] = "0005\1";
 			write_or_die(1, buf, 5);
 		}
@@ -354,15 +356,17 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 	/* flush the data */
 	if (0 <= buffered) {
 		data[0] = buffered;
-		send_client_data(1, data, 1);
+		send_client_data(1, data, 1,
+				 pack_data->use_sideband);
 		fprintf(stderr, "flushed.\n");
 	}
-	if (use_sideband)
+	if (pack_data->use_sideband)
 		packet_flush(1);
 	return;
 
  fail:
-	send_client_data(3, abort_msg, sizeof(abort_msg));
+	send_client_data(3, abort_msg, sizeof(abort_msg),
+			 pack_data->use_sideband);
 	die("git upload-pack: %s", abort_msg);
 }
 
@@ -958,9 +962,9 @@  static void receive_needs(struct upload_pack_data *data,
 		if (parse_feature_request(features, "ofs-delta"))
 			data->use_ofs_delta = 1;
 		if (parse_feature_request(features, "side-band-64k"))
-			use_sideband = LARGE_PACKET_MAX;
+			data->use_sideband = LARGE_PACKET_MAX;
 		else if (parse_feature_request(features, "side-band"))
-			use_sideband = DEFAULT_PACKET_MAX;
+			data->use_sideband = DEFAULT_PACKET_MAX;
 		if (parse_feature_request(features, "no-progress"))
 			data->no_progress = 1;
 		if (parse_feature_request(features, "include-tag"))
@@ -995,7 +999,7 @@  static void receive_needs(struct upload_pack_data *data,
 	if (has_non_tip)
 		check_non_tip(data);
 
-	if (!use_sideband && data->daemon_mode)
+	if (!data->use_sideband && data->daemon_mode)
 		data->no_progress = 1;
 
 	if (data->depth == 0 && !data->deepen_rev_list && data->shallows.nr == 0)
@@ -1480,7 +1484,7 @@  int upload_pack_v2(struct repository *r, struct argv_array *keys,
 	git_config(upload_pack_config, NULL);
 
 	upload_pack_data_init(&data);
-	use_sideband = LARGE_PACKET_MAX;
+	data.use_sideband = LARGE_PACKET_MAX;
 
 	while (state != FETCH_DONE) {
 		switch (state) {