@@ -188,17 +188,7 @@ impl SourceId {
188188 match kind {
189189 "git" => {
190190 let mut url = url. into_url ( ) ?;
191- let mut reference = GitReference :: DefaultBranch ;
192- for ( k, v) in url. query_pairs ( ) {
193- match & k[ ..] {
194- // Map older 'ref' to branch.
195- "branch" | "ref" => reference = GitReference :: Branch ( v. into_owned ( ) ) ,
196-
197- "rev" => reference = GitReference :: Rev ( v. into_owned ( ) ) ,
198- "tag" => reference = GitReference :: Tag ( v. into_owned ( ) ) ,
199- _ => { }
200- }
201- }
191+ let reference = GitReference :: from_query ( url. query_pairs ( ) ) ;
202192 let precise = url. fragment ( ) . map ( |s| s. to_owned ( ) ) ;
203193 url. set_fragment ( None ) ;
204194 url. set_query ( None ) ;
@@ -884,6 +874,24 @@ impl<'a> fmt::Display for SourceIdAsUrl<'a> {
884874}
885875
886876impl GitReference {
877+ pub fn from_query (
878+ query_pairs : impl Iterator < Item = ( impl AsRef < str > , impl AsRef < str > ) > ,
879+ ) -> Self {
880+ let mut reference = GitReference :: DefaultBranch ;
881+ for ( k, v) in query_pairs {
882+ let v = v. as_ref ( ) ;
883+ match k. as_ref ( ) {
884+ // Map older 'ref' to branch.
885+ "branch" | "ref" => reference = GitReference :: Branch ( v. to_owned ( ) ) ,
886+
887+ "rev" => reference = GitReference :: Rev ( v. to_owned ( ) ) ,
888+ "tag" => reference = GitReference :: Tag ( v. to_owned ( ) ) ,
889+ _ => { }
890+ }
891+ }
892+ reference
893+ }
894+
887895 /// Returns a `Display`able view of this git reference, or None if using
888896 /// the head of the default branch
889897 pub fn pretty_ref ( & self , url_encoded : bool ) -> Option < PrettyRef < ' _ > > {
0 commit comments