@@ -135,16 +135,25 @@ impl crate::Repository {
135
135
mod transport;
136
136
137
137
mod remote {
138
+ use crate :: bstr:: BStr ;
138
139
use std:: { borrow:: Cow , collections:: BTreeSet } ;
139
140
140
- use crate :: { bstr :: ByteSlice , remote} ;
141
+ use crate :: remote;
141
142
142
143
impl crate :: Repository {
143
144
/// Returns a sorted list unique of symbolic names of remotes that
144
145
/// we deem [trustworthy][crate::open::Options::filter_config_section()].
145
- // TODO: Use `remote::Name` here
146
- pub fn remote_names ( & self ) -> BTreeSet < & str > {
147
- self . subsection_names_of ( "remote" )
146
+ pub fn remote_names ( & self ) -> BTreeSet < Cow < ' _ , BStr > > {
147
+ self . config
148
+ . resolved
149
+ . sections_by_name ( "remote" )
150
+ . map ( |it| {
151
+ let filter = self . filter_config_section ( ) ;
152
+ it. filter ( move |s| filter ( s. meta ( ) ) )
153
+ . filter_map ( |section| section. header ( ) . subsection_name ( ) . map ( Cow :: Borrowed ) )
154
+ . collect ( )
155
+ } )
156
+ . unwrap_or_default ( )
148
157
}
149
158
150
159
/// Obtain the branch-independent name for a remote for use in the given `direction`, or `None` if it could not be determined.
@@ -155,25 +164,23 @@ mod remote {
155
164
/// # Notes
156
165
///
157
166
/// It's up to the caller to determine what to do if the current `head` is unborn or detached.
158
- // TODO: use remote::Name here
159
- pub fn remote_default_name ( & self , direction : remote:: Direction ) -> Option < Cow < ' _ , str > > {
167
+ pub fn remote_default_name ( & self , direction : remote:: Direction ) -> Option < Cow < ' _ , BStr > > {
160
168
let name = ( direction == remote:: Direction :: Push )
161
169
. then ( || {
162
170
self . config
163
171
. resolved
164
172
. string_filter ( "remote" , None , "pushDefault" , & mut self . filter_config_section ( ) )
165
- . and_then ( |s| match s {
166
- Cow :: Borrowed ( s) => s. to_str ( ) . ok ( ) . map ( Cow :: Borrowed ) ,
167
- Cow :: Owned ( s) => s. to_str ( ) . ok ( ) . map ( |s| Cow :: Owned ( s. into ( ) ) ) ,
168
- } )
169
173
} )
170
174
. flatten ( ) ;
171
175
name. or_else ( || {
172
176
let names = self . remote_names ( ) ;
173
177
match names. len ( ) {
174
178
0 => None ,
175
- 1 => names. iter ( ) . next ( ) . copied ( ) . map ( Cow :: Borrowed ) ,
176
- _more_than_one => names. get ( "origin" ) . copied ( ) . map ( Cow :: Borrowed ) ,
179
+ 1 => names. into_iter ( ) . next ( ) ,
180
+ _more_than_one => {
181
+ let origin = Cow :: Borrowed ( "origin" . into ( ) ) ;
182
+ names. contains ( & origin) . then_some ( origin)
183
+ }
177
184
}
178
185
} )
179
186
}
@@ -191,8 +198,12 @@ mod branch {
191
198
impl crate :: Repository {
192
199
/// Return a set of unique short branch names for which custom configuration exists in the configuration,
193
200
/// if we deem them [trustworthy][crate::open::Options::filter_config_section()].
201
+ ///
202
+ /// ### Note
203
+ ///
204
+ /// Branch names that have illformed UTF-8 will silently be skipped.
194
205
pub fn branch_names ( & self ) -> BTreeSet < & str > {
195
- self . subsection_names_of ( "branch" )
206
+ self . subsection_str_names_of ( "branch" )
196
207
}
197
208
198
209
/// Returns the validated reference on the remote associated with the given `short_branch_name`,
@@ -237,7 +248,7 @@ impl crate::Repository {
237
248
. unwrap_or ( config:: section:: is_trusted)
238
249
}
239
250
240
- fn subsection_names_of < ' a > ( & ' a self , header_name : & ' a str ) -> BTreeSet < & ' a str > {
251
+ fn subsection_str_names_of < ' a > ( & ' a self , header_name : & ' a str ) -> BTreeSet < & ' a str > {
241
252
self . config
242
253
. resolved
243
254
. sections_by_name ( header_name)
0 commit comments