Skip to content

Commit

Permalink
squash! FormBrowse init optimizations (#9725)
Browse files Browse the repository at this point in the history
  • Loading branch information
RussKie committed Nov 21, 2021
1 parent da33732 commit 9e74d91
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 23 deletions.
2 changes: 1 addition & 1 deletion GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private void RefreshRevisions()
}

Debug.Assert(RevisionGrid.CanRefresh, "Already loading revisions when running RefreshRevisions(). This could cause the commits in the grid to be loaded several times.");
RevisionGrid.ForceRefreshRevisions();
RevisionGrid.RefreshRevisions();

InternalInitialize();

Expand Down
56 changes: 34 additions & 22 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public void SetAndApplyPathFilter(string filter)
_filterInfo.ByPathFilter = !string.IsNullOrWhiteSpace(filter);
_filterInfo.PathFilter = filter;

ForceRefreshRevisions();
PerformRefreshRevisions();
}

private void InitiateRefAction(IReadOnlyList<IGitRef>? refs, Action<IGitRef> action, FormQuickGitRefSelector.Action actionLabel)
Expand Down Expand Up @@ -459,7 +459,7 @@ public void DisableContextMenu()
}

/// <summary>
/// Prevents revisions refreshes and stops <see cref="ForceRefreshRevisions"/> from executing
/// Prevents revisions refreshes and stops <see cref="PerformRefreshRevisions"/> from executing
/// until <see cref="ResumeRefreshRevisions"/> is called.
/// </summary>
internal void SuspendRefreshRevisions() => _updatingFilters++;
Expand All @@ -486,7 +486,7 @@ public void SetAndApplyBranchFilter(string filter)
_filterInfo.ByBranchFilter = !string.IsNullOrWhiteSpace(newFilter);
_filterInfo.BranchFilter = newFilter;

ForceRefreshRevisions();
PerformRefreshRevisions();
}

/// <summary>
Expand All @@ -502,7 +502,7 @@ public void SetAndApplyRevisionFilter(RevisionFilter filter)
return;
}

ForceRefreshRevisions();
PerformRefreshRevisions();
}

public override void Refresh()
Expand Down Expand Up @@ -548,7 +548,7 @@ public new void Load()
ReloadHotkeys();
}

ForceRefreshRevisions();
PerformRefreshRevisions();

LoadCustomDifftools();
}
Expand Down Expand Up @@ -789,11 +789,14 @@ public GitRevision GetActualRevision(GitRevision revision)
return revision;
}

/// <summary>
/// Refreshes the revision grid, if there are any changes reported by <see cref="IndexWatcher.IndexChanged"/>.
/// </summary>
public void RefreshRevisions()
{
if (IndexWatcher.IndexChanged)
{
ForceRefreshRevisions();
PerformRefreshRevisions();
}
}

Expand All @@ -820,9 +823,18 @@ private void ShowLoading(bool sync = true)
_loadingControlAsync.BringToFront();
}

/// <summary>
/// Indicates whether the revision grid can be refreshed, i.e. it is not currently being refreshed
/// or it is not in a middle of reconfiguration process guarded by <see cref="SuspendRefreshRevisions"/>
/// and <see cref="ResumeRefreshRevisions"/>.
/// </summary>
public bool CanRefresh => !_isRefreshingRevisions && _updatingFilters == 0;

public void ForceRefreshRevisions()
/// <summary>
/// Queries git for the new set of revisions, and refreshed the grid.
/// </summary>
/// <exception cref="AggregateException"></exception>
private void PerformRefreshRevisions()
{
ThreadHelper.AssertOnUIThread();

Expand Down Expand Up @@ -1620,7 +1632,7 @@ public void ShowCurrentBranchOnly()
_filterInfo.ShowCurrentBranchOnly = true;
_filterInfo.ShowReflogReferences = false;

ForceRefreshRevisions();
PerformRefreshRevisions();
}

public void ShowAllBranches()
Expand All @@ -1633,7 +1645,7 @@ public void ShowAllBranches()
_filterInfo.ByBranchFilter = false;
_filterInfo.ShowCurrentBranchOnly = false;

ForceRefreshRevisions();
PerformRefreshRevisions();
}

public void ShowFilteredBranches()
Expand All @@ -1647,15 +1659,15 @@ public void ShowFilteredBranches()
_filterInfo.ShowCurrentBranchOnly = false;
_filterInfo.ShowReflogReferences = false;

ForceRefreshRevisions();
PerformRefreshRevisions();
}

public void ShowRevisionFilterDialog()
{
using FormRevisionFilter form = new(UICommands, _filterInfo);
if (form.ShowDialog(ParentForm) == DialogResult.OK)
{
ForceRefreshRevisions();
PerformRefreshRevisions();
}
}

Expand Down Expand Up @@ -2018,43 +2030,43 @@ internal void ToggleShowRemoteBranches()
internal void ToggleShowArtificialCommits()
{
AppSettings.RevisionGraphShowArtificialCommits = !AppSettings.RevisionGraphShowArtificialCommits;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleAuthorDateSort()
{
AppSettings.SortByAuthorDate = !AppSettings.SortByAuthorDate;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

public void ToggleShowReflogReferences()
{
_filterInfo.ShowReflogReferences = !_filterInfo.ShowReflogReferences;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleShowLatestStash()
{
AppSettings.ShowLatestStash = !AppSettings.ShowLatestStash;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleShowSuperprojectTags()
{
AppSettings.ShowSuperprojectTags = !AppSettings.ShowSuperprojectTags;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ShowSuperprojectBranches_ToolStripMenuItemClick()
{
AppSettings.ShowSuperprojectBranches = !AppSettings.ShowSuperprojectBranches;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ShowSuperprojectRemoteBranches_ToolStripMenuItemClick()
{
AppSettings.ShowSuperprojectRemoteBranches = !AppSettings.ShowSuperprojectRemoteBranches;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

private void RevertCommitToolStripMenuItemClick(object sender, EventArgs e)
Expand Down Expand Up @@ -2182,7 +2194,7 @@ private void StopBisectToolStripMenuItemClick(object sender, EventArgs e)
internal void ToggleShowGitNotes()
{
AppSettings.ShowGitNotes = !AppSettings.ShowGitNotes;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleShowMergeCommits()
Expand All @@ -2197,7 +2209,7 @@ internal void ToggleShowMergeCommits()
AppSettings.ShowRevisionGridGraphColumn = !AppSettings.ShowRevisionGridGraphColumn;
}

ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleShowCommitBodyInRevisionGrid()
Expand All @@ -2210,7 +2222,7 @@ internal void ToggleShowCommitBodyInRevisionGrid()
public void ToggleShowFirstParent()
{
_filterInfo.ShowFirstParent = !_filterInfo.ShowFirstParent;
ForceRefreshRevisions();
PerformRefreshRevisions();
}

internal void ToggleBetweenArtificialAndHeadCommits()
Expand Down Expand Up @@ -2259,7 +2271,7 @@ internal void ToggleRevisionGraphColumn()
if (!AppSettings.ShowMergeCommits && AppSettings.ShowRevisionGridGraphColumn)
{
AppSettings.ShowMergeCommits = true;
ForceRefreshRevisions();
PerformRefreshRevisions();
}
else
{
Expand Down

0 comments on commit 9e74d91

Please sign in to comment.