Skip to content

Commit f78a6c9

Browse files
NainetenNaineten
authored andcommitted
refactor: improve naming and style consistency in OFPA logic
1 parent 6ff8826 commit f78a6c9

2 files changed

Lines changed: 25 additions & 21 deletions

File tree

src/ViewModels/CommitDetail.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public CommitDetailSharedData()
2828

2929
public partial class CommitDetail : ObservableObject, IDisposable
3030
{
31+
private const int MaxOFPASampleSize = 256 * 1024;
32+
3133
public Repository Repository
3234
{
3335
get => _repo;
@@ -693,30 +695,32 @@ private async Task DecodeOFPAPathsAsync(List<Models.Change> changes)
693695

694696
await Task.Run(async () =>
695697
{
696-
var objectSpecs = new List<(string RelativePath, string Spec)>();
698+
var filesToDecode = new List<(string RelativePath, string Spec)>();
697699
foreach (var change in changes)
698700
{
699701
if (Utilities.OFPAParser.IsOFPAFile(change.Path))
700702
{
701-
// For deleted files, read from parent. For others, read from current commit.
703+
// Use heuristic to determine revision:
704+
// - Deleted files (WorkTree or Index) -> fetch from Parent commit.
705+
// - Added/Modified files -> fetch from Current commit.
702706
var spec = (change.WorkTree == Models.ChangeState.Deleted || change.Index == Models.ChangeState.Deleted)
703707
? $"{parent}:{change.Path}"
704708
: $"{_commit.SHA}:{change.Path}";
705-
objectSpecs.Add((change.Path, spec));
709+
filesToDecode.Add((change.Path, spec));
706710
}
707711
}
708712

709-
if (objectSpecs.Count == 0)
713+
if (filesToDecode.Count == 0)
710714
return;
711715

712-
var specs = new List<string>();
713-
foreach (var entry in objectSpecs)
714-
specs.Add(entry.Spec);
716+
var batchRequests = new List<string>();
717+
foreach (var entry in filesToDecode)
718+
batchRequests.Add(entry.Spec);
715719

716-
var dataMap = await Commands.QueryFileContent.RunBatchAsync(repositoryPath, specs, MaxOFPASampleSize).ConfigureAwait(false);
717-
foreach (var entry in objectSpecs)
720+
var batchResults = await Commands.QueryFileContent.RunBatchAsync(repositoryPath, batchRequests, MaxOFPASampleSize).ConfigureAwait(false);
721+
foreach (var entry in filesToDecode)
718722
{
719-
if (dataMap.TryGetValue(entry.Spec, out var data))
723+
if (batchResults.TryGetValue(entry.Spec, out var data))
720724
{
721725
var decoded = Utilities.OFPAParser.DecodeFromData(data);
722726
results[entry.RelativePath] = decoded?.LabelValue;
@@ -763,6 +767,5 @@ await Dispatcher.UIThread.InvokeAsync(() =>
763767
private Vector _scrollOffset = Vector.Zero;
764768
private Dictionary<string, string> _decodedPaths = null;
765769
private Task _currentDecodeTask = Task.CompletedTask;
766-
private const int MaxOFPASampleSize = 256 * 1024;
767770
}
768771
}

src/ViewModels/StashesPage.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace SourceGit.ViewModels
99
{
1010
public class StashesPage : ObservableObject, IDisposable
1111
{
12+
private const int MaxOFPASampleSize = 256 * 1024;
13+
1214
public IReadOnlyDictionary<string, string> DecodedPaths
1315
{
1416
get
@@ -310,7 +312,7 @@ private async Task DecodeOFPAPathsAsync(Models.Stash stash, List<Models.Change>
310312

311313
await Task.Run(async () =>
312314
{
313-
var objectSpecs = new List<(string RelativePath, string Spec)>();
315+
var filesToDecode = new List<(string RelativePath, string Spec)>();
314316
foreach (var change in changes)
315317
{
316318
if (!Utilities.OFPAParser.IsOFPAFile(change.Path))
@@ -332,20 +334,20 @@ await Task.Run(async () =>
332334
spec = $"{stash.SHA}:{change.Path}";
333335
}
334336

335-
objectSpecs.Add((change.Path, spec));
337+
filesToDecode.Add((change.Path, spec));
336338
}
337339

338-
if (objectSpecs.Count == 0)
340+
if (filesToDecode.Count == 0)
339341
return;
340342

341-
var specs = new List<string>();
342-
foreach (var entry in objectSpecs)
343-
specs.Add(entry.Spec);
343+
var batchRequests = new List<string>();
344+
foreach (var entry in filesToDecode)
345+
batchRequests.Add(entry.Spec);
344346

345-
var dataMap = await Commands.QueryFileContent.RunBatchAsync(repositoryPath, specs, MaxOFPASampleSize).ConfigureAwait(false);
346-
foreach (var entry in objectSpecs)
347+
var batchResults = await Commands.QueryFileContent.RunBatchAsync(repositoryPath, batchRequests, MaxOFPASampleSize).ConfigureAwait(false);
348+
foreach (var entry in filesToDecode)
347349
{
348-
if (dataMap.TryGetValue(entry.Spec, out var data))
350+
if (batchResults.TryGetValue(entry.Spec, out var data))
349351
{
350352
var decoded = Utilities.OFPAParser.DecodeFromData(data);
351353
results[entry.RelativePath] = decoded?.LabelValue;
@@ -381,6 +383,5 @@ await Dispatcher.UIThread.InvokeAsync(() =>
381383
private DiffContext _diffContext = null;
382384
private Dictionary<string, string> _decodedPaths = null;
383385
private Task _currentDecodeTask = Task.CompletedTask;
384-
private const int MaxOFPASampleSize = 256 * 1024;
385386
}
386387
}

0 commit comments

Comments
 (0)