@@ -83,40 +83,54 @@ export class Repository {
8383 async getBranches ( ) {
8484 const repoUrl = await this . getRepoUrl ( ) ;
8585
86- const branches = [ ] ;
86+ let branches : string [ ] = [ ] ;
8787
88- let trunkExists = await this . svn . exec ( "" , [
89- "ls" ,
90- repoUrl + "/trunk" ,
91- "--depth" ,
92- "empty"
93- ] ) ;
88+ let promises = [ ] ;
9489
95- if ( trunkExists . exitCode === 0 ) {
96- branches . push ( "trunk" ) ;
97- }
90+ promises . push ( new Promise < string [ ] > ( async resolve => {
91+ let trunkExists = await this . svn . exec ( "" , [
92+ "ls" ,
93+ repoUrl + "/trunk" ,
94+ "--depth" ,
95+ "empty"
96+ ] ) ;
97+
98+ if ( trunkExists . exitCode === 0 ) {
99+ resolve ( [ "trunk" ] ) ;
100+ return ;
101+ }
102+ resolve ( [ ] ) ;
103+ } ) ) ;
98104
99105 const trees = [ "branches" , "tags" ] ;
100106
101107 for ( let index in trees ) {
102- const tree = trees [ index ] ;
103- const branchUrl = repoUrl + "/" + tree ;
108+ promises . push ( new Promise < string [ ] > ( async resolve => {
109+ const tree = trees [ index ] ;
110+ const branchUrl = repoUrl + "/" + tree ;
104111
105- const result = await this . svn . list ( branchUrl ) ;
112+ const result = await this . svn . list ( branchUrl ) ;
106113
107- if ( result . exitCode !== 0 ) {
108- continue ;
109- }
114+ if ( result . exitCode !== 0 ) {
115+ resolve ( [ ] ) ;
116+ return ;
117+ }
110118
111- const list = result . stdout
112- . trim ( )
113- . replace ( / \/ | \\ / g, "" )
114- . split ( / [ \r \n ] + / )
115- . map ( ( i : string ) => tree + "/" + i ) ;
119+ const list = result . stdout
120+ . trim ( )
121+ . replace ( / \/ | \\ / g, "" )
122+ . split ( / [ \r \n ] + / )
123+ . map ( ( i : string ) => tree + "/" + i ) ;
116124
117- branches . push ( ...list ) ;
125+ resolve ( list ) ;
126+ } ) ) ;
118127 }
119128
129+ const all = await Promise . all < any > ( promises ) ;
130+ all . forEach ( list => {
131+ branches . push ( ...list ) ;
132+ } ) ;
133+
120134 return branches ;
121135 }
122136
0 commit comments