@matheusbsbs / matheus-bagliano / commits / 0797769505
Fork 0

upload-pack: pass upload_pack_data to get_common_commits()

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's pass 'struct upload_pack_data' to get_common_commits(), so that this function and the functions it calls can use all the fields of that struct in followup commits. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 15, 2020 at 12:04 UTC 079776950561befa3040ebad789da2c3fab918ef
1 file changed +13 -13
upload-pack.c
+13 -13
@@ -414,9 +414,8 @@ static int ok_to_give_up(const struct object_array *have_obj,
414 min_generation);
415 }
416
417 -static int get_common_commits(struct packet_reader *reader,
418 - struct object_array *have_obj,
419 - struct object_array *want_obj)
417 +static int get_common_commits(struct upload_pack_data *data,
418 + struct packet_reader *reader)
419 {
420 struct object_id oid;
421 char last_hex[GIT_MAX_HEXSZ + 1];
@@ -432,12 +431,14 @@ static int get_common_commits(struct packet_reader *reader,
431 reset_timeout();
432
433 if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
435 - if (multi_ack == 2 && got_common
436 - && !got_other && ok_to_give_up(have_obj, want_obj)) {
434 + if (multi_ack == 2
435 + && got_common
436 + && !got_other
437 + && ok_to_give_up(&data->have_obj, &data->want_obj)) {
438 sent_ready = 1;
439 packet_write_fmt(1, "ACK %s ready\n", last_hex);
440 }
440 - if (have_obj->nr == 0 || multi_ack)
441 + if (data->have_obj.nr == 0 || multi_ack)
442 packet_write_fmt(1, "NAK\n");
443
444 if (no_done && sent_ready) {
@@ -451,10 +452,11 @@ static int get_common_commits(struct packet_reader *reader,
452 continue;
453 }
454 if (skip_prefix(reader->line, "have ", &arg)) {
454 - switch (got_oid(arg, &oid, have_obj)) {
455 + switch (got_oid(arg, &oid, &data->have_obj)) {
456 case -1: /* they have what we do not */
457 got_other = 1;
457 - if (multi_ack && ok_to_give_up(have_obj, want_obj)) {
458 + if (multi_ack
459 + && ok_to_give_up(&data->have_obj, &data->want_obj)) {
460 const char *hex = oid_to_hex(&oid);
461 if (multi_ack == 2) {
462 sent_ready = 1;
@@ -470,14 +472,14 @@ static int get_common_commits(struct packet_reader *reader,
472 packet_write_fmt(1, "ACK %s common\n", last_hex);
473 else if (multi_ack)
474 packet_write_fmt(1, "ACK %s continue\n", last_hex);
473 - else if (have_obj->nr == 1)
475 + else if (data->have_obj.nr == 1)
476 packet_write_fmt(1, "ACK %s\n", last_hex);
477 break;
478 }
479 continue;
480 }
481 if (!strcmp(reader->line, "done")) {
480 - if (have_obj->nr > 0) {
482 + if (data->have_obj.nr > 0) {
483 if (multi_ack)
484 packet_write_fmt(1, "ACK %s\n", last_hex);
485 return 0;
@@ -1176,9 +1178,7 @@ void upload_pack(struct upload_pack_options *options)
1178
1179 receive_needs(&reader, &data.want_obj, &data.filter_options);
1180 if (data.want_obj.nr) {
1179 - get_common_commits(&reader,
1180 - &data.have_obj,
1181 - &data.want_obj);
1181 + get_common_commits(&data, &reader);
1182 create_pack_file(&data.have_obj,
1183 &data.want_obj,
1184 &data.filter_options);