@@ -153,29 +153,38 @@ impl<'event> GitConfig<'event> {
153
153
. iter ( )
154
154
. map ( |p| PathBuf :: from ( p. to_str ( ) . expect ( "invalid utf-8 path" ) ) )
155
155
. collect ( ) ;
156
+ const MAX_DEPTH : u8 = 10 ;
156
157
157
158
fn from_paths_req (
158
159
paths : Vec < PathBuf > ,
159
160
seen : & mut HashSet < PathBuf > ,
160
161
config : & mut GitConfig ,
162
+ depth : u8 ,
161
163
) -> Result < ( ) , ParserOrIoError < ' static > > {
164
+ if depth >= MAX_DEPTH {
165
+ return Ok ( ( ) ) ;
166
+ }
162
167
for path in paths. iter ( ) {
163
168
let other = GitConfig :: open ( path) ?;
164
- for ( section_id, section_header) in other. section_headers {
169
+ let mut section_ids: Vec < _ > = other. section_headers . keys ( ) . collect ( ) ;
170
+ section_ids. sort ( ) ;
171
+ for section_id in section_ids {
172
+ let section_header = & other. section_headers [ & section_id] ;
165
173
if section_header. name . 0 == "include" {
166
174
let path_values = other. sections [ & section_id] . values ( & Key :: from ( "path" ) ) ;
167
175
let mut paths = vec ! [ ] ;
168
- // TODO handle relative and interpolated path
169
- for path in path_values {
170
- let path = PathBuf :: from (
171
- std:: string:: String :: from_utf8 ( path. to_vec ( ) ) . expect ( "invalid utf-8 path" ) ,
172
- ) ;
173
- if !seen. contains ( & path) {
174
- seen. insert ( path. clone ( ) ) ;
175
- paths. push ( path. clone ( ) ) ;
176
+ for path_value in path_values {
177
+ let interpolated_path = crate :: values:: Path :: from ( path_value) . interpolate ( None ) . unwrap ( ) ;
178
+ let path = if interpolated_path. is_relative ( ) {
179
+ path. parent ( ) . unwrap ( ) . join ( interpolated_path)
180
+ } else {
181
+ interpolated_path. into ( )
182
+ } ;
183
+ if seen. insert ( path. clone ( ) ) {
184
+ paths. push ( path) ;
176
185
}
177
186
}
178
- from_paths_req ( paths, seen, config) ?;
187
+ from_paths_req ( paths, seen, config, depth + 1 ) ?;
179
188
} else {
180
189
config. push_section (
181
190
section_header. name . 0 . to_owned ( ) ,
@@ -188,7 +197,7 @@ impl<'event> GitConfig<'event> {
188
197
Ok ( ( ) )
189
198
}
190
199
191
- from_paths_req ( paths, & mut seen, & mut config) ?;
200
+ from_paths_req ( paths, & mut seen, & mut config, 0 ) ?;
192
201
193
202
Ok ( config)
194
203
}
@@ -1714,11 +1723,14 @@ mod from_paths {
1714
1723
r"
1715
1724
[core]
1716
1725
a = false
1726
+ sslVerify = true
1727
+ d = 41
1717
1728
" ,
1718
1729
)
1719
1730
. expect ( "Unable to write config file" ) ;
1720
1731
1721
1732
let b_path = dir. path ( ) . join ( "b" ) ;
1733
+ let relative_b_path = std:: path:: PathBuf :: from ( "b" ) ;
1722
1734
fs:: write (
1723
1735
b_path. as_path ( ) ,
1724
1736
r"
@@ -1735,12 +1747,15 @@ mod from_paths {
1735
1747
r"
1736
1748
[core]
1737
1749
c = 12
1750
+ d = 42
1738
1751
[include]
1739
1752
path = {}
1740
1753
path = {}
1754
+ [http]
1755
+ sslVerify = false
1741
1756
" ,
1742
1757
a_path. as_path( ) . to_str( ) . unwrap( ) ,
1743
- b_path . as_path( ) . to_str( ) . unwrap( )
1758
+ relative_b_path . as_path( ) . to_str( ) . unwrap( )
1744
1759
) ,
1745
1760
)
1746
1761
. expect ( "Unable to write config file" ) ;
@@ -1751,6 +1766,14 @@ mod from_paths {
1751
1766
config. get_raw_value( "core" , None , "c" ) ,
1752
1767
Ok ( Cow :: <[ u8 ] >:: Borrowed ( b"12" ) )
1753
1768
) ;
1769
+ assert_eq ! (
1770
+ config. get_raw_value( "core" , None , "d" ) ,
1771
+ Ok ( Cow :: <[ u8 ] >:: Borrowed ( b"41" ) )
1772
+ ) ;
1773
+ assert_eq ! (
1774
+ config. get_raw_value( "http" , None , "sslVerify" ) ,
1775
+ Ok ( Cow :: <[ u8 ] >:: Borrowed ( b"false" ) )
1776
+ ) ;
1754
1777
1755
1778
assert_eq ! (
1756
1779
config. get_raw_value( "diff" , None , "renames" ) ,
@@ -1770,11 +1793,11 @@ mod from_paths {
1770
1793
let a_path = dir. path ( ) . join ( "a" ) ;
1771
1794
fs:: write (
1772
1795
a_path. as_path ( ) ,
1773
- r"
1796
+ r# "
1774
1797
[core]
1775
1798
a = false
1776
1799
c = 1
1777
- " ,
1800
+ "# ,
1778
1801
)
1779
1802
. expect ( "Unable to write config file" ) ;
1780
1803
0 commit comments