@@ -1446,6 +1446,72 @@ static int module_clone(int argc, const char **argv, const char *prefix)
1446
1446
return 0 ;
1447
1447
}
1448
1448
1449
+ static void determine_submodule_update_strategy (struct repository * r ,
1450
+ int just_cloned ,
1451
+ const char * path ,
1452
+ const char * update ,
1453
+ struct submodule_update_strategy * out )
1454
+ {
1455
+ const struct submodule * sub = submodule_from_path (r , & null_oid , path );
1456
+ char * key ;
1457
+ const char * val ;
1458
+
1459
+ key = xstrfmt ("submodule.%s.update" , sub -> name );
1460
+
1461
+ if (update ) {
1462
+ trace_printf ("parsing update" );
1463
+ if (parse_submodule_update_strategy (update , out ) < 0 )
1464
+ die (_ ("Invalid update mode '%s' for submodule path '%s'" ),
1465
+ update , path );
1466
+ } else if (!repo_config_get_string_const (r , key , & val )) {
1467
+ if (parse_submodule_update_strategy (val , out ) < 0 )
1468
+ die (_ ("Invalid update mode '%s' configured for submodule path '%s'" ),
1469
+ val , path );
1470
+ } else if (sub -> update_strategy .type != SM_UPDATE_UNSPECIFIED ) {
1471
+ trace_printf ("loaded thing" );
1472
+ out -> type = sub -> update_strategy .type ;
1473
+ out -> command = sub -> update_strategy .command ;
1474
+ } else
1475
+ out -> type = SM_UPDATE_CHECKOUT ;
1476
+
1477
+ if (just_cloned &&
1478
+ (out -> type == SM_UPDATE_MERGE ||
1479
+ out -> type == SM_UPDATE_REBASE ||
1480
+ out -> type == SM_UPDATE_NONE ))
1481
+ out -> type = SM_UPDATE_CHECKOUT ;
1482
+
1483
+ free (key );
1484
+ }
1485
+
1486
+ static int module_update_module_mode (int argc , const char * * argv , const char * prefix )
1487
+ {
1488
+ const char * path , * update = NULL ;
1489
+ int just_cloned ;
1490
+ struct submodule_update_strategy update_strategy = { .type = SM_UPDATE_CHECKOUT };
1491
+
1492
+ if (argc < 3 || argc > 4 )
1493
+ die ("submodule--helper update-module-clone expects <just-cloned> <path> [<update>]" );
1494
+
1495
+ just_cloned = git_config_int ("just_cloned" , argv [1 ]);
1496
+ path = argv [2 ];
1497
+
1498
+ if (argc == 4 )
1499
+ update = argv [3 ];
1500
+
1501
+ determine_submodule_update_strategy (the_repository ,
1502
+ just_cloned , path , update ,
1503
+ & update_strategy );
1504
+ fputs (submodule_strategy_to_string (& update_strategy ), stdout );
1505
+
1506
+ return 0 ;
1507
+ }
1508
+
1509
+ struct update_clone_data {
1510
+ const struct submodule * sub ;
1511
+ struct object_id oid ;
1512
+ unsigned just_cloned ;
1513
+ };
1514
+
1449
1515
struct submodule_update_clone {
1450
1516
/* index into 'list', the list of submodules to look into for cloning */
1451
1517
int current ;
@@ -1465,20 +1531,23 @@ struct submodule_update_clone {
1465
1531
const char * recursive_prefix ;
1466
1532
const char * prefix ;
1467
1533
1468
- /* Machine-readable status lines to be consumed by git-submodule.sh */
1469
- struct string_list projectlines ;
1534
+ /* to be consumed by git-submodule.sh */
1535
+ struct update_clone_data * update_clone ;
1536
+ int update_clone_nr ; int update_clone_alloc ;
1470
1537
1471
1538
/* If we want to stop as fast as possible and return an error */
1472
1539
unsigned quickstop : 1 ;
1473
1540
1474
1541
/* failed clones to be retried again */
1475
1542
const struct cache_entry * * failed_clones ;
1476
1543
int failed_clones_nr , failed_clones_alloc ;
1544
+
1545
+ int max_jobs ;
1477
1546
};
1478
1547
#define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
1479
1548
SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, 0, \
1480
1549
NULL, NULL, NULL, \
1481
- STRING_LIST_INIT_DUP , 0, NULL, 0, 0}
1550
+ NULL , 0, 0, 0, NULL, 0 , 0, 0}
1482
1551
1483
1552
1484
1553
static void next_submodule_warn_missing (struct submodule_update_clone * suc ,
@@ -1572,11 +1641,12 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1572
1641
strbuf_addf (& sb , "%s/.git" , ce -> name );
1573
1642
needs_cloning = !file_exists (sb .buf );
1574
1643
1575
- strbuf_reset (& sb );
1576
- strbuf_addf (& sb , "%06o %s %d %d\t%s\n" , ce -> ce_mode ,
1577
- oid_to_hex (& ce -> oid ), ce_stage (ce ),
1578
- needs_cloning , ce -> name );
1579
- string_list_append (& suc -> projectlines , sb .buf );
1644
+ ALLOC_GROW (suc -> update_clone , suc -> update_clone_nr + 1 ,
1645
+ suc -> update_clone_alloc );
1646
+ oidcpy (& suc -> update_clone [suc -> update_clone_nr ].oid , & ce -> oid );
1647
+ suc -> update_clone [suc -> update_clone_nr ].just_cloned = needs_cloning ;
1648
+ suc -> update_clone [suc -> update_clone_nr ].sub = sub ;
1649
+ suc -> update_clone_nr ++ ;
1580
1650
1581
1651
if (!needs_cloning )
1582
1652
goto cleanup ;
@@ -1717,11 +1787,44 @@ static int git_update_clone_config(const char *var, const char *value,
1717
1787
return 0 ;
1718
1788
}
1719
1789
1790
+ static void update_submodule (struct update_clone_data * ucd )
1791
+ {
1792
+ fprintf (stdout , "dummy %s %d\t%s\n" ,
1793
+ oid_to_hex (& ucd -> oid ),
1794
+ ucd -> just_cloned ,
1795
+ ucd -> sub -> path );
1796
+ }
1797
+
1798
+ static int update_submodules (struct submodule_update_clone * suc )
1799
+ {
1800
+ int i ;
1801
+
1802
+ run_processes_parallel (suc -> max_jobs ,
1803
+ update_clone_get_next_task ,
1804
+ update_clone_start_failure ,
1805
+ update_clone_task_finished ,
1806
+ suc );
1807
+
1808
+ /*
1809
+ * We saved the output and put it out all at once now.
1810
+ * That means:
1811
+ * - the listener does not have to interleave their (checkout)
1812
+ * work with our fetching. The writes involved in a
1813
+ * checkout involve more straightforward sequential I/O.
1814
+ * - the listener can avoid doing any work if fetching failed.
1815
+ */
1816
+ if (suc -> quickstop )
1817
+ return 1 ;
1818
+
1819
+ for (i = 0 ; i < suc -> update_clone_nr ; i ++ )
1820
+ update_submodule (& suc -> update_clone [i ]);
1821
+
1822
+ return 0 ;
1823
+ }
1824
+
1720
1825
static int update_clone (int argc , const char * * argv , const char * prefix )
1721
1826
{
1722
1827
const char * update = NULL ;
1723
- int max_jobs = 1 ;
1724
- struct string_list_item * item ;
1725
1828
struct pathspec pathspec ;
1726
1829
struct submodule_update_clone suc = SUBMODULE_UPDATE_CLONE_INIT ;
1727
1830
@@ -1743,7 +1846,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1743
1846
OPT_STRING (0 , "depth" , & suc .depth , "<depth>" ,
1744
1847
N_ ("Create a shallow clone truncated to the "
1745
1848
"specified number of revisions" )),
1746
- OPT_INTEGER ('j' , "jobs" , & max_jobs ,
1849
+ OPT_INTEGER ('j' , "jobs" , & suc . max_jobs ,
1747
1850
N_ ("parallel jobs" )),
1748
1851
OPT_BOOL (0 , "recommend-shallow" , & suc .recommend_shallow ,
1749
1852
N_ ("whether the initial clone should follow the shallow recommendation" )),
@@ -1759,8 +1862,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1759
1862
};
1760
1863
suc .prefix = prefix ;
1761
1864
1762
- update_clone_config_from_gitmodules (& max_jobs );
1763
- git_config (git_update_clone_config , & max_jobs );
1865
+ update_clone_config_from_gitmodules (& suc . max_jobs );
1866
+ git_config (git_update_clone_config , & suc . max_jobs );
1764
1867
1765
1868
argc = parse_options (argc , argv , prefix , module_update_clone_options ,
1766
1869
git_submodule_helper_usage , 0 );
@@ -1775,27 +1878,7 @@ static int update_clone(int argc, const char **argv, const char *prefix)
1775
1878
if (pathspec .nr )
1776
1879
suc .warn_if_uninitialized = 1 ;
1777
1880
1778
- run_processes_parallel (max_jobs ,
1779
- update_clone_get_next_task ,
1780
- update_clone_start_failure ,
1781
- update_clone_task_finished ,
1782
- & suc );
1783
-
1784
- /*
1785
- * We saved the output and put it out all at once now.
1786
- * That means:
1787
- * - the listener does not have to interleave their (checkout)
1788
- * work with our fetching. The writes involved in a
1789
- * checkout involve more straightforward sequential I/O.
1790
- * - the listener can avoid doing any work if fetching failed.
1791
- */
1792
- if (suc .quickstop )
1793
- return 1 ;
1794
-
1795
- for_each_string_list_item (item , & suc .projectlines )
1796
- fprintf (stdout , "%s" , item -> string );
1797
-
1798
- return 0 ;
1881
+ return update_submodules (& suc );
1799
1882
}
1800
1883
1801
1884
static int resolve_relative_path (int argc , const char * * argv , const char * prefix )
@@ -2041,6 +2124,7 @@ static struct cmd_struct commands[] = {
2041
2124
{"list" , module_list , 0 },
2042
2125
{"name" , module_name , 0 },
2043
2126
{"clone" , module_clone , 0 },
2127
+ {"update-module-mode" , module_update_module_mode , 0 },
2044
2128
{"update-clone" , update_clone , 0 },
2045
2129
{"connect-gitdir-workingtree" , connect_gitdir_workingtree , 0 },
2046
2130
{"relative-path" , resolve_relative_path , 0 },
0 commit comments