@@ -13,11 +13,33 @@ interface StashEntry {
1313
1414export class GitStashParser {
1515
16+ static parse ( data : string , repoPath : string ) : GitStash | undefined {
17+ const entries = this . _parseEntries ( data ) ;
18+ if ( entries === undefined ) return undefined ;
19+
20+ const commits : Map < string , GitStashCommit > = new Map ( ) ;
21+
22+ for ( let i = 0 , len = entries . length ; i < len ; i ++ ) {
23+ const entry = entries [ i ] ;
24+
25+ let commit = commits . get ( entry . sha ) ;
26+ if ( commit === undefined ) {
27+ commit = new GitStashCommit ( entry . stashName , repoPath , entry . sha , entry . fileNames , new Date ( entry . date ! as any * 1000 ) , entry . summary , undefined , entry . fileStatuses ) as GitStashCommit ;
28+ commits . set ( entry . sha , commit ) ;
29+ }
30+ }
31+
32+ return {
33+ repoPath : repoPath ,
34+ commits : commits
35+ } as GitStash ;
36+ }
37+
1638 private static _parseEntries ( data : string ) : StashEntry [ ] | undefined {
1739 if ( ! data ) return undefined ;
1840
1941 const lines = data . split ( '\n' ) ;
20- if ( ! lines . length ) return undefined ;
42+ if ( lines . length === 0 ) return undefined ;
2143
2244 const entries : StashEntry [ ] = [ ] ;
2345
@@ -65,7 +87,12 @@ export class GitStashParser {
6587 case 'filename' :
6688 const nextLine = lines [ position + 1 ] ;
6789 // If the next line isn't blank, make sure it isn't starting a new commit
68- if ( nextLine && Git . shaRegex . test ( nextLine ) ) continue ;
90+ if ( nextLine && Git . shaRegex . test ( nextLine ) ) {
91+ entries . push ( entry ) ;
92+ entry = undefined ;
93+
94+ continue ;
95+ }
6996
7097 position ++ ;
7198
@@ -108,28 +135,6 @@ export class GitStashParser {
108135 return entries ;
109136 }
110137
111- static parse ( data : string , repoPath : string ) : GitStash | undefined {
112- const entries = this . _parseEntries ( data ) ;
113- if ( entries === undefined ) return undefined ;
114-
115- const commits : Map < string , GitStashCommit > = new Map ( ) ;
116-
117- for ( let i = 0 , len = entries . length ; i < len ; i ++ ) {
118- const entry = entries [ i ] ;
119-
120- let commit = commits . get ( entry . sha ) ;
121- if ( commit === undefined ) {
122- commit = new GitStashCommit ( entry . stashName , repoPath , entry . sha , entry . fileNames , new Date ( entry . date ! as any * 1000 ) , entry . summary , undefined , entry . fileStatuses ) as GitStashCommit ;
123- commits . set ( entry . sha , commit ) ;
124- }
125- }
126-
127- return {
128- repoPath : repoPath ,
129- commits : commits
130- } as GitStash ;
131- }
132-
133138 private static _parseFileName ( entry : { fileName ?: string , originalFileName ?: string } ) {
134139 if ( entry . fileName === undefined ) return ;
135140
0 commit comments