@@ -84,15 +84,19 @@ public Models.Stash SelectedStash
8484 changes . Sort ( ( l , r ) => Models . NumericSort . Compare ( l . Path , r . Path ) ) ;
8585 }
8686
87+ Dictionary < string , string > decodedPaths = null ;
88+ if ( _repo . Settings . EnableUnrealEngineSupport && _repo . Settings . EnableOFPADecoding )
89+ decodedPaths = await CalculateDecodedPathsAsync ( value , changes , untracked ) . ConfigureAwait ( false ) ;
90+
8791 Dispatcher . UIThread . Post ( ( ) =>
8892 {
8993 if ( value . SHA . Equals ( _selectedStash ? . SHA ?? string . Empty , StringComparison . Ordinal ) )
9094 {
95+ _decodedPaths = decodedPaths ;
96+ OnPropertyChanged ( nameof ( DecodedPaths ) ) ;
97+
9198 _untracked = untracked ;
9299 Changes = changes ;
93-
94- if ( _repo . Settings . EnableUnrealEngineSupport && _repo . Settings . EnableOFPADecoding )
95- _currentDecodeTask = DecodeOFPAPathsAsync ( value , changes , untracked ) ;
96100 }
97101 } ) ;
98102 } ) ;
@@ -306,70 +310,70 @@ private async Task DecodeOFPAPathsAsync(Models.Stash stash, List<Models.Change>
306310 changes == null || changes . Count == 0 )
307311 return ;
308312
309- var repositoryPath = _repo . FullPath ;
310- var untrackedSet = new HashSet < Models . Change > ( untracked ) ;
311- var results = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
312-
313- await Task . Run ( async ( ) =>
313+ _currentDecodeTask = Task . Run ( async ( ) =>
314314 {
315- var filesToDecode = new List < ( string RelativePath , string Spec ) > ( ) ;
316- foreach ( var change in changes )
315+ var results = await CalculateDecodedPathsAsync ( stash , changes , untracked ) . ConfigureAwait ( false ) ;
316+ if ( results != null )
317317 {
318- if ( ! Utilities . OFPAParser . IsOFPAFile ( change . Path ) )
319- continue ;
320-
321- string spec ;
322- if ( untrackedSet . Contains ( change ) && stash . Parents . Count == 3 )
318+ await Dispatcher . UIThread . InvokeAsync ( ( ) =>
323319 {
324- // Untracked files are in the 3rd parent commit.
325- spec = $ "{ stash . Parents [ 2 ] } :{ change . Path } ";
326- }
327- else
328- {
329- // Standard stash changes (index + worktree).
330- // Deleted files need to be looked up in the parent.
331- if ( change . WorkTree == Models . ChangeState . Deleted || change . Index == Models . ChangeState . Deleted )
332- spec = $ "{ stash . Parents [ 0 ] } :{ change . Path } ";
333- else
334- spec = $ "{ stash . SHA } :{ change . Path } ";
335- }
336-
337- filesToDecode . Add ( ( change . Path , spec ) ) ;
320+ _decodedPaths = results ;
321+ OnPropertyChanged ( nameof ( DecodedPaths ) ) ;
322+ } ) ;
338323 }
324+ } ) ;
325+ }
326+
327+ private async Task < Dictionary < string , string > > CalculateDecodedPathsAsync ( Models . Stash stash , List < Models . Change > changes , List < Models . Change > untracked )
328+ {
329+ if ( _repo == null || stash == null || changes == null || changes . Count == 0 )
330+ return null ;
339331
340- if ( filesToDecode . Count == 0 )
341- return ;
332+ var repositoryPath = _repo . FullPath ;
333+ var untrackedSet = new HashSet < Models . Change > ( untracked ) ;
334+ var filesToDecode = new List < ( string RelativePath , string Spec ) > ( ) ;
342335
343- var batchRequests = new List < string > ( ) ;
344- foreach ( var entry in filesToDecode )
345- batchRequests . Add ( entry . Spec ) ;
336+ foreach ( var change in changes )
337+ {
338+ if ( ! Utilities . OFPAParser . IsOFPAFile ( change . Path ) )
339+ continue ;
346340
347- var batchResults = await Commands . QueryFileContent . RunBatchAsync ( repositoryPath , batchRequests , MaxOFPASampleSize ) . ConfigureAwait ( false ) ;
348- foreach ( var entry in filesToDecode )
341+ string spec ;
342+ if ( untrackedSet . Contains ( change ) && stash . Parents . Count == 3 )
349343 {
350- if ( batchResults . TryGetValue ( entry . Spec , out var data ) )
351- {
352- var decoded = Utilities . OFPAParser . DecodeFromData ( data ) ;
353- results [ entry . RelativePath ] = decoded ? . LabelValue ;
354- }
344+ spec = $ "{ stash . Parents [ 2 ] } :{ change . Path } ";
345+ }
346+ else
347+ {
348+ if ( change . WorkTree == Models . ChangeState . Deleted || change . Index == Models . ChangeState . Deleted )
349+ spec = $ "{ stash . Parents [ 0 ] } :{ change . Path } ";
350+ else
351+ spec = $ "{ stash . SHA } :{ change . Path } ";
355352 }
356353
357- var updated = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
358- foreach ( var kvp in results )
359- updated [ kvp . Key ] = kvp . Value ;
360- _decodedPaths = updated ;
361- } ) ;
354+ filesToDecode . Add ( ( change . Path , spec ) ) ;
355+ }
356+
357+ if ( filesToDecode . Count == 0 )
358+ return null ;
359+
360+ var batchRequests = new List < string > ( ) ;
361+ foreach ( var entry in filesToDecode )
362+ batchRequests . Add ( entry . Spec ) ;
362363
363- if ( results . Count > 0 )
364+ var batchResults = await Commands . QueryFileContent . RunBatchAsync ( repositoryPath , batchRequests , MaxOFPASampleSize ) . ConfigureAwait ( false ) ;
365+ var results = new Dictionary < string , string > ( StringComparer . Ordinal ) ;
366+ foreach ( var entry in filesToDecode )
364367 {
365- await Dispatcher . UIThread . InvokeAsync ( ( ) =>
368+ if ( batchResults . TryGetValue ( entry . Spec , out var data ) )
366369 {
367- if ( _repo == null || ! _repo . Settings . EnableUnrealEngineSupport || ! _repo . Settings . EnableOFPADecoding )
368- return ;
369-
370- OnPropertyChanged ( nameof ( DecodedPaths ) ) ;
371- } ) ;
370+ var decoded = Utilities . OFPAParser . DecodeFromData ( data ) ;
371+ if ( decoded . HasValue )
372+ results [ entry . RelativePath ] = decoded . Value . LabelValue ;
373+ }
372374 }
375+
376+ return results ;
373377 }
374378
375379 private Repository _repo = null ;
0 commit comments