Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormBrowse init optimizations #9729

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 37 additions & 29 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,11 @@ 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);

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

revisionDiff.Bind(RevisionGrid, fileTree, RefreshGitStatusMonitor);
fileTree.Bind(RevisionGrid, RefreshGitStatusMonitor);
RevisionGrid.ResumeRefreshRevisions();
RussKie marked this conversation as resolved.
Show resolved Hide resolved

// Application is init, the repo related operations are triggered in OnLoad()
return;

void InitCountArtificial(out GitStatusMonitor gitStatusMonitor)
Expand Down Expand Up @@ -442,20 +439,20 @@ protected override void OnApplicationActivated()
base.OnApplicationActivated();
}

// Contains app init logics ONLY. All repo-specific logic must be placed UICommands.PostRepositoryChanged handler.
protected override void OnLoad(EventArgs e)
{
_formBrowseMenus.CreateToolbarsMenus(ToolStripMain, ToolStripFilters, ToolStripScripts);

HideVariableMainMenuItems();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run from SetGitModule(), always run before opening module or dashboard so no explicit call needed.

RefreshSplitViewLayout();
LayoutRevisionInfo();
SetSplitterPositions();
InternalInitialize(false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has repo specific setup and runs from RefreshRevisions()
Previously needed here as it must run after RevisionGrid.ForceRefreshRevisions()


base.OnLoad(e);

_formBrowseDiagnosticsReporter.Report();

// All app init is done, make all repo related similar to switching repos (like triggering RefreshRevisions())
SetGitModule(this, new GitModuleEventArgs(new GitModule(Module.WorkingDir)));
}

protected override void OnActivated(EventArgs e)
Expand Down Expand Up @@ -572,22 +569,28 @@ private void RefreshRevisions()
return;
}

_gitStatusMonitor.InvalidateGitWorkingDirectoryStatus();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run from SetGitModule()

RequestRefresh();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to RefreshGitStatusMonitor


if (_dashboard is null || !_dashboard.Visible)
bool isDashboard = string.IsNullOrEmpty(Module.WorkingDir) || (_dashboard?.Visible ?? false);
if (isDashboard)
{
revisionDiff.RefreshArtificial();
RevisionGrid.ForceRefreshRevisions();
RevisionGrid.IndexWatcher.Reset();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Runs in RevisionGrid.ForceRefreshRevisions()

// Explicit call: Title is normally updated on RevisionGrid filter change
_appTitleGenerator.Generate();

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

InternalInitialize(true);
return;
}

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

InternalInitialize();

RefreshGitStatusMonitor();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the separate git-status calls run after the UI is refreshed

revisionDiff.RefreshArtificial();
}

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

private void RefreshSelection()
{
Expand Down Expand Up @@ -658,7 +661,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 +717,7 @@ private void RegisterPlugins()
{
if (plugin.Execute(new GitUIEventArgs(this, UICommands)))
{
_gitStatusMonitor.InvalidateGitWorkingDirectoryStatus();
RefreshRevisions();
}
};
Expand Down Expand Up @@ -772,7 +776,7 @@ private void HideVariableMainMenuItems()
mainMenuStrip.Refresh();
}

private void InternalInitialize(bool hard)
private void InternalInitialize()
{
toolPanel.SuspendLayout();
toolPanel.TopToolStripPanel.SuspendLayout();
Expand All @@ -798,7 +802,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 +838,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 +849,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 +869,7 @@ private void InternalInitialize(bool hard)

SetShortcutKeyDisplayStringsFromHotkeySettings();

if (hard && hasWorkingDir)
if (hasWorkingDir)
{
ShowRevisions();
}
Expand All @@ -885,7 +891,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 +1315,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 @@ -1773,6 +1779,7 @@ private void SetGitModule(object sender, GitModuleEventArgs e)
UICommands = new GitUICommands(module);
if (Module.IsValidGitWorkingDir())
{
RevisionGrid.SuspendRefreshRevisions();
var path = Module.WorkingDir;
ThreadHelper.JoinableTaskFactory.Run(() => RepositoryHistoryManager.Locals.AddAsMostRecentAsync(path));
AppSettings.RecentWorkingDir = path;
Expand Down Expand Up @@ -1803,8 +1810,9 @@ private void SetGitModule(object sender, GitModuleEventArgs e)
}

RevisionInfo.SetRevisionWithChildren(revision: null, children: Array.Empty<ObjectId>());
RevisionGrid.ResumeRefreshRevisions();

// This will raise UICommands.PostRepositoryChanged event
// This will raise UICommands.PostRepositoryChanged -> RefreshRevisions()
UICommands.RepoChangedNotifier.Notify();
}
else
Expand Down Expand Up @@ -2993,7 +3001,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