@@ -1253,9 +1253,11 @@ static int process_acks(struct fetch_negotiator *negotiator,
1253
1253
}
1254
1254
1255
1255
static void receive_shallow_info (struct fetch_pack_args * args ,
1256
- struct packet_reader * reader )
1256
+ struct packet_reader * reader ,
1257
+ struct oid_array * shallows ,
1258
+ struct shallow_info * si )
1257
1259
{
1258
- int line_received = 0 ;
1260
+ int unshallow_received = 0 ;
1259
1261
1260
1262
process_section_header (reader , "shallow-info" , 0 );
1261
1263
while (packet_reader_read (reader ) == PACKET_READ_NORMAL ) {
@@ -1265,8 +1267,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
1265
1267
if (skip_prefix (reader -> line , "shallow " , & arg )) {
1266
1268
if (get_oid_hex (arg , & oid ))
1267
1269
die (_ ("invalid shallow line: %s" ), reader -> line );
1268
- register_shallow (the_repository , & oid );
1269
- line_received = 1 ;
1270
+ oid_array_append (shallows , & oid );
1270
1271
continue ;
1271
1272
}
1272
1273
if (skip_prefix (reader -> line , "unshallow " , & arg )) {
@@ -1279,7 +1280,7 @@ static void receive_shallow_info(struct fetch_pack_args *args,
1279
1280
die (_ ("error in object: %s" ), reader -> line );
1280
1281
if (unregister_shallow (& oid ))
1281
1282
die (_ ("no shallow found: %s" ), reader -> line );
1282
- line_received = 1 ;
1283
+ unshallow_received = 1 ;
1283
1284
continue ;
1284
1285
}
1285
1286
die (_ ("expected shallow/unshallow, got %s" ), reader -> line );
@@ -1289,10 +1290,31 @@ static void receive_shallow_info(struct fetch_pack_args *args,
1289
1290
reader -> status != PACKET_READ_DELIM )
1290
1291
die (_ ("error processing shallow info: %d" ), reader -> status );
1291
1292
1292
- if (line_received ) {
1293
+ if (args -> deepen || unshallow_received ) {
1294
+ /*
1295
+ * Treat these as shallow lines caused by our depth settings.
1296
+ * In v0, these lines cannot cause refs to be rejected; do the
1297
+ * same.
1298
+ */
1299
+ int i ;
1300
+
1301
+ for (i = 0 ; i < shallows -> nr ; i ++ )
1302
+ register_shallow (the_repository , & shallows -> oid [i ]);
1293
1303
setup_alternate_shallow (& shallow_lock , & alternate_shallow_file ,
1294
1304
NULL );
1295
1305
args -> deepen = 1 ;
1306
+ } else if (shallows -> nr ) {
1307
+ /*
1308
+ * Treat these as shallow lines caused by the remote being
1309
+ * shallow. In v0, remote refs that reach these objects are
1310
+ * rejected (unless --update-shallow is set); do the same.
1311
+ */
1312
+ prepare_shallow_info (si , shallows );
1313
+ if (si -> nr_ours || si -> nr_theirs )
1314
+ alternate_shallow_file =
1315
+ setup_temporary_shallow (si -> shallow );
1316
+ else
1317
+ alternate_shallow_file = NULL ;
1296
1318
} else {
1297
1319
alternate_shallow_file = NULL ;
1298
1320
}
@@ -1338,6 +1360,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1338
1360
int fd [2 ],
1339
1361
const struct ref * orig_ref ,
1340
1362
struct ref * * sought , int nr_sought ,
1363
+ struct oid_array * shallows ,
1364
+ struct shallow_info * si ,
1341
1365
char * * pack_lockfile )
1342
1366
{
1343
1367
struct ref * ref = copy_ref_list (orig_ref );
@@ -1412,7 +1436,7 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
1412
1436
case FETCH_GET_PACK :
1413
1437
/* Check for shallow-info section */
1414
1438
if (process_section_header (& reader , "shallow-info" , 1 ))
1415
- receive_shallow_info (args , & reader );
1439
+ receive_shallow_info (args , & reader , shallows , si );
1416
1440
1417
1441
if (process_section_header (& reader , "wanted-refs" , 1 ))
1418
1442
receive_wanted_refs (& reader , sought , nr_sought );
@@ -1625,6 +1649,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1625
1649
{
1626
1650
struct ref * ref_cpy ;
1627
1651
struct shallow_info si ;
1652
+ struct oid_array shallows_scratch = OID_ARRAY_INIT ;
1628
1653
1629
1654
fetch_pack_setup ();
1630
1655
if (nr_sought )
@@ -1648,13 +1673,18 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1648
1673
packet_flush (fd [1 ]);
1649
1674
die (_ ("no matching remote head" ));
1650
1675
}
1651
- prepare_shallow_info (& si , shallow );
1652
- if (version == protocol_v2 )
1676
+ if (version == protocol_v2 ) {
1677
+ if (shallow -> nr )
1678
+ BUG ("Protocol V2 does not provide shallows at this point in the fetch" );
1679
+ memset (& si , 0 , sizeof (si ));
1653
1680
ref_cpy = do_fetch_pack_v2 (args , fd , ref , sought , nr_sought ,
1681
+ & shallows_scratch , & si ,
1654
1682
pack_lockfile );
1655
- else
1683
+ } else {
1684
+ prepare_shallow_info (& si , shallow );
1656
1685
ref_cpy = do_fetch_pack (args , fd , ref , sought , nr_sought ,
1657
1686
& si , pack_lockfile );
1687
+ }
1658
1688
reprepare_packed_git (the_repository );
1659
1689
1660
1690
if (!args -> cloning && args -> deepen ) {
@@ -1676,6 +1706,7 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1676
1706
update_shallow (args , sought , nr_sought , & si );
1677
1707
cleanup :
1678
1708
clear_shallow_info (& si );
1709
+ oid_array_clear (& shallows_scratch );
1679
1710
return ref_cpy ;
1680
1711
}
1681
1712
0 commit comments