Skip to content

Commit df126e1

Browse files
committed
remote-curl: hoist gzip buffer size to top of post_rpc
When we gzip the post data for a smart-http rpc request, we compute the gzip body and its size inside the "use_gzip" conditional. We keep track of the body after the conditional ends, but not the size. Let's remember both, which will enable us to retry failed gzip requests in a future patch. Signed-off-by: Jeff King <[email protected]>
1 parent 1960897 commit df126e1

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

remote-curl.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ static int post_rpc(struct rpc_state *rpc)
413413
struct curl_slist *headers = NULL;
414414
int use_gzip = rpc->gzip_request;
415415
char *gzip_body = NULL;
416+
size_t gzip_size;
416417
int err, large_request = 0;
417418

418419
/* Try to load the entire request, if we can fit it into the
@@ -478,19 +479,18 @@ static int post_rpc(struct rpc_state *rpc)
478479
* we can try to deflate it ourselves, this may save on.
479480
* the transfer time.
480481
*/
481-
size_t size;
482482
git_zstream stream;
483483
int ret;
484484

485485
memset(&stream, 0, sizeof(stream));
486486
git_deflate_init_gzip(&stream, Z_BEST_COMPRESSION);
487-
size = git_deflate_bound(&stream, rpc->len);
488-
gzip_body = xmalloc(size);
487+
gzip_size = git_deflate_bound(&stream, rpc->len);
488+
gzip_body = xmalloc(gzip_size);
489489

490490
stream.next_in = (unsigned char *)rpc->buf;
491491
stream.avail_in = rpc->len;
492492
stream.next_out = (unsigned char *)gzip_body;
493-
stream.avail_out = size;
493+
stream.avail_out = gzip_size;
494494

495495
ret = git_deflate(&stream, Z_FINISH);
496496
if (ret != Z_STREAM_END)
@@ -500,16 +500,16 @@ static int post_rpc(struct rpc_state *rpc)
500500
if (ret != Z_OK)
501501
die("cannot deflate request; zlib end error %d", ret);
502502

503-
size = stream.total_out;
503+
gzip_size = stream.total_out;
504504

505505
headers = curl_slist_append(headers, "Content-Encoding: gzip");
506506
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDS, gzip_body);
507-
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, size);
507+
curl_easy_setopt(slot->curl, CURLOPT_POSTFIELDSIZE, gzip_size);
508508

509509
if (options.verbosity > 1) {
510510
fprintf(stderr, "POST %s (gzip %lu to %lu bytes)\n",
511511
rpc->service_name,
512-
(unsigned long)rpc->len, (unsigned long)size);
512+
(unsigned long)rpc->len, (unsigned long)gzip_size);
513513
fflush(stderr);
514514
}
515515
} else {

0 commit comments

Comments
 (0)