Skip to content

Commit f203a88

Browse files
chriscoolgitster
authored andcommitted
upload-pack: move keepalive to upload_pack_data
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a0e6f1 commit f203a88

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

upload-pack.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ static timestamp_t oldest_have;
5353
static unsigned int allow_unadvertised_object_request;
5454
static int shallow_nr;
5555
static struct object_array extra_edge_obj;
56-
static int keepalive = 5;
5756
static const char *pack_objects_hook;
5857

5958
static int allow_filter;
@@ -78,6 +77,7 @@ struct upload_pack_data {
7877
timestamp_t deepen_since;
7978
int deepen_rev_list;
8079
int deepen_relative;
80+
int keepalive;
8181

8282
unsigned int timeout; /* v0 only */
8383
enum {
@@ -125,6 +125,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
125125
data->shallows = shallows;
126126
data->deepen_not = deepen_not;
127127
packet_writer_init(&data->writer, 1);
128+
129+
data->keepalive = 5;
128130
}
129131

130132
static void upload_pack_data_clear(struct upload_pack_data *data)
@@ -253,7 +255,7 @@ static void create_pack_file(struct upload_pack_data *pack_data)
253255

254256
while (1) {
255257
struct pollfd pfd[2];
256-
int pe, pu, pollsize;
258+
int pe, pu, pollsize, polltimeout;
257259
int ret;
258260

259261
reset_timeout(pack_data->timeout);
@@ -277,8 +279,11 @@ static void create_pack_file(struct upload_pack_data *pack_data)
277279
if (!pollsize)
278280
break;
279281

280-
ret = poll(pfd, pollsize,
281-
keepalive < 0 ? -1 : 1000 * keepalive);
282+
polltimeout = pack_data->keepalive < 0
283+
? -1
284+
: 1000 * pack_data->keepalive;
285+
286+
ret = poll(pfd, pollsize, polltimeout);
282287

283288
if (ret < 0) {
284289
if (errno != EINTR) {
@@ -1115,6 +1120,8 @@ static int find_symref(const char *refname, const struct object_id *oid,
11151120

11161121
static int upload_pack_config(const char *var, const char *value, void *cb_data)
11171122
{
1123+
struct upload_pack_data *data = cb_data;
1124+
11181125
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
11191126
if (git_config_bool(var, value))
11201127
allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
@@ -1131,9 +1138,9 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
11311138
else
11321139
allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
11331140
} else if (!strcmp("uploadpack.keepalive", var)) {
1134-
keepalive = git_config_int(var, value);
1135-
if (!keepalive)
1136-
keepalive = -1;
1141+
data->keepalive = git_config_int(var, value);
1142+
if (!data->keepalive)
1143+
data->keepalive = -1;
11371144
} else if (!strcmp("uploadpack.allowfilter", var)) {
11381145
allow_filter = git_config_bool(var, value);
11391146
} else if (!strcmp("uploadpack.allowrefinwant", var)) {

0 commit comments

Comments
 (0)