@@ -77,87 +77,78 @@ export class StashGitSubProvider implements GitStashSubProvider {
7777 ) : Promise < GitStash | undefined > {
7878 if ( repoPath == null ) return undefined ;
7979
80- let stashPromise = this . cache . stashes ?. get ( repoPath ) ;
81- if ( stashPromise == null ) {
82- async function load ( this : StashGitSubProvider ) : Promise < GitStash > {
83- const parser = getStashLogParser ( ) ;
84- const args = [ ...parser . arguments ] ;
85-
86- const similarityThreshold = configuration . get ( 'advanced.similarityThreshold' ) ;
87- args . push ( `-M${ similarityThreshold == null ? '' : `${ similarityThreshold } %` } ` ) ;
88-
89- const result = await this . git . exec (
90- { cwd : repoPath , cancellation : cancellation } ,
91- 'stash' ,
92- 'list' ,
93- ...args ,
94- ) ;
95-
96- const stashes = new Map < string , GitStashCommit > ( ) ;
97- const parentShas = new Set < string > ( ) ;
98-
99- // First pass: create stashes and collect parent SHAs
100- for ( const s of parser . parse ( result . stdout ) ) {
101- stashes . set ( s . sha , createStash ( this . container , s , repoPath ) ) ;
102- // Collect all parent SHAs for timestamp lookup
103- if ( s . parents ) {
104- for ( const parentSha of s . parents . split ( ' ' ) ) {
105- if ( parentSha . trim ( ) ) {
106- parentShas . add ( parentSha . trim ( ) ) ;
107- }
80+ const stashPromise = this . cache . stashes ?. getOrCreate ( repoPath , async _cancellable => {
81+ const parser = getStashLogParser ( ) ;
82+ const args = [ ...parser . arguments ] ;
83+
84+ const similarityThreshold = configuration . get ( 'advanced.similarityThreshold' ) ;
85+ args . push ( `-M${ similarityThreshold == null ? '' : `${ similarityThreshold } %` } ` ) ;
86+
87+ const result = await this . git . exec ( { cwd : repoPath , cancellation : cancellation } , 'stash' , 'list' , ...args ) ;
88+
89+ const stashes = new Map < string , GitStashCommit > ( ) ;
90+ const parentShas = new Set < string > ( ) ;
91+
92+ // First pass: create stashes and collect parent SHAs
93+ for ( const s of parser . parse ( result . stdout ) ) {
94+ stashes . set ( s . sha , createStash ( this . container , s , repoPath ) ) ;
95+ // Collect all parent SHAs for timestamp lookup
96+ if ( s . parents ) {
97+ for ( const parentSha of s . parents . split ( ' ' ) ) {
98+ if ( parentSha . trim ( ) ) {
99+ parentShas . add ( parentSha . trim ( ) ) ;
108100 }
109101 }
110102 }
103+ }
111104
112- // Second pass: fetch parent timestamps if we have any parents
113- const parentTimestamps = new Map < string , { authorDate : number ; committerDate : number } > ( ) ;
114- if ( parentShas . size > 0 ) {
115- try {
116- const datesParser = getShaAndDatesLogParser ( ) ;
117- const parentResult = await this . git . exec (
118- {
119- cwd : repoPath ,
120- cancellation : cancellation ,
121- stdin : Array . from ( parentShas ) . join ( '\n' ) ,
122- } ,
123- 'log' ,
124- ...datesParser . arguments ,
125- '--no-walk' ,
126- '--stdin' ,
127- ) ;
128-
129- for ( const entry of datesParser . parse ( parentResult . stdout ) ) {
130- parentTimestamps . set ( entry . sha , {
131- authorDate : Number ( entry . authorDate ) ,
132- committerDate : Number ( entry . committerDate ) ,
133- } ) ;
134- }
135- } catch ( _ex ) {
136- // If we can't get parent timestamps, continue without them
137- // This could happen if some parent commits are not available
105+ // Second pass: fetch parent timestamps if we have any parents
106+ const parentTimestamps = new Map < string , { authorDate : number ; committerDate : number } > ( ) ;
107+ if ( parentShas . size > 0 ) {
108+ try {
109+ const datesParser = getShaAndDatesLogParser ( ) ;
110+ const parentResult = await this . git . exec (
111+ {
112+ cwd : repoPath ,
113+ cancellation : cancellation ,
114+ stdin : Array . from ( parentShas ) . join ( '\n' ) ,
115+ } ,
116+ 'log' ,
117+ ...datesParser . arguments ,
118+ '--no-walk' ,
119+ '--stdin' ,
120+ ) ;
121+
122+ for ( const entry of datesParser . parse ( parentResult . stdout ) ) {
123+ parentTimestamps . set ( entry . sha , {
124+ authorDate : Number ( entry . authorDate ) ,
125+ committerDate : Number ( entry . committerDate ) ,
126+ } ) ;
138127 }
128+ } catch ( _ex ) {
129+ // If we can't get parent timestamps, continue without them
130+ // This could happen if some parent commits are not available
139131 }
132+ }
140133
141- // Third pass: update stashes with parent timestamp information
142- for ( const sha of stashes . keys ( ) ) {
143- const stash = stashes . get ( sha ) ;
144- if ( stash ?. parents . length ) {
145- const parentsWithTimestamps : GitStashParentInfo [ ] = stash . parents . map ( parentSha => ( {
146- sha : parentSha ,
147- authorDate : parentTimestamps . get ( parentSha ) ?. authorDate ,
148- committerDate : parentTimestamps . get ( parentSha ) ?. committerDate ,
149- } ) ) ;
150- // Store the parent timestamp information on the stash
151- stashes . set ( sha , stash . with ( { parentTimestamps : parentsWithTimestamps } ) ) ;
152- }
134+ // Third pass: update stashes with parent timestamp information
135+ for ( const sha of stashes . keys ( ) ) {
136+ const stash = stashes . get ( sha ) ;
137+ if ( stash ?. parents . length ) {
138+ const parentsWithTimestamps : GitStashParentInfo [ ] = stash . parents . map ( parentSha => ( {
139+ sha : parentSha ,
140+ authorDate : parentTimestamps . get ( parentSha ) ?. authorDate ,
141+ committerDate : parentTimestamps . get ( parentSha ) ?. committerDate ,
142+ } ) ) ;
143+ // Store the parent timestamp information on the stash
144+ stashes . set ( sha , stash . with ( { parentTimestamps : parentsWithTimestamps } ) ) ;
153145 }
154-
155- return { repoPath : repoPath , stashes : stashes } ;
156146 }
157147
158- stashPromise = load . call ( this ) ;
159- this . cache . stashes ?. set ( repoPath , stashPromise ) ;
160- }
148+ return { repoPath : repoPath , stashes : stashes } ;
149+ } ) ;
150+
151+ if ( stashPromise == null ) return undefined ;
161152
162153 const stash = await stashPromise ;
163154 if ( ! options ?. reachableFrom || ! stash ?. stashes . size ) return stash ;
0 commit comments