@@ -50,8 +50,12 @@ static int marked;
50
50
*/
51
51
#define MAX_IN_VAIN 256
52
52
53
- static struct prio_queue rev_list = { compare_commits_by_commit_date };
54
- static int non_common_revs , multi_ack , use_sideband ;
53
+ struct negotiation_state {
54
+ struct prio_queue rev_list ;
55
+ int non_common_revs ;
56
+ };
57
+
58
+ static int multi_ack , use_sideband ;
55
59
/* Allow specifying sha1 if it is a ref tip. */
56
60
#define ALLOW_TIP_SHA1 01
57
61
/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
@@ -93,7 +97,9 @@ static void cache_one_alternate(const char *refname,
93
97
cache -> items [cache -> nr ++ ] = obj ;
94
98
}
95
99
96
- static void for_each_cached_alternate (void (* cb )(struct object * ))
100
+ static void for_each_cached_alternate (struct negotiation_state * ns ,
101
+ void (* cb )(struct negotiation_state * ,
102
+ struct object * ))
97
103
{
98
104
static int initialized ;
99
105
static struct alternate_object_cache cache ;
@@ -105,38 +111,41 @@ static void for_each_cached_alternate(void (*cb)(struct object *))
105
111
}
106
112
107
113
for (i = 0 ; i < cache .nr ; i ++ )
108
- cb (cache .items [i ]);
114
+ cb (ns , cache .items [i ]);
109
115
}
110
116
111
- static void rev_list_push (struct commit * commit , int mark )
117
+ static void rev_list_push (struct negotiation_state * ns ,
118
+ struct commit * commit , int mark )
112
119
{
113
120
if (!(commit -> object .flags & mark )) {
114
121
commit -> object .flags |= mark ;
115
122
116
123
if (parse_commit (commit ))
117
124
return ;
118
125
119
- prio_queue_put (& rev_list , commit );
126
+ prio_queue_put (& ns -> rev_list , commit );
120
127
121
128
if (!(commit -> object .flags & COMMON ))
122
- non_common_revs ++ ;
129
+ ns -> non_common_revs ++ ;
123
130
}
124
131
}
125
132
126
- static int rev_list_insert_ref (const char * refname , const struct object_id * oid )
133
+ static int rev_list_insert_ref (struct negotiation_state * ns ,
134
+ const char * refname ,
135
+ const struct object_id * oid )
127
136
{
128
137
struct object * o = deref_tag (parse_object (oid ), refname , 0 );
129
138
130
139
if (o && o -> type == OBJ_COMMIT )
131
- rev_list_push ((struct commit * )o , SEEN );
140
+ rev_list_push (ns , (struct commit * )o , SEEN );
132
141
133
142
return 0 ;
134
143
}
135
144
136
145
static int rev_list_insert_ref_oid (const char * refname , const struct object_id * oid ,
137
146
int flag , void * cb_data )
138
147
{
139
- return rev_list_insert_ref (refname , oid );
148
+ return rev_list_insert_ref (cb_data , refname , oid );
140
149
}
141
150
142
151
static int clear_marks (const char * refname , const struct object_id * oid ,
@@ -156,7 +165,7 @@ static int clear_marks(const char *refname, const struct object_id *oid,
156
165
when only the server does not yet know that they are common).
157
166
*/
158
167
159
- static void mark_common (struct commit * commit ,
168
+ static void mark_common (struct negotiation_state * ns , struct commit * commit ,
160
169
int ancestors_only , int dont_parse )
161
170
{
162
171
if (commit != NULL && !(commit -> object .flags & COMMON )) {
@@ -166,20 +175,21 @@ static void mark_common(struct commit *commit,
166
175
o -> flags |= COMMON ;
167
176
168
177
if (!(o -> flags & SEEN ))
169
- rev_list_push (commit , SEEN );
178
+ rev_list_push (ns , commit , SEEN );
170
179
else {
171
180
struct commit_list * parents ;
172
181
173
182
if (!ancestors_only && !(o -> flags & POPPED ))
174
- non_common_revs -- ;
183
+ ns -> non_common_revs -- ;
175
184
if (!o -> parsed && !dont_parse )
176
185
if (parse_commit (commit ))
177
186
return ;
178
187
179
188
for (parents = commit -> parents ;
180
189
parents ;
181
190
parents = parents -> next )
182
- mark_common (parents -> item , 0 , dont_parse );
191
+ mark_common (ns , parents -> item , 0 ,
192
+ dont_parse );
183
193
}
184
194
}
185
195
}
@@ -188,24 +198,24 @@ static void mark_common(struct commit *commit,
188
198
Get the next rev to send, ignoring the common.
189
199
*/
190
200
191
- static const struct object_id * get_rev (void )
201
+ static const struct object_id * get_rev (struct negotiation_state * ns )
192
202
{
193
203
struct commit * commit = NULL ;
194
204
195
205
while (commit == NULL ) {
196
206
unsigned int mark ;
197
207
struct commit_list * parents ;
198
208
199
- if (rev_list .nr == 0 || non_common_revs == 0 )
209
+ if (ns -> rev_list .nr == 0 || ns -> non_common_revs == 0 )
200
210
return NULL ;
201
211
202
- commit = prio_queue_get (& rev_list );
212
+ commit = prio_queue_get (& ns -> rev_list );
203
213
parse_commit (commit );
204
214
parents = commit -> parents ;
205
215
206
216
commit -> object .flags |= POPPED ;
207
217
if (!(commit -> object .flags & COMMON ))
208
- non_common_revs -- ;
218
+ ns -> non_common_revs -- ;
209
219
210
220
if (commit -> object .flags & COMMON ) {
211
221
/* do not send "have", and ignore ancestors */
@@ -220,9 +230,9 @@ static const struct object_id *get_rev(void)
220
230
221
231
while (parents ) {
222
232
if (!(parents -> item -> object .flags & SEEN ))
223
- rev_list_push (parents -> item , mark );
233
+ rev_list_push (ns , parents -> item , mark );
224
234
if (mark & COMMON )
225
- mark_common (parents -> item , 1 , 0 );
235
+ mark_common (ns , parents -> item , 1 , 0 );
226
236
parents = parents -> next ;
227
237
}
228
238
}
@@ -296,9 +306,10 @@ static void send_request(struct fetch_pack_args *args,
296
306
write_or_die (fd , buf -> buf , buf -> len );
297
307
}
298
308
299
- static void insert_one_alternate_object (struct object * obj )
309
+ static void insert_one_alternate_object (struct negotiation_state * ns ,
310
+ struct object * obj )
300
311
{
301
- rev_list_insert_ref (NULL , & obj -> oid );
312
+ rev_list_insert_ref (ns , NULL , & obj -> oid );
302
313
}
303
314
304
315
#define INITIAL_FLUSH 16
@@ -321,7 +332,8 @@ static int next_flush(int stateless_rpc, int count)
321
332
return count ;
322
333
}
323
334
324
- static int find_common (struct fetch_pack_args * args ,
335
+ static int find_common (struct negotiation_state * ns ,
336
+ struct fetch_pack_args * args ,
325
337
int fd [2 ], struct object_id * result_oid ,
326
338
struct ref * refs )
327
339
{
@@ -337,8 +349,8 @@ static int find_common(struct fetch_pack_args *args,
337
349
if (args -> stateless_rpc && multi_ack == 1 )
338
350
die (_ ("--stateless-rpc requires multi_ack_detailed" ));
339
351
340
- for_each_ref (rev_list_insert_ref_oid , NULL );
341
- for_each_cached_alternate (insert_one_alternate_object );
352
+ for_each_ref (rev_list_insert_ref_oid , ns );
353
+ for_each_cached_alternate (ns , insert_one_alternate_object );
342
354
343
355
fetching = 0 ;
344
356
for ( ; refs ; refs = refs -> next ) {
@@ -456,7 +468,7 @@ static int find_common(struct fetch_pack_args *args,
456
468
retval = -1 ;
457
469
if (args -> no_dependents )
458
470
goto done ;
459
- while ((oid = get_rev ())) {
471
+ while ((oid = get_rev (ns ))) {
460
472
packet_buf_write (& req_buf , "have %s\n" , oid_to_hex (oid ));
461
473
print_verbose (args , "have %s" , oid_to_hex (oid ));
462
474
in_vain ++ ;
@@ -514,7 +526,7 @@ static int find_common(struct fetch_pack_args *args,
514
526
} else if (!args -> stateless_rpc
515
527
|| ack != ACK_common )
516
528
in_vain = 0 ;
517
- mark_common (commit , 0 , 1 );
529
+ mark_common (ns , commit , 0 , 1 );
518
530
retval = 0 ;
519
531
got_continue = 1 ;
520
532
if (ack == ACK_ready )
@@ -704,7 +716,8 @@ static void filter_refs(struct fetch_pack_args *args,
704
716
* refs = newlist ;
705
717
}
706
718
707
- static void mark_alternate_complete (struct object * obj )
719
+ static void mark_alternate_complete (struct negotiation_state * unused ,
720
+ struct object * obj )
708
721
{
709
722
mark_complete (& obj -> oid );
710
723
}
@@ -741,7 +754,8 @@ static int add_loose_objects_to_set(const struct object_id *oid,
741
754
* earliest commit time of the objects in refs that are commits and that we know
742
755
* the commit time of.
743
756
*/
744
- static void mark_complete_and_common_ref (struct fetch_pack_args * args ,
757
+ static void mark_complete_and_common_ref (struct negotiation_state * ns ,
758
+ struct fetch_pack_args * args ,
745
759
struct ref * * refs )
746
760
{
747
761
struct ref * ref ;
@@ -792,7 +806,7 @@ static void mark_complete_and_common_ref(struct fetch_pack_args *args,
792
806
if (!args -> no_dependents ) {
793
807
if (!args -> deepen ) {
794
808
for_each_ref (mark_complete_oid , NULL );
795
- for_each_cached_alternate (mark_alternate_complete );
809
+ for_each_cached_alternate (NULL , mark_alternate_complete );
796
810
commit_list_sort_by_date (& complete );
797
811
if (cutoff )
798
812
mark_recent_complete_commits (args , cutoff );
@@ -810,9 +824,10 @@ static void mark_complete_and_common_ref(struct fetch_pack_args *args,
810
824
continue ;
811
825
812
826
if (!(o -> flags & SEEN )) {
813
- rev_list_push ((struct commit * )o , COMMON_REF | SEEN );
827
+ rev_list_push (ns , (struct commit * )o ,
828
+ COMMON_REF | SEEN );
814
829
815
- mark_common ((struct commit * )o , 1 , 1 );
830
+ mark_common (ns , (struct commit * )o , 1 , 1 );
816
831
}
817
832
}
818
833
}
@@ -995,6 +1010,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
995
1010
struct object_id oid ;
996
1011
const char * agent_feature ;
997
1012
int agent_len ;
1013
+ struct negotiation_state ns = { { compare_commits_by_commit_date } };
998
1014
999
1015
sort_ref_list (& ref , ref_compare_name );
1000
1016
QSORT (sought , nr_sought , cmp_ref_by_name );
@@ -1070,13 +1086,13 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1070
1086
if (marked )
1071
1087
for_each_ref (clear_marks , NULL );
1072
1088
marked = 1 ;
1073
- mark_complete_and_common_ref (args , & ref );
1089
+ mark_complete_and_common_ref (& ns , args , & ref );
1074
1090
filter_refs (args , & ref , sought , nr_sought );
1075
1091
if (everything_local (args , & ref )) {
1076
1092
packet_flush (fd [1 ]);
1077
1093
goto all_done ;
1078
1094
}
1079
- if (find_common (args , fd , & oid , ref ) < 0 )
1095
+ if (find_common (& ns , args , fd , & oid , ref ) < 0 )
1080
1096
if (!args -> keep_pack )
1081
1097
/* When cloning, it is not unusual to have
1082
1098
* no common commit.
@@ -1096,7 +1112,7 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
1096
1112
die (_ ("git fetch-pack: fetch failed." ));
1097
1113
1098
1114
all_done :
1099
- clear_prio_queue (& rev_list );
1115
+ clear_prio_queue (& ns . rev_list );
1100
1116
return ref ;
1101
1117
}
1102
1118
@@ -1158,13 +1174,14 @@ static void add_common(struct strbuf *req_buf, struct oidset *common)
1158
1174
}
1159
1175
}
1160
1176
1161
- static int add_haves (struct strbuf * req_buf , int * haves_to_send , int * in_vain )
1177
+ static int add_haves (struct negotiation_state * ns , struct strbuf * req_buf ,
1178
+ int * haves_to_send , int * in_vain )
1162
1179
{
1163
1180
int ret = 0 ;
1164
1181
int haves_added = 0 ;
1165
1182
const struct object_id * oid ;
1166
1183
1167
- while ((oid = get_rev ())) {
1184
+ while ((oid = get_rev (ns ))) {
1168
1185
packet_buf_write (req_buf , "have %s\n" , oid_to_hex (oid ));
1169
1186
if (++ haves_added >= * haves_to_send )
1170
1187
break ;
@@ -1183,7 +1200,8 @@ static int add_haves(struct strbuf *req_buf, int *haves_to_send, int *in_vain)
1183
1200
return ret ;
1184
1201
}
1185
1202
1186
- static int send_fetch_request (int fd_out , const struct fetch_pack_args * args ,
1203
+ static int send_fetch_request (struct negotiation_state * ns , int fd_out ,
1204
+ const struct fetch_pack_args * args ,
1187
1205
const struct ref * wants , struct oidset * common ,
1188
1206
int * haves_to_send , int * in_vain )
1189
1207
{
@@ -1239,7 +1257,7 @@ static int send_fetch_request(int fd_out, const struct fetch_pack_args *args,
1239
1257
add_common (& req_buf , common );
1240
1258
1241
1259
/* Add initial haves */
1242
- ret = add_haves (& req_buf , haves_to_send , in_vain );
1260
+ ret = add_haves (ns , & req_buf , haves_to_send , in_vain );
1243
1261
}
1244
1262
1245
1263
/* Send request */
@@ -1276,7 +1294,9 @@ static int process_section_header(struct packet_reader *reader,
1276
1294
return ret ;
1277
1295
}
1278
1296
1279
- static int process_acks (struct packet_reader * reader , struct oidset * common )
1297
+ static int process_acks (struct negotiation_state * ns ,
1298
+ struct packet_reader * reader ,
1299
+ struct oidset * common )
1280
1300
{
1281
1301
/* received */
1282
1302
int received_ready = 0 ;
@@ -1295,7 +1315,7 @@ static int process_acks(struct packet_reader *reader, struct oidset *common)
1295
1315
struct commit * commit ;
1296
1316
oidset_insert (common , & oid );
1297
1317
commit = lookup_commit (& oid );
1298
- mark_common (commit , 0 , 1 );
1318
+ mark_common (ns , commit , 0 , 1 );
1299
1319
}
1300
1320
continue ;
1301
1321
}
@@ -1373,6 +1393,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1373
1393
struct packet_reader reader ;
1374
1394
int in_vain = 0 ;
1375
1395
int haves_to_send = INITIAL_FLUSH ;
1396
+ struct negotiation_state ns = { { compare_commits_by_commit_date } };
1376
1397
packet_reader_init (& reader , fd [0 ], NULL , 0 ,
1377
1398
PACKET_READ_CHOMP_NEWLINE );
1378
1399
@@ -1393,26 +1414,27 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1393
1414
marked = 1 ;
1394
1415
1395
1416
/* Filter 'ref' by 'sought' and those that aren't local */
1396
- mark_complete_and_common_ref (args , & ref );
1417
+ mark_complete_and_common_ref (& ns , args , & ref );
1397
1418
filter_refs (args , & ref , sought , nr_sought );
1398
1419
if (everything_local (args , & ref ))
1399
1420
state = FETCH_DONE ;
1400
1421
else
1401
1422
state = FETCH_SEND_REQUEST ;
1402
1423
1403
- for_each_ref (rev_list_insert_ref_oid , NULL );
1404
- for_each_cached_alternate (insert_one_alternate_object );
1424
+ for_each_ref (rev_list_insert_ref_oid , & ns );
1425
+ for_each_cached_alternate (& ns ,
1426
+ insert_one_alternate_object );
1405
1427
break ;
1406
1428
case FETCH_SEND_REQUEST :
1407
- if (send_fetch_request (fd [1 ], args , ref , & common ,
1429
+ if (send_fetch_request (& ns , fd [1 ], args , ref , & common ,
1408
1430
& haves_to_send , & in_vain ))
1409
1431
state = FETCH_GET_PACK ;
1410
1432
else
1411
1433
state = FETCH_PROCESS_ACKS ;
1412
1434
break ;
1413
1435
case FETCH_PROCESS_ACKS :
1414
1436
/* Process ACKs/NAKs */
1415
- switch (process_acks (& reader , & common )) {
1437
+ switch (process_acks (& ns , & reader , & common )) {
1416
1438
case 2 :
1417
1439
state = FETCH_GET_PACK ;
1418
1440
break ;
@@ -1441,7 +1463,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1441
1463
}
1442
1464
}
1443
1465
1444
- clear_prio_queue (& rev_list );
1466
+ clear_prio_queue (& ns . rev_list );
1445
1467
oidset_clear (& common );
1446
1468
return ref ;
1447
1469
}
0 commit comments