Skip to content

Commit

Permalink
FormBrowse init optimizations (gitextensions#9725)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed Nov 14, 2021
1 parent 1b27e63 commit 26f9b6e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
62 changes: 37 additions & 25 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ public FormBrowse(GitUICommands commands, BrowseArguments args)
_aheadBehindDataProvider = new AheadBehindDataProvider(() => Module.GitExecutable);
toolStripButtonPush.Initialize(_aheadBehindDataProvider);
repoObjectsTree.Initialize(_aheadBehindDataProvider, branchFilterAction: ToolStripFilters.SetBranchFilter, RevisionGrid, RevisionGrid, RevisionGrid);
revisionDiff.Bind(RevisionGrid, fileTree, RequestRefresh);
fileTree.Bind(RevisionGrid, RequestRefresh);
revisionDiff.Bind(RevisionGrid, fileTree, RefreshGitStatusMonitor);
fileTree.Bind(RevisionGrid, RefreshGitStatusMonitor);
RevisionGrid.ResumeRefreshRevisions();

// We're launching the main form, and whilst the module has been set for us we still need to formally switch to it
// Also triggers RefreshRevisions()
SetGitModule(this, new GitModuleEventArgs(new GitModule(Module.WorkingDir)));

RevisionGrid.ResumeRefreshRevisions();

return;

void InitCountArtificial(out GitStatusMonitor gitStatusMonitor)
Expand Down Expand Up @@ -447,11 +447,9 @@ protected override void OnLoad(EventArgs e)
{
_formBrowseMenus.CreateToolbarsMenus(ToolStripMain, ToolStripFilters, ToolStripScripts);

HideVariableMainMenuItems();
RefreshSplitViewLayout();
LayoutRevisionInfo();
SetSplitterPositions();
InternalInitialize(false);

base.OnLoad(e);

Expand Down Expand Up @@ -572,22 +570,33 @@ private void RefreshRevisions()
return;
}

_gitStatusMonitor.InvalidateGitWorkingDirectoryStatus();
RequestRefresh();

if (_dashboard is null || !_dashboard.Visible)
bool isDashboard = string.IsNullOrEmpty(Module.WorkingDir) || (_dashboard?.Visible ?? false);
if (isDashboard)
{
revisionDiff.RefreshArtificial();
RevisionGrid.ForceRefreshRevisions();
RevisionGrid.IndexWatcher.Reset();
// Explicit call: Title is normally updated on RevisionGrid filter change
_appTitleGenerator.Generate();

// "Repo" related methods, creates _dashboard
InternalInitialize();

return;
}

InternalInitialize(true);
if (!RevisionGrid.CanRefresh)
{
// Still loading, the method will be called again
return;
}

toolStripButtonPush.DisplayAheadBehindInformation(Module.GetSelectedBranch());
RevisionGrid.ForceRefreshRevisions();

InternalInitialize();

RefreshGitStatusMonitor();
revisionDiff.RefreshArtificial();
}

private void RequestRefresh() => _gitStatusMonitor?.RequestRefresh();
private void RefreshGitStatusMonitor() => _gitStatusMonitor?.RequestRefresh();

