Skip to content

Commit

Permalink
Clear custom tool caches in sequence after updating settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed Aug 31, 2021
1 parent c02af14 commit fdadf89
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 20 deletions.
25 changes: 11 additions & 14 deletions GitCommands/CustomDiffMergeToolCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@ private CustomDiffMergeToolCache(bool isDiff)
public static CustomDiffMergeToolCache MergeToolCache { get; } = new(false);

/// <summary>
/// Clear the existing caches
/// Clear the existing caches (await current calculation to finsh first)
/// </summary>
public void Clear()
public async Task ClearAsync()
{
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await _mutex.WaitAsync().ConfigureAwait(false);
await _mutex.WaitAsync().ConfigureAwait(false);

try
{
_tools = null;
}
finally
{
_mutex.Release();
}
}).FileAndForget();
try
{
_tools = null;
}
finally
{
_mutex.Release();
}
}

/// <summary>
Expand Down
20 changes: 17 additions & 3 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,9 +1590,23 @@ private void OnShowSettingsClick(object sender, EventArgs e)
RevisionGrid.ReloadTranslation();
fileTree.ReloadHotkeys();
revisionDiff.ReloadHotkeys();
new CustomDiffMergeToolProvider().Clear();
revisionDiff.LoadCustomDifftools();
RevisionGrid.LoadCustomDifftools();

// Clear the separate caches for diff/merge tools
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await new CustomDiffMergeToolProvider().ClearAsync(isDiff: false);
}).FileAndForget();
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
revisionDiff.CancelLoadCustomDifftools();
RevisionGrid.CancelLoadCustomDifftools();
await new CustomDiffMergeToolProvider().ClearAsync(isDiff: true);
// The tool lists are created when the forms are init, must be redone after clearing the cache
revisionDiff.LoadCustomDifftools();
RevisionGrid.LoadCustomDifftools();
}).FileAndForget();

_dashboard?.RefreshContent();

Expand Down
5 changes: 5 additions & 0 deletions GitUI/CommandsDialogs/RevisionDiffControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ public void LoadCustomDifftools()
new CustomDiffMergeToolProvider().LoadCustomDiffMergeTools(Module, menus, components, isDiff: true);
}

public void CancelLoadCustomDifftools()
{
_customDiffToolsSequence.CancelCurrent();
}

private string GetShortcutKeyDisplayString(Command cmd)
{
return GetShortcutKeys((int)cmd).ToShortcutKeyDisplayString();
Expand Down
14 changes: 11 additions & 3 deletions GitUI/CustomDiffMergeToolProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using GitCommands;

Expand All @@ -18,10 +19,17 @@ public class CustomDiffMergeToolProvider
/// <summary>
/// Clear the existing caches.
/// </summary>
public void Clear()
/// <param name="isDiff">True if diff, false if merge.</param>
public async Task ClearAsync(bool isDiff)
{
CustomDiffMergeToolCache.DiffToolCache.Clear();
CustomDiffMergeToolCache.MergeToolCache.Clear();
if (isDiff)
{
await CustomDiffMergeToolCache.DiffToolCache.ClearAsync();
}
else
{
await CustomDiffMergeToolCache.MergeToolCache.ClearAsync();
}
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,11 @@ public void LoadCustomDifftools()
new CustomDiffMergeToolProvider().LoadCustomDiffMergeTools(Module, menus, components, isDiff: true);
}

public void CancelLoadCustomDifftools()
{
_customDiffToolsSequence.CancelCurrent();
}

private void SetSelectedIndex(int index, bool toggleSelection = false)
{
try
Expand Down

0 comments on commit fdadf89

Please sign in to comment.