@@ -111,40 +111,38 @@ export class StashGitSubProvider implements GitStashSubProvider {
111
111
) ;
112
112
113
113
const ancestors = result . stdout . trim ( ) . split ( '\n' ) ;
114
- if ( ancestors ?. length && ( ancestors . length !== 1 || ancestors [ 0 ] ) ) {
115
- const reachableCommits = new Set ( ancestors ) ;
116
-
117
- if ( reachableCommits . size ) {
118
- const reachableStashes = new Set < string > ( ) ;
114
+ const reachableCommits =
115
+ ancestors ?. length && ( ancestors . length !== 1 || ancestors [ 0 ] ) ? new Set ( ancestors ) : undefined ;
116
+ if ( reachableCommits ?. size ) {
117
+ const reachableStashes = new Set < string > ( ) ;
118
+
119
+ // First pass: mark directly reachable stashes
120
+ for ( const [ sha , s ] of stash . stashes ) {
121
+ if ( s . parents . some ( p => p === options . reachableFrom || reachableCommits . has ( p ) ) ) {
122
+ reachableStashes . add ( sha ) ;
123
+ }
124
+ }
119
125
120
- // First pass: mark directly reachable stashes
126
+ // Second pass: mark stashes that build upon reachable stashes
127
+ let changed ;
128
+ do {
129
+ changed = false ;
121
130
for ( const [ sha , s ] of stash . stashes ) {
122
- if ( s . parents . some ( p => p === options . reachableFrom || reachableCommits . has ( p ) ) ) {
131
+ if ( ! reachableStashes . has ( sha ) && s . parents . some ( p => reachableStashes . has ( p ) ) ) {
123
132
reachableStashes . add ( sha ) ;
133
+ changed = true ;
124
134
}
125
135
}
136
+ } while ( changed ) ;
126
137
127
- // Second pass: mark stashes that build upon reachable stashes
128
- let changed ;
129
- do {
130
- changed = false ;
131
- for ( const [ sha , s ] of stash . stashes ) {
132
- if ( ! reachableStashes . has ( sha ) && s . parents . some ( p => reachableStashes . has ( p ) ) ) {
133
- reachableStashes . add ( sha ) ;
134
- changed = true ;
135
- }
136
- }
137
- } while ( changed ) ;
138
-
139
- // Remove unreachable stashes
140
- for ( const [ sha ] of stash . stashes ) {
141
- if ( ! reachableStashes . has ( sha ) ) {
142
- stash . stashes . delete ( sha ) ;
143
- }
138
+ // Remove unreachable stashes
139
+ for ( const [ sha ] of stash . stashes ) {
140
+ if ( ! reachableStashes . has ( sha ) ) {
141
+ stash . stashes . delete ( sha ) ;
144
142
}
145
- } else {
146
- stash . stashes . clear ( ) ;
147
143
}
144
+ } else {
145
+ stash . stashes . clear ( ) ;
148
146
}
149
147
}
150
148
0 commit comments