Skip to content

Commit 389f161

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 06c7a43 commit 389f161

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

upload-pack.c

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ void upload_pack(struct upload_pack_options *options)
11321132

11331133
struct upload_pack_data {
11341134
struct string_list wanted_refs;
1135+
struct object_array want_obj;
1136+
struct object_array have_obj;
11351137
struct oid_array haves;
11361138

11371139
struct object_array shallows;
@@ -1157,12 +1159,16 @@ struct upload_pack_data {
11571159
static void upload_pack_data_init(struct upload_pack_data *data)
11581160
{
11591161
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;
11601164
struct oid_array haves = OID_ARRAY_INIT;
11611165
struct object_array shallows = OBJECT_ARRAY_INIT;
11621166
struct string_list deepen_not = STRING_LIST_INIT_DUP;
11631167

11641168
memset(data, 0, sizeof(*data));
11651169
data->wanted_refs = wanted_refs;
1170+
data->want_obj = want_obj;
1171+
data->have_obj = have_obj;
11661172
data->haves = haves;
11671173
data->shallows = shallows;
11681174
data->deepen_not = deepen_not;
@@ -1172,6 +1178,8 @@ static void upload_pack_data_init(struct upload_pack_data *data)
11721178
static void upload_pack_data_clear(struct upload_pack_data *data)
11731179
{
11741180
string_list_clear(&data->wanted_refs, 1);
1181+
object_array_clear(&data->want_obj);
1182+
object_array_clear(&data->have_obj);
11751183
oid_array_clear(&data->haves);
11761184
object_array_clear(&data->shallows);
11771185
string_list_clear(&data->deepen_not, 0);
@@ -1256,19 +1264,18 @@ static int parse_have(const char *line, struct oid_array *haves)
12561264
}
12571265

12581266
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)
12611268
{
12621269
while (packet_reader_read(request) == PACKET_READ_NORMAL) {
12631270
const char *arg = request->line;
12641271
const char *p;
12651272

12661273
/* process want */
1267-
if (parse_want(&data->writer, arg, want_obj))
1274+
if (parse_want(&data->writer, arg, &data->want_obj))
12681275
continue;
12691276
if (allow_ref_in_want &&
12701277
parse_want_ref(&data->writer, arg, &data->wanted_refs,
1271-
want_obj))
1278+
&data->want_obj))
12721279
continue;
12731280
/* process have line */
12741281
if (parse_have(arg, &data->haves))
@@ -1399,17 +1406,16 @@ static int send_acks(struct packet_writer *writer, struct oid_array *acks,
13991406
return 0;
14001407
}
14011408

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)
14051410
{
14061411
struct oid_array common = OID_ARRAY_INIT;
14071412
int ret = 0;
14081413

1409-
process_haves(&data->haves, &common, have_obj);
1414+
process_haves(&data->haves, &common, &data->have_obj);
14101415
if (data->done) {
14111416
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)) {
14131419
packet_writer_delim(&data->writer);
14141420
ret = 1;
14151421
} else {
@@ -1441,8 +1447,7 @@ static void send_wanted_ref_info(struct upload_pack_data *data)
14411447
packet_writer_delim(&data->writer);
14421448
}
14431449

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)
14461451
{
14471452
/* No shallow info needs to be sent */
14481453
if (!data->depth && !data->deepen_rev_list && !data->shallows.nr &&
@@ -1455,10 +1460,10 @@ static void send_shallow_info(struct upload_pack_data *data,
14551460
data->deepen_rev_list,
14561461
data->deepen_since, &data->deepen_not,
14571462
data->deepen_relative,
1458-
&data->shallows, want_obj) &&
1463+
&data->shallows, &data->want_obj) &&
14591464
is_repository_shallow(the_repository))
14601465
deepen(&data->writer, INFINITE_DEPTH, data->deepen_relative,
1461-
&data->shallows, want_obj);
1466+
&data->shallows, &data->want_obj);
14621467

14631468
packet_delim(1);
14641469
}
@@ -1475,8 +1480,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
14751480
{
14761481
enum fetch_state state = FETCH_PROCESS_ARGS;
14771482
struct upload_pack_data data;
1478-
struct object_array have_obj = OBJECT_ARRAY_INIT;
1479-
struct object_array want_obj = OBJECT_ARRAY_INIT;
14801483

14811484
clear_object_flags(ALL_FLAGS);
14821485

@@ -1488,9 +1491,9 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
14881491
while (state != FETCH_DONE) {
14891492
switch (state) {
14901493
case FETCH_PROCESS_ARGS:
1491-
process_args(request, &data, &want_obj);
1494+
process_args(request, &data);
14921495

1493-
if (!want_obj.nr) {
1496+
if (!data.want_obj.nr) {
14941497
/*
14951498
* Request didn't contain any 'want' lines,
14961499
* guess they didn't want anything.
@@ -1510,18 +1513,19 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
15101513
}
15111514
break;
15121515
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))
15151517
state = FETCH_SEND_PACK;
15161518
else
15171519
state = FETCH_DONE;
15181520
break;
15191521
case FETCH_SEND_PACK:
15201522
send_wanted_ref_info(&data);
1521-
send_shallow_info(&data, &want_obj);
1523+
send_shallow_info(&data);
15221524

15231525
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);
15251529
state = FETCH_DONE;
15261530
break;
15271531
case FETCH_DONE:
@@ -1530,8 +1534,6 @@ int upload_pack_v2(struct repository *r, struct argv_array *keys,
15301534
}
15311535

15321536
upload_pack_data_clear(&data);
1533-
object_array_clear(&have_obj);
1534-
object_array_clear(&want_obj);
15351537
return 0;
15361538
}
15371539

0 commit comments

Comments
 (0)