private void RefreshSelection()
{
Expand Down Expand Up @@ -658,7 +667,7 @@ private void ShowDashboard()
private void HideDashboard()
{
MainSplitContainer.Visible = true;
if (_dashboard is null || !_dashboard.Visible)
if (!_dashboard?.Visible ?? true)
{
return;
}
Expand Down Expand Up @@ -714,6 +723,7 @@ private void RegisterPlugins()
{
if (plugin.Execute(new GitUIEventArgs(this, UICommands)))
{
_gitStatusMonitor.InvalidateGitWorkingDirectoryStatus();
RefreshRevisions();
}
};
Expand Down Expand Up @@ -772,7 +782,7 @@ private void HideVariableMainMenuItems()
mainMenuStrip.Refresh();
}

private void InternalInitialize(bool hard)
private void InternalInitialize()
{
toolPanel.SuspendLayout();
toolPanel.TopToolStripPanel.SuspendLayout();
Expand All @@ -798,7 +808,7 @@ private void InternalInitialize(bool hard)
}

bool bareRepository = Module.IsBareRepository();
bool isDashboard = _dashboard is not null && _dashboard.Visible;
bool isDashboard = _dashboard?.Visible ?? false;
bool validBrowseDir = !isDashboard && Module.IsValidGitWorkingDir();

branchSelect.Text = validBrowseDir ? Module.GetSelectedBranch() : "";
Expand Down Expand Up @@ -834,7 +844,8 @@ private void InternalInitialize(bool hard)
_createPullRequestsToolStripMenuItem.Enabled = validBrowseDir;
_viewPullRequestsToolStripMenuItem.Enabled = validBrowseDir;

if (repositoryToolStripMenuItem.Visible)
// repositoryToolStripMenuItem.Visible
if (validBrowseDir)
{
manageSubmodulesToolStripMenuItem.Enabled = !bareRepository;
updateAllSubmodulesToolStripMenuItem.Enabled = !bareRepository;
Expand All @@ -844,7 +855,8 @@ private void InternalInitialize(bool hard)
editmailmapToolStripMenuItem.Enabled = !bareRepository;
}

if (commandsToolStripMenuItem.Visible)
// commandsToolStripMenuItem.Visible
if (validBrowseDir)
{
commitToolStripMenuItem.Enabled = !bareRepository;
mergeToolStripMenuItem.Enabled = !bareRepository;
Expand All @@ -863,7 +875,7 @@ private void InternalInitialize(bool hard)

SetShortcutKeyDisplayStringsFromHotkeySettings();

if (hard && hasWorkingDir)
if (hasWorkingDir)
{
ShowRevisions();
}
Expand All @@ -885,7 +897,7 @@ private void InternalInitialize(bool hard)

_formBrowseMenus.InsertRevisionGridMainMenuItems(repositoryToolStripMenuItem);

toolStripButtonPush.DisplayAheadBehindInformation(Module.GetSelectedBranch());
toolStripButtonPush.DisplayAheadBehindInformation(branchSelect.Text);

ActiveControl = RevisionGrid;
RevisionGrid.IndexWatcher.Reset();
Expand Down Expand Up @@ -1309,7 +1321,7 @@ private void StashToolStripMenuItemClick(object sender, EventArgs e)
private void ResetToolStripMenuItem_Click(object sender, EventArgs e)
{
UICommands.StartResetChangesDialog(this);
RequestRefresh();
RefreshGitStatusMonitor();
revisionDiff.RefreshArtificial();
}

Expand Down Expand Up @@ -2993,7 +3005,7 @@ private void undoLastCommitToolStripMenuItem_Click(object sender, EventArgs e)
var args = GitCommandHelpers.ResetCmd(ResetMode.Soft, "HEAD~1");
Module.GitExecutable.GetOutput(args);
refreshToolStripMenuItem.PerformClick();
RequestRefresh();
RefreshGitStatusMonitor();
}
}

Expand Down
11 changes: 4 additions & 7 deletions GitUI/UserControls/RevisionGrid/RevisionGridControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -465,17 +465,12 @@ public void DisableContextMenu()
internal void SuspendRefreshRevisions() => _updatingFilters++;

/// <summary>
/// Resume revisions refreshes and invokes <see cref="ForceRefreshRevisions"/>.
/// Resume revisions refreshes.
/// </summary>
internal void ResumeRefreshRevisions()
{
--_updatingFilters;
Debug.Assert(_updatingFilters >= 0, $"{nameof(ResumeRefreshRevisions)} was called without matching {nameof(SuspendRefreshRevisions)}!");

if (_updatingFilters == 0)
{
ForceRefreshRevisions();
}
}

public void SetAndApplyBranchFilter(string filter)
Expand Down Expand Up @@ -825,11 +820,13 @@ private void ShowLoading(bool sync = true)
_loadingControlAsync.BringToFront();
}

public bool CanRefresh => !_isRefreshingRevisions && _updatingFilters == 0;

public void ForceRefreshRevisions()
{
ThreadHelper.AssertOnUIThread();

if (_isRefreshingRevisions || _updatingFilters != 0)
if (!CanRefresh)
{
return;
}
Expand Down

0 comments on commit 26f9b6e

Please sign in to comment.