Skip to content

Commit 57c3451

Browse files
jonathantanmygitster
authored andcommitted
fetch-pack: refactor add_haves()
A subsequent commit will need part, but not all, of the functionality in add_haves(), so move some of its functionality to its sole caller send_fetch_request(). Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8102570 commit 57c3451

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

fetch-pack.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,11 +1195,9 @@ static void add_common(struct strbuf *req_buf, struct oidset *common)
11951195
}
11961196

11971197
static int add_haves(struct fetch_negotiator *negotiator,
1198-
int seen_ack,
11991198
struct strbuf *req_buf,
1200-
int *haves_to_send, int *in_vain)
1199+
int *haves_to_send)
12011200
{
1202-
int ret = 0;
12031201
int haves_added = 0;
12041202
const struct object_id *oid;
12051203

@@ -1209,17 +1207,10 @@ static int add_haves(struct fetch_negotiator *negotiator,
12091207
break;
12101208
}
12111209

1212-
*in_vain += haves_added;
1213-
if (!haves_added || (seen_ack && *in_vain >= MAX_IN_VAIN)) {
1214-
/* Send Done */
1215-
packet_buf_write(req_buf, "done\n");
1216-
ret = 1;
1217-
}
1218-
12191210
/* Increase haves to send on next round */
12201211
*haves_to_send = next_flush(1, *haves_to_send);
12211212

1222-
return ret;
1213+
return haves_added;
12231214
}
12241215

12251216
static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
@@ -1228,7 +1219,8 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
12281219
int *haves_to_send, int *in_vain,
12291220
int sideband_all, int seen_ack)
12301221
{
1231-
int ret = 0;
1222+
int haves_added;
1223+
int done_sent = 0;
12321224
const char *hash_name;
12331225
struct strbuf req_buf = STRBUF_INIT;
12341226

@@ -1312,17 +1304,21 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
13121304
/* Add all of the common commits we've found in previous rounds */
13131305
add_common(&req_buf, common);
13141306

1315-
/* Add initial haves */
1316-
ret = add_haves(negotiator, seen_ack, &req_buf,
1317-
haves_to_send, in_vain);
1307+
haves_added = add_haves(negotiator, &req_buf, haves_to_send);
1308+
*in_vain += haves_added;
1309+
if (!haves_added || (seen_ack && *in_vain >= MAX_IN_VAIN)) {
1310+
/* Send Done */
1311+
packet_buf_write(&req_buf, "done\n");
1312+
done_sent = 1;
1313+
}
13181314

13191315
/* Send request */
13201316
packet_buf_flush(&req_buf);
13211317
if (write_in_full(fd_out, req_buf.buf, req_buf.len) < 0)
13221318
die_errno(_("unable to write request to remote"));
13231319

13241320
strbuf_release(&req_buf);
1325-
return ret;
1321+
return done_sent;
13261322
}
13271323

13281324
/*

0 commit comments

Comments
 (0)