@@ -253,8 +253,10 @@ static int find_common(struct fetch_negotiator *negotiator,
253
253
if (args -> stateless_rpc && multi_ack == 1 )
254
254
die (_ ("--stateless-rpc requires multi_ack_detailed" ));
255
255
256
- mark_tips (negotiator , args -> negotiation_tips );
257
- for_each_cached_alternate (negotiator , insert_one_alternate_object );
256
+ if (!args -> no_dependents ) {
257
+ mark_tips (negotiator , args -> negotiation_tips );
258
+ for_each_cached_alternate (negotiator , insert_one_alternate_object );
259
+ }
258
260
259
261
fetching = 0 ;
260
262
for ( ; refs ; refs = refs -> next ) {
@@ -271,8 +273,12 @@ static int find_common(struct fetch_negotiator *negotiator,
271
273
* We use lookup_object here because we are only
272
274
* interested in the case we *know* the object is
273
275
* reachable and we have already scanned it.
276
+ *
277
+ * Do this only if args->no_dependents is false (if it is true,
278
+ * we cannot trust the object flags).
274
279
*/
275
- if (((o = lookup_object (the_repository , remote -> hash )) != NULL ) &&
280
+ if (!args -> no_dependents &&
281
+ ((o = lookup_object (the_repository , remote -> hash )) != NULL ) &&
276
282
(o -> flags & COMPLETE )) {
277
283
continue ;
278
284
}
@@ -707,31 +713,29 @@ static void mark_complete_and_common_ref(struct fetch_negotiator *negotiator,
707
713
708
714
oidset_clear (& loose_oid_set );
709
715
710
- if (!args -> no_dependents ) {
711
- if (!args -> deepen ) {
712
- for_each_ref (mark_complete_oid , NULL );
713
- for_each_cached_alternate (NULL , mark_alternate_complete );
714
- commit_list_sort_by_date (& complete );
715
- if (cutoff )
716
- mark_recent_complete_commits (args , cutoff );
717
- }
716
+ if (!args -> deepen ) {
717
+ for_each_ref (mark_complete_oid , NULL );
718
+ for_each_cached_alternate (NULL , mark_alternate_complete );
719
+ commit_list_sort_by_date (& complete );
720
+ if (cutoff )
721
+ mark_recent_complete_commits (args , cutoff );
722
+ }
718
723
719
- /*
720
- * Mark all complete remote refs as common refs.
721
- * Don't mark them common yet; the server has to be told so first.
722
- */
723
- for (ref = * refs ; ref ; ref = ref -> next ) {
724
- struct object * o = deref_tag (the_repository ,
725
- lookup_object (the_repository ,
726
- ref -> old_oid .hash ),
727
- NULL , 0 );
724
+ /*
725
+ * Mark all complete remote refs as common refs.
726
+ * Don't mark them common yet; the server has to be told so first.
727
+ */
728
+ for (ref = * refs ; ref ; ref = ref -> next ) {
729
+ struct object * o = deref_tag (the_repository ,
730
+ lookup_object (the_repository ,
731
+ ref -> old_oid .hash ),
732
+ NULL , 0 );
728
733
729
- if (!o || o -> type != OBJ_COMMIT || !(o -> flags & COMPLETE ))
730
- continue ;
734
+ if (!o || o -> type != OBJ_COMMIT || !(o -> flags & COMPLETE ))
735
+ continue ;
731
736
732
- negotiator -> known_common (negotiator ,
733
- (struct commit * )o );
734
- }
737
+ negotiator -> known_common (negotiator ,
738
+ (struct commit * )o );
735
739
}
736
740
737
741
save_commit_buffer = old_save_commit_buffer ;
@@ -987,11 +991,15 @@ static struct ref *do_fetch_pack(struct fetch_pack_args *args,
987
991
if (!server_supports ("deepen-relative" ) && args -> deepen_relative )
988
992
die (_ ("Server does not support --deepen" ));
989
993
990
- mark_complete_and_common_ref (& negotiator , args , & ref );
991
- filter_refs (args , & ref , sought , nr_sought );
992
- if (everything_local (args , & ref )) {
993
- packet_flush (fd [1 ]);
994
- goto all_done ;
994
+ if (!args -> no_dependents ) {
995
+ mark_complete_and_common_ref (& negotiator , args , & ref );
996
+ filter_refs (args , & ref , sought , nr_sought );
997
+ if (everything_local (args , & ref )) {
998
+ packet_flush (fd [1 ]);
999
+ goto all_done ;
1000
+ }
1001
+ } else {
1002
+ filter_refs (args , & ref , sought , nr_sought );
995
1003
}
996
1004
if (find_common (& negotiator , args , fd , & oid , ref ) < 0 )
997
1005
if (!args -> keep_pack )
@@ -1037,7 +1045,7 @@ static void add_shallow_requests(struct strbuf *req_buf,
1037
1045
}
1038
1046
}
1039
1047
1040
- static void add_wants (const struct ref * wants , struct strbuf * req_buf )
1048
+ static void add_wants (int no_dependents , const struct ref * wants , struct strbuf * req_buf )
1041
1049
{
1042
1050
int use_ref_in_want = server_supports_feature ("fetch" , "ref-in-want" , 0 );
1043
1051
@@ -1054,8 +1062,12 @@ static void add_wants(const struct ref *wants, struct strbuf *req_buf)
1054
1062
* We use lookup_object here because we are only
1055
1063
* interested in the case we *know* the object is
1056
1064
* reachable and we have already scanned it.
1065
+ *
1066
+ * Do this only if args->no_dependents is false (if it is true,
1067
+ * we cannot trust the object flags).
1057
1068
*/
1058
- if (((o = lookup_object (the_repository , remote -> hash )) != NULL ) &&
1069
+ if (!no_dependents &&
1070
+ ((o = lookup_object (the_repository , remote -> hash )) != NULL ) &&
1059
1071
(o -> flags & COMPLETE )) {
1060
1072
continue ;
1061
1073
}
@@ -1152,7 +1164,7 @@ static int send_fetch_request(struct fetch_negotiator *negotiator, int fd_out,
1152
1164
}
1153
1165
1154
1166
/* add wants */
1155
- add_wants (wants , & req_buf );
1167
+ add_wants (args -> no_dependents , wants , & req_buf );
1156
1168
1157
1169
if (args -> no_dependents ) {
1158
1170
packet_buf_write (& req_buf , "done" );
@@ -1343,16 +1355,21 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1343
1355
args -> deepen = 1 ;
1344
1356
1345
1357
/* Filter 'ref' by 'sought' and those that aren't local */
1346
- mark_complete_and_common_ref (& negotiator , args , & ref );
1347
- filter_refs (args , & ref , sought , nr_sought );
1348
- if (everything_local (args , & ref ))
1349
- state = FETCH_DONE ;
1350
- else
1358
+ if (!args -> no_dependents ) {
1359
+ mark_complete_and_common_ref (& negotiator , args , & ref );
1360
+ filter_refs (args , & ref , sought , nr_sought );
1361
+ if (everything_local (args , & ref ))
1362
+ state = FETCH_DONE ;
1363
+ else
1364
+ state = FETCH_SEND_REQUEST ;
1365
+
1366
+ mark_tips (& negotiator , args -> negotiation_tips );
1367
+ for_each_cached_alternate (& negotiator ,
1368
+ insert_one_alternate_object );
1369
+ } else {
1370
+ filter_refs (args , & ref , sought , nr_sought );
1351
1371
state = FETCH_SEND_REQUEST ;
1352
-
1353
- mark_tips (& negotiator , args -> negotiation_tips );
1354
- for_each_cached_alternate (& negotiator ,
1355
- insert_one_alternate_object );
1372
+ }
1356
1373
break ;
1357
1374
case FETCH_SEND_REQUEST :
1358
1375
if (send_fetch_request (& negotiator , fd [1 ], args , ref ,
@@ -1595,6 +1612,20 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1595
1612
if (nr_sought )
1596
1613
nr_sought = remove_duplicates_in_refs (sought , nr_sought );
1597
1614
1615
+ if (args -> no_dependents && !args -> filter_options .choice ) {
1616
+ /*
1617
+ * The protocol does not support requesting that only the
1618
+ * wanted objects be sent, so approximate this by setting a
1619
+ * "blob:none" filter if no filter is already set. This works
1620
+ * for all object types: note that wanted blobs will still be
1621
+ * sent because they are directly specified as a "want".
1622
+ *
1623
+ * NEEDSWORK: Add an option in the protocol to request that
1624
+ * only the wanted objects be sent, and implement it.
1625
+ */
1626
+ parse_list_objects_filter (& args -> filter_options , "blob:none" );
1627
+ }
1628
+
1598
1629
if (!ref ) {
1599
1630
packet_flush (fd [1 ]);
1600
1631
die (_ ("no matching remote head" ));
0 commit comments