@@ -16,3 +16,54 @@ impl Default for Mode {
16
16
pub fn run ( _mode : Mode , _source_dir : PathBuf , _destination : PathBuf , _progress : impl Progress ) -> anyhow:: Result < ( ) > {
17
17
Ok ( ( ) )
18
18
}
19
+
20
+ mod parse {
21
+ use anyhow:: { bail, Context } ;
22
+ use bstr:: { BStr , ByteSlice } ;
23
+
24
+ fn verbose_remotes ( input : & [ u8 ] ) -> anyhow:: Result < Vec < ( & BStr , git_url:: Url ) > > {
25
+ fn parse_line ( line : & BStr ) -> anyhow:: Result < ( & BStr , git_url:: Url ) > {
26
+ let mut tokens = line. splitn ( 2 , |b| * b == b'\t' ) ;
27
+ Ok ( match ( tokens. next ( ) , tokens. next ( ) , tokens. next ( ) ) {
28
+ ( Some ( remote) , Some ( url_and_type) , None ) => {
29
+ let mut tokens = url_and_type. splitn ( 2 , |b| * b == b' ' ) ;
30
+ match ( tokens. next ( ) , tokens. next ( ) , tokens. next ( ) ) {
31
+ ( Some ( url) , Some ( _type) , None ) => ( remote. as_bstr ( ) , git_url:: parse ( url) ?) ,
32
+ _ => bail ! ( "None or more than one 'space' as separator" ) ,
33
+ }
34
+ }
35
+ _ => bail ! ( "None or more than one tab as separator" ) ,
36
+ } )
37
+ }
38
+
39
+ let mut out = Vec :: new ( ) ;
40
+ for line in input. split ( |b| * b == b'\n' ) {
41
+ let line = line. as_bstr ( ) ;
42
+ if line. trim ( ) . len ( ) == 0 {
43
+ continue ;
44
+ }
45
+ out. push (
46
+ parse_line ( line) . with_context ( || format ! ( "Line {:?} should be <origin>TAB<URL>SPACE<TYPE>" , line) ) ?,
47
+ ) ;
48
+ }
49
+
50
+ Ok ( out)
51
+ }
52
+
53
+ #[ cfg( test) ]
54
+ mod tests {
55
+ use super :: * ;
56
+ static GITOXIDE_REMOTES : & [ u8 ] = br#"commitgraph https://github.com/avoidscorn/gitoxide (fetch)
57
+ commitgraph https://github.com/avoidscorn/gitoxide (push)
58
+ origin https://github.com/Byron/gitoxide (fetch)
59
+ origin https://github.com/Byron/gitoxide (push)
60
+ rad rad://hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81@hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git (fetch)
61
+ rad rad://hynkuwzskprmswzeo4qdtku7grdrs4ffj3g9tjdxomgmjzhtzpqf81@hwd1yregyf1dudqwkx85x5ps3qsrqw3ihxpx3ieopq6ukuuq597p6m8161c.git (push)
62
+ "# ;
63
+ #[ test]
64
+ fn valid_verbose_remotes ( ) -> anyhow:: Result < ( ) > {
65
+ assert_eq ! ( verbose_remotes( GITOXIDE_REMOTES ) ?, vec![ ] ) ;
66
+ Ok ( ( ) )
67
+ }
68
+ }
69
+ }
0 commit comments