diff mbox series

[08/12] upload-pack: move keepalive to upload_pack_data

Message ID 20200527164742.23067-9-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 'keepalive' static variable
into this struct.

It is used by code common to protocol v0 and protocol v2.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 upload-pack.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

Comments

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

> As we cleanup 'upload-pack.c' by using 'struct upload_pack_data'
> more thoroughly, let's move the 'keepalive' static variable
> into this struct.
> 
> It is used by code common to protocol v0 and protocol v2.

Sounds good.

> @@ -248,7 +250,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
>  
>  	while (1) {
>  		struct pollfd pfd[2];
> -		int pe, pu, pollsize;
> +		int pe, pu, pollsize, polltimeout;
>  		int ret;
>  
>  		reset_timeout(pack_data->timeout);
> @@ -272,8 +274,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
>  		if (!pollsize)
>  			break;
>  
> -		ret = poll(pfd, pollsize,
> -			keepalive < 0 ? -1 : 1000 * keepalive);
> +		polltimeout = pack_data->keepalive < 0
> +			? -1
> +			: 1000 * pack_data->keepalive;
> +
> +		ret = poll(pfd, pollsize, polltimeout);

The new variable isn't strictly necessary, but it keeps the line-length
down now that the variable name is much longer. Looks reasonable.

-Peff
diff mbox series

Patch

diff --git a/upload-pack.c b/upload-pack.c
index 101e28f478..e00631a703 100644
--- a/upload-pack.c
+++ b/upload-pack.c
@@ -53,7 +53,6 @@  static timestamp_t oldest_have;
 static unsigned int allow_unadvertised_object_request;
 static int shallow_nr;
 static struct object_array extra_edge_obj;
-static int keepalive = 5;
 static const char *pack_objects_hook;
 
 static int allow_filter;
@@ -75,6 +74,7 @@  struct upload_pack_data {
 	int deepen_rev_list;
 	int deepen_relative;
 	int timeout;
+	int keepalive;
 
 	enum  {
 		no_multi_ack = 0,
@@ -120,6 +120,8 @@  static void upload_pack_data_init(struct upload_pack_data *data)
 	data->shallows = shallows;
 	data->deepen_not = deepen_not;
 	packet_writer_init(&data->writer, 1);
+
+	data->keepalive = 5;
 }
 
 static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -248,7 +250,7 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 
 	while (1) {
 		struct pollfd pfd[2];
-		int pe, pu, pollsize;
+		int pe, pu, pollsize, polltimeout;
 		int ret;
 
 		reset_timeout(pack_data->timeout);
@@ -272,8 +274,11 @@  static void create_pack_file(struct upload_pack_data *pack_data)
 		if (!pollsize)
 			break;
 
-		ret = poll(pfd, pollsize,
-			keepalive < 0 ? -1 : 1000 * keepalive);
+		polltimeout = pack_data->keepalive < 0
+			? -1
+			: 1000 * pack_data->keepalive;
+
+		ret = poll(pfd, pollsize, polltimeout);
 
 		if (ret < 0) {
 			if (errno != EINTR) {
@@ -1110,6 +1115,8 @@  static int find_symref(const char *refname, const struct object_id *oid,
 
 static int upload_pack_config(const char *var, const char *value, void *cb_data)
 {
+	struct upload_pack_data *data = cb_data;
+
 	if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
 		if (git_config_bool(var, value))
 			allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
@@ -1126,9 +1133,9 @@  static int upload_pack_config(const char *var, const char *value, void *cb_data)
 		else
 			allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
 	} else if (!strcmp("uploadpack.keepalive", var)) {
-		keepalive = git_config_int(var, value);
-		if (!keepalive)
-			keepalive = -1;
+		data->keepalive = git_config_int(var, value);
+		if (!data->keepalive)
+			data->keepalive = -1;
 	} else if (!strcmp("uploadpack.allowfilter", var)) {
 		allow_filter = git_config_bool(var, value);
 	} else if (!strcmp("uploadpack.allowrefinwant", var)) {