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

Sorted refs needs to be refreshed after the repository has changed. #6335

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 46 additions & 26 deletions GitUI/CommitInfo/CommitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ public CommitInfo()
InitializeComponent();
InitializeComplete();

UICommandsSourceSet += delegate { this.InvokeAsync(() => ReloadCommitInfo()).FileAndForget(); };
UICommandsSourceSet += delegate
{
this.InvokeAsync(() =>
{
UICommandsSource.UICommandsChanged += UICommandsSource_UICommandsChanged;
RefreshSortedRefs();
ReloadCommitInfo();
}).FileAndForget();
};

_commitDataManager = new CommitDataManager(() => Module);

Expand Down Expand Up @@ -127,6 +135,19 @@ IDisposable subscribeToContentsResized(RichTextBox richTextBox, Action<ContentsR
commitInfoHeader.SetContextMenuStrip(commitInfoContextMenuStrip);
}

private void UICommandsSource_UICommandsChanged(object sender, GitUICommandsChangedEventArgs e)
{
RefreshSortedRefs();
}

private void RefreshSortedRefs()
{
ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await LoadSortedRefsAsync();
}).FileAndForget();
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Browsable(false)]
public GitRevision Revision
Expand Down Expand Up @@ -179,6 +200,30 @@ public void SetRevisionWithChildren(GitRevision revision, IReadOnlyList<ObjectId
ReloadCommitInfo();
}

private async Task LoadSortedRefsAsync()
{
ThreadHelper.AssertOnUIThread();
_refsOrderDict = null;

await TaskScheduler.Default.SwitchTo();
var refsOrderDict = ToDictionary(Module.GetSortedRefs());

await this.SwitchToMainThreadAsync();
_refsOrderDict = refsOrderDict;
UpdateRevisionInfo();

IDictionary<string, int> ToDictionary(IReadOnlyList<string> list)
{
var dict = new Dictionary<string, int>();
for (int i = 0; i < list.Count; i++)
{
dict.Add(list[i], i);
}

return dict;
}
}

private void ReloadCommitInfo()
{
showContainedInBranchesToolStripMenuItem.Checked = AppSettings.CommitInfoShowContainedInBranchesLocal;
Expand Down Expand Up @@ -231,11 +276,6 @@ void StartAsyncDataLoad()

ThreadHelper.JoinableTaskFactory.RunAsync(() => LoadLinksForRevisionAsync(_revision)).FileAndForget();

if (_refsOrderDict == null)
{
ThreadHelper.JoinableTaskFactory.RunAsync(() => LoadSortedRefsAsync()).FileAndForget();
}

// No branch/tag data for artificial commands

if (AppSettings.CommitInfoShowContainedInBranches)
Expand Down Expand Up @@ -296,26 +336,6 @@ string GetLinksForRevision()
}
}

async Task LoadSortedRefsAsync()
{
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
_refsOrderDict = ToDictionary(Module.GetSortedRefs());

await this.SwitchToMainThreadAsync(cancellationToken);
UpdateRevisionInfo();

IDictionary<string, int> ToDictionary(IReadOnlyList<string> list)
{
var dict = new Dictionary<string, int>();
for (int i = 0; i < list.Count; i++)
{
dict.Add(list[i], i);
}

return dict;
}
}

async Task LoadAnnotatedTagInfoAsync(IReadOnlyList<IGitRef> refs)
{
await TaskScheduler.Default.SwitchTo(alwaysYield: true);
Expand Down