@matheusbsbs / matheus-bagliano / commits / 389f161ab2
Fork 0

upload-pack: move {want,have}_obj to upload_pack_data

As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the want_obj and have_obj object arrays into 'struct upload_pack_data'. These object arrays are used by both upload_pack() and upload_pack_v2(), for example when these functions call create_pack_file(). We are going to use 'struct upload_pack_data' in upload_pack() in a followup commit. 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 389f161ab295e9aad227ba9b13cc7b61b272dda8
1 file changed +25 -23
upload-pack.c
+25 -23
@@ -1132,6 +1132,8 @@ void upload_pack(struct upload_pack_options *options)
1132
1133 struct upload_pack_data {
1134 struct string_list wanted_refs;
1135 + struct object_array want_obj;
1136 + struct object_array have_obj;
1137 struct oid_array haves;
1138
1139 struct object_array shallows;
@@ -1157,12 +1159,16 @@ struct upload_pack_data {
1159 static void upload_pack_data_init(struct upload_pack_data *data)
1160 {
1161 struct string_list wanted_refs = STRING_LIST_INIT_DUP;
1162 + struct object_array want_obj = OBJECT_ARRAY_INIT;
1163 + struct object_array have_obj = OBJECT_ARRAY_INIT;
1164 struct oid_array haves = OID_ARRAY_INIT;
1165 struct object_array shallows = OBJECT_ARRAY_INIT;
1166 struct string_list deepen_not = STRING_LIST_INIT_DUP;
1167
1168 memset(data, 0, sizeof(*data));
1169 data->wanted_refs = wanted_refs;
1170 + data->want_obj = want_obj;
1171 + data->have_obj = have_obj;
1172 data->haves = haves;
1173 data->shallows = shallows;
1174 data->deepen_not = deepen_not;
@@ -1172,6 +1178,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
1178 static void upload_pack_data_clear(struct upload_pack_data *data)
1179 {
1180 string_list_clear(&data->wanted_refs, 1);
1181 + object_array_clear(&data->want_obj);
1182 + object_array_clear(&data->have_obj);
1183 oid_array_clear(&data->haves);
1184 object_array_clear(&data->shallows);
1185 string_list_clear(&data->deepen_not, 0);
@@ -1256,19 +1264,18 @@ static int parse_have(const char *line, struct oid_array *haves)
1264 }
1265
1266 static void process_args(struct packet_reader *request,
1259 - struct upload_pack_data *data,
1260 - struct object_array *want_obj)
1267 + struct upload_pack_data *data)
1268 {
1269 while (packet_reader_read(request) == PACKET_READ_NORMAL) {
1270 const char *arg = request->line;
1271 const char *p;
1272
1273 /* process want */
1267 - if (parse_want(&data->writer, arg, want_obj))
1274 + if (parse_want(&data->writer, arg, &data->want_obj))
1275 continue;
1276 if (allow_ref_in_want &&
1277 parse_want_ref(&data->writer, arg, &data->wanted_refs,
1271 - want_obj))
1278 + &data->want_obj))
1279 continue;
1280 /* process have line */
1281 if (parse_have(arg, &data->haves))
@@ -1399,17 +1406,16 @@ static int send_acks(struct packet_writer *writer, struct oid_array *acks,
1406 return 0;
1407 }
1408
1402 -static int process_haves_and_send_acks(struct upload_pack_data *data,
1403 - struct object_array *have_obj,
1404 - struct object_array *want_obj)
1409 +static int process_haves_and_send_acks(struct upload_pack_data *data)
1410 {
1411 struct oid_array common = OID_ARRAY_INIT;
1412 int ret = 0;
1413
1409 - process_haves(&data->haves, &common, have_obj);
1414 + process_haves(&data->haves, &common, &data->have_obj);
1415 if (data->done) {
1416 ret = 1;
1412 - } else if (send_acks(&data->writer, &common, have_obj, want_obj)) {
1417 + } else if (send_acks(&data->writer, &common,
1418 + &data->have_obj, &data->want_obj)) {
1419 packet_writer_delim(&data->writer);
1420 ret = 1;
1421 } else {
@@ -1441,8 +1447,7 @@ static void send_wanted_ref_info(struct upload_pack_data *data)
1447 packet_writer_delim(&data->writer);
1448 }
1449
1444 -static void send_shallow_info(struct upload_pack_data *data,
1445 - struct object_array *want_obj)
1450 +static void send_shallow_info(struct upload_pack_data *data)
1451 {
1452 /* No shallow info needs to be sent */
1453 if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
@@ -1455,10 +1460,10 @@ static void send_shallow_info(struct upload_pack_data *data,
1460 data->deepen_rev_list,
1461 data->deepen_since, &data->deepen_not,
1462 data->deepen_relative,
1458 - &data->shallows, want_obj) &&
1463 + &data->shallows, &data->want_obj) &&
1464 is_repository_shallow(the_repository))
1465 deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
1461 - &data->shallows, want_obj);
1466 + &data->shallows, &data->want_obj);
1467
1468 packet_delim(1);
1469 }
@@ -1475,8 +1480,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
1480 {
1481 enum fetch_state state = FETCH_PROCESS_ARGS;
1482 struct upload_pack_data data;
1478 - struct object_array have_obj = OBJECT_ARRAY_INIT;
1479 - struct object_array want_obj = OBJECT_ARRAY_INIT;
1483
1484 clear_object_flags(ALL_FLAGS);
1485
@@ -1488,9 +1491,9 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
1491 while (state != FETCH_DONE) {
1492 switch (state) {
1493 case FETCH_PROCESS_ARGS:
1491 - process_args(request, &data, &want_obj);
1494 + process_args(request, &data);
1495
1493 - if (!want_obj.nr) {
1496 + if (!data.want_obj.nr) {
1497 /*
1498 * Request didn't contain any 'want' lines,
1499 * guess they didn't want anything.
@@ -1510,18 +1513,19 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
1513 }
1514 break;
1515 case FETCH_SEND_ACKS:
1513 - if (process_haves_and_send_acks(&data, &have_obj,
1514 - &want_obj))
1516 + if (process_haves_and_send_acks(&data))
1517 state = FETCH_SEND_PACK;
1518 else
1519 state = FETCH_DONE;
1520 break;
1521 case FETCH_SEND_PACK:
1522 send_wanted_ref_info(&data);
1521 - send_shallow_info(&data, &want_obj);
1523 + send_shallow_info(&data);
1524
1525 packet_writer_write(&data.writer, "packfile\n");
1524 - create_pack_file(&have_obj, &want_obj, &data.filter_options);
1526 + create_pack_file(&data.have_obj,
1527 + &data.want_obj,
1528 + &data.filter_options);
1529 state = FETCH_DONE;
1530 break;
1531 case FETCH_DONE:
@@ -1530,8 +1534,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
1534 }
1535
1536 upload_pack_data_clear(&data);
1533 - object_array_clear(&have_obj);
1534 - object_array_clear(&want_obj);
1537 return 0;
1538 }
1539