@@ -80,6 +80,7 @@ static struct list_objects_filter_options filter_options;
80
80
static struct string_list server_options = STRING_LIST_INIT_DUP ;
81
81
static struct string_list negotiation_tip = STRING_LIST_INIT_NODUP ;
82
82
static int fetch_write_commit_graph = -1 ;
83
+ static int stdin_refspecs = 0 ;
83
84
84
85
static int git_fetch_config (const char * k , const char * v , void * cb )
85
86
{
@@ -205,6 +206,8 @@ static struct option builtin_fetch_options[] = {
205
206
N_ ("check for forced-updates on all updated branches" )),
206
207
OPT_BOOL (0 , "write-commit-graph" , & fetch_write_commit_graph ,
207
208
N_ ("write the commit-graph after fetching" )),
209
+ OPT_BOOL (0 , "stdin" , & stdin_refspecs ,
210
+ N_ ("accept refspecs from stdin" )),
208
211
OPT_END ()
209
212
};
210
213
@@ -442,6 +445,7 @@ static struct ref *get_ref_map(struct remote *remote,
442
445
struct ref * orefs = NULL , * * oref_tail = & orefs ;
443
446
444
447
struct hashmap existing_refs ;
448
+ int existing_refs_populated = 0 ;
445
449
446
450
if (rs -> nr ) {
447
451
struct refspec * fetch_refspec ;
@@ -535,15 +539,18 @@ static struct ref *get_ref_map(struct remote *remote,
535
539
536
540
ref_map = ref_remove_duplicates (ref_map );
537
541
538
- refname_hash_init (& existing_refs );
539
- for_each_ref (add_one_refname , & existing_refs );
540
-
541
542
for (rm = ref_map ; rm ; rm = rm -> next ) {
542
543
if (rm -> peer_ref ) {
543
544
const char * refname = rm -> peer_ref -> name ;
544
545
struct refname_hash_entry * peer_item ;
545
546
unsigned int hash = strhash (refname );
546
547
548
+ if (!existing_refs_populated ) {
549
+ refname_hash_init (& existing_refs );
550
+ for_each_ref (add_one_refname , & existing_refs );
551
+ existing_refs_populated = 1 ;
552
+ }
553
+
547
554
peer_item = hashmap_get_entry_from_hash (& existing_refs ,
548
555
hash , refname ,
549
556
struct refname_hash_entry , ent );
@@ -553,7 +560,8 @@ static struct ref *get_ref_map(struct remote *remote,
553
560
}
554
561
}
555
562
}
556
- hashmap_free_entries (& existing_refs , struct refname_hash_entry , ent );
563
+ if (existing_refs_populated )
564
+ hashmap_free_entries (& existing_refs , struct refname_hash_entry , ent );
557
565
558
566
return ref_map ;
559
567
}
@@ -1015,11 +1023,17 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
1015
1023
rc |= update_local_ref (ref , what , rm , & note ,
1016
1024
summary_width );
1017
1025
free (ref );
1018
- } else
1026
+ } else if (write_fetch_head || dry_run ) {
1027
+ /*
1028
+ * Display fetches written to FETCH_HEAD (or
1029
+ * would be written to FETCH_HEAD, if --dry-run
1030
+ * is set).
1031
+ */
1019
1032
format_display (& note , '*' ,
1020
1033
* kind ? kind : "branch" , NULL ,
1021
1034
* what ? what : "HEAD" ,
1022
1035
"FETCH_HEAD" , summary_width );
1036
+ }
1023
1037
if (note .len ) {
1024
1038
if (verbosity >= 0 && !shown_url ) {
1025
1039
fprintf (stderr , _ ("From %.*s\n" ),
@@ -1680,7 +1694,8 @@ static inline void fetch_one_setup_partial(struct remote *remote)
1680
1694
return ;
1681
1695
}
1682
1696
1683
- static int fetch_one (struct remote * remote , int argc , const char * * argv , int prune_tags_ok )
1697
+ static int fetch_one (struct remote * remote , int argc , const char * * argv ,
1698
+ int prune_tags_ok , int use_stdin_refspecs )
1684
1699
{
1685
1700
struct refspec rs = REFSPEC_INIT_FETCH ;
1686
1701
int i ;
@@ -1737,6 +1752,13 @@ static int fetch_one(struct remote *remote, int argc, const char **argv, int pru
1737
1752
}
1738
1753
}
1739
1754
1755
+ if (use_stdin_refspecs ) {
1756
+ struct strbuf line = STRBUF_INIT ;
1757
+ while (strbuf_getline_lf (& line , stdin ) != EOF )
1758
+ refspec_append (& rs , line .buf );
1759
+ strbuf_release (& line );
1760
+ }
1761
+
1740
1762
if (server_options .nr )
1741
1763
gtransport -> server_options = & server_options ;
1742
1764
@@ -1771,12 +1793,18 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1771
1793
free (anon );
1772
1794
}
1773
1795
1774
- fetch_config_from_gitmodules (& submodule_fetch_jobs_config ,
1775
- & recurse_submodules );
1776
1796
git_config (git_fetch_config , NULL );
1777
1797
1778
1798
argc = parse_options (argc , argv , prefix ,
1779
1799
builtin_fetch_options , builtin_fetch_usage , 0 );
1800
+ if (recurse_submodules != RECURSE_SUBMODULES_OFF ) {
1801
+ int * sfjc = submodule_fetch_jobs_config == -1
1802
+ ? & submodule_fetch_jobs_config : NULL ;
1803
+ int * rs = recurse_submodules == RECURSE_SUBMODULES_DEFAULT
1804
+ ? & recurse_submodules : NULL ;
1805
+
1806
+ fetch_config_from_gitmodules (sfjc , rs );
1807
+ }
1780
1808
1781
1809
if (deepen_relative ) {
1782
1810
if (deepen_relative < 0 )
@@ -1837,14 +1865,18 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1837
1865
if (remote ) {
1838
1866
if (filter_options .choice || has_promisor_remote ())
1839
1867
fetch_one_setup_partial (remote );
1840
- result = fetch_one (remote , argc , argv , prune_tags_ok );
1868
+ result = fetch_one (remote , argc , argv , prune_tags_ok , stdin_refspecs );
1841
1869
} else {
1842
1870
int max_children = max_jobs ;
1843
1871
1844
1872
if (filter_options .choice )
1845
1873
die (_ ("--filter can only be used with the remote "
1846
1874
"configured in extensions.partialclone" ));
1847
1875
1876
+ if (stdin_refspecs )
1877
+ die (_ ("--stdin can only be used when fetching "
1878
+ "from one remote" ));
1879
+
1848
1880
if (max_children < 0 )
1849
1881
max_children = fetch_parallel_config ;
1850
1882
0 commit comments