@@ -63,6 +63,7 @@ static int shown_url = 0;
6363static struct refspec refmap = REFSPEC_INIT_FETCH ;
6464static struct list_objects_filter_options filter_options ;
6565static struct string_list server_options = STRING_LIST_INIT_DUP ;
66+ static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP ;
6667
6768static int git_fetch_config (const char * k , const char * v , void * cb )
6869{
@@ -174,6 +175,8 @@ static struct option builtin_fetch_options[] = {
174175 TRANSPORT_FAMILY_IPV4 ),
175176 OPT_SET_INT ('6' , "ipv6" , & family , N_ ("use IPv6 addresses only" ),
176177 TRANSPORT_FAMILY_IPV6 ),
178+ OPT_STRING_LIST (0 , "negotiation-tip" , & negotiation_tip , N_ ("revision" ),
179+ N_ ("report that we have only objects reachable from this object" )),
177180 OPT_PARSE_LIST_OBJECTS_FILTER (& filter_options ),
178181 OPT_END ()
179182};
@@ -1049,6 +1052,40 @@ static void set_option(struct transport *transport, const char *name, const char
10491052 name , transport -> url );
10501053}
10511054
1055+
1056+ static int add_oid (const char * refname , const struct object_id * oid , int flags ,
1057+ void * cb_data )
1058+ {
1059+ struct oid_array * oids = cb_data ;
1060+
1061+ oid_array_append (oids , oid );
1062+ return 0 ;
1063+ }
1064+
1065+ static void add_negotiation_tips (struct git_transport_options * smart_options )
1066+ {
1067+ struct oid_array * oids = xcalloc (1 , sizeof (* oids ));
1068+ int i ;
1069+
1070+ for (i = 0 ; i < negotiation_tip .nr ; i ++ ) {
1071+ const char * s = negotiation_tip .items [i ].string ;
1072+ int old_nr ;
1073+ if (!has_glob_specials (s )) {
1074+ struct object_id oid ;
1075+ if (get_oid (s , & oid ))
1076+ die ("%s is not a valid object" , s );
1077+ oid_array_append (oids , & oid );
1078+ continue ;
1079+ }
1080+ old_nr = oids -> nr ;
1081+ for_each_glob_ref (add_oid , s , oids );
1082+ if (old_nr == oids -> nr )
1083+ warning ("Ignoring --negotiation-tip=%s because it does not match any refs" ,
1084+ s );
1085+ }
1086+ smart_options -> negotiation_tips = oids ;
1087+ }
1088+
10521089static struct transport * prepare_transport (struct remote * remote , int deepen )
10531090{
10541091 struct transport * transport ;
@@ -1075,6 +1112,12 @@ static struct transport *prepare_transport(struct remote *remote, int deepen)
10751112 filter_options .filter_spec );
10761113 set_option (transport , TRANS_OPT_FROM_PROMISOR , "1" );
10771114 }
1115+ if (negotiation_tip .nr ) {
1116+ if (transport -> smart_options )
1117+ add_negotiation_tips (transport -> smart_options );
1118+ else
1119+ warning ("Ignoring --negotiation-tip because the protocol does not support it." );
1120+ }
10781121 return transport ;
10791122}
10801123
0 commit comments