-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow forced reload of revisions #11205
Draft
mstv
wants to merge
3
commits into
gitextensions:master
Choose a base branch
from
mstv:fix/i9418_force_reload
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,7 +112,7 @@ public sealed partial class RevisionGridControl : GitModuleControl, ICheckRefs, | |
/// </summary> | ||
private Lazy<IReadOnlyCollection<string>>? _ambiguousRefs; | ||
|
||
private int _updatingFilters; | ||
private int _suspendRefreshCounter; | ||
|
||
private IDisposable? _revisionSubscription; | ||
private GitRevision? _baseCommitToCompare; | ||
|
@@ -471,15 +471,15 @@ public void DisableContextMenu() | |
/// Prevents revisions refreshes and stops <see cref="PerformRefreshRevisions"/> from executing | ||
/// until <see cref="ResumeRefreshRevisions"/> is called. | ||
/// </summary> | ||
internal void SuspendRefreshRevisions() => _updatingFilters++; | ||
internal void SuspendRefreshRevisions() => ++_suspendRefreshCounter; | ||
|
||
/// <summary> | ||
/// Resume revisions refreshes. | ||
/// </summary> | ||
internal void ResumeRefreshRevisions() | ||
{ | ||
--_updatingFilters; | ||
DebugHelpers.Assert(_updatingFilters >= 0, $"{nameof(ResumeRefreshRevisions)} was called without matching {nameof(SuspendRefreshRevisions)}!"); | ||
--_suspendRefreshCounter; | ||
DebugHelpers.Assert(_suspendRefreshCounter >= 0, $"{nameof(ResumeRefreshRevisions)} was called without matching {nameof(SuspendRefreshRevisions)}!"); | ||
} | ||
|
||
public void SetAndApplyBranchFilter(string filter) | ||
|
@@ -851,29 +851,38 @@ private void ShowLoading(bool showSpinner = true) | |
} | ||
|
||
/// <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"/> | ||
/// Indicates whether the revision grid can be refreshed, | ||
/// i.e. it is not in a middle of reconfiguration process guarded by <see cref="SuspendRefreshRevisions"/> | ||
/// and <see cref="ResumeRefreshRevisions"/>. | ||
/// </summary> | ||
private bool CanRefresh => !_isRefreshingRevisions && _updatingFilters == 0; | ||
private bool CanRefresh => _suspendRefreshCounter == 0; | ||
|
||
#region PerformRefreshRevisions | ||
|
||
/// <summary> | ||
/// Queries git for the new set of revisions and refreshes the grid. | ||
/// </summary> | ||
/// <exception cref="Exception"></exception> | ||
/// <param name="forceRefresh">Refresh may be required as references may be changed.</param> | ||
public void PerformRefreshRevisions(Func<RefsFilter, IReadOnlyList<IGitRef>> getRefs = null, bool forceRefresh = false) | ||
/// <param name="forceRefreshRefs">Refresh may be required as references may be changed.</param> | ||
public void PerformRefreshRevisions(Func<RefsFilter, IReadOnlyList<IGitRef>> getRefs = null, bool forceRefreshRefs = false) | ||
{ | ||
ThreadHelper.AssertOnUIThread(); | ||
|
||
if (!CanRefresh) | ||
{ | ||
Trace.WriteLine("Ignoring refresh as RefreshRevisions() is already running."); | ||
Trace.WriteLine("Ignoring refresh as RefreshRevisions() is suspended."); | ||
return; | ||
} | ||
|
||
if (_isRefreshingRevisions) | ||
{ | ||
Trace.WriteLine("Forcing refresh, cancel already running RefreshRevisions()."); | ||
if (!_gridView.IsDataLoadComplete) | ||
{ | ||
_gridView.MarkAsDataLoadingComplete(); | ||
} | ||
} | ||
|
||
IGitModule capturedModule = Module; | ||
|
||
// Reset the "cache" for current branch | ||
|
@@ -1081,7 +1090,7 @@ public void PerformRefreshRevisions(Func<RefsFilter, IReadOnlyList<IGitRef>> get | |
}); | ||
|
||
// Initiate update left panel | ||
RevisionsLoading?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefresh)); | ||
RevisionsLoading?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefreshRefs)); | ||
} | ||
catch | ||
{ | ||
|
@@ -1222,55 +1231,59 @@ string BuildPathFilter(string? path) | |
|
||
void OnRevisionRead(GitRevision revision) | ||
{ | ||
if (!firstRevisionReceived) | ||
{ | ||
// Wait for refs,CurrentCheckout and stashes as second step | ||
this.InvokeAndForget(() => ShowLoading(showSpinner: false)); | ||
semaphoreUpdateGrid.Wait(cancellationToken); | ||
semaphoreUpdateGrid.Wait(cancellationToken); | ||
firstRevisionReceived = true; | ||
} | ||
|
||
if (stashesById is not null) | ||
try | ||
{ | ||
if (stashesById.TryGetValue(revision.ObjectId, out GitRevision gridStash)) | ||
if (!firstRevisionReceived) | ||
{ | ||
revision.ReflogSelector = gridStash.ReflogSelector; | ||
|
||
// Do not add this again (when the main commit is handled) | ||
stashesById.Remove(revision.ObjectId); | ||
// Wait for refs,CurrentCheckout and stashes as second step | ||
this.InvokeAndForget(() => ShowLoading(showSpinner: false)); | ||
semaphoreUpdateGrid.Wait(cancellationToken); | ||
semaphoreUpdateGrid.Wait(cancellationToken); | ||
Comment on lines
+1240
to
+1241
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing this twice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The answer is not far away:
|
||
firstRevisionReceived = true; | ||
} | ||
else if (stashesByParentId?.Contains(revision.ObjectId) is true) | ||
|
||
if (stashesById is not null) | ||
{ | ||
foreach (GitRevision stash in stashesByParentId[revision.ObjectId]) | ||
if (stashesById.TryGetValue(revision.ObjectId, out GitRevision gridStash)) | ||
{ | ||
// Add if not already added (reflogs etc list before parent commit) | ||
if (stashesById.ContainsKey(stash.ObjectId)) | ||
revision.ReflogSelector = gridStash.ReflogSelector; | ||
|
||
// Do not add this again (when the main commit is handled) | ||
stashesById.Remove(revision.ObjectId); | ||
} | ||
else if (stashesByParentId?.Contains(revision.ObjectId) is true) | ||
{ | ||
foreach (GitRevision stash in stashesByParentId[revision.ObjectId]) | ||
{ | ||
_gridView.Add(stash); | ||
if (untrackedByStashId.TryGetValue(stash.ObjectId, out GitRevision untracked)) | ||
// Add if not already added (reflogs etc list before parent commit) | ||
if (stashesById.ContainsKey(stash.ObjectId)) | ||
{ | ||
_gridView.Add(untracked); | ||
_gridView.Add(stash); | ||
if (untrackedByStashId.TryGetValue(stash.ObjectId, out GitRevision untracked)) | ||
{ | ||
_gridView.Add(untracked); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
// Look up any refs associated with this revision | ||
revision.Refs = refsByObjectId[revision.ObjectId].AsReadOnlyList(); | ||
// Look up any refs associated with this revision | ||
revision.Refs = refsByObjectId[revision.ObjectId].AsReadOnlyList(); | ||
|
||
if (!headIsHandled && (revision.ObjectId.Equals(CurrentCheckout) || CurrentCheckout is null)) | ||
if (!headIsHandled && (revision.ObjectId.Equals(CurrentCheckout) || CurrentCheckout is null)) | ||
{ | ||
// Insert artificial worktree/index just before HEAD (CurrentCheckout) | ||
// If grid is filtered and HEAD not visible, insert in OnRevisionReadCompleted() | ||
headIsHandled = true; | ||
AddArtificialRevisions(); | ||
} | ||
|
||
_gridView.Add(revision); | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
// Insert artificial worktree/index just before HEAD (CurrentCheckout) | ||
// If grid is filtered and HEAD not visible, insert in OnRevisionReadCompleted() | ||
headIsHandled = true; | ||
AddArtificialRevisions(); | ||
} | ||
|
||
_gridView.Add(revision); | ||
|
||
return; | ||
} | ||
|
||
bool ShowArtificialRevisions() | ||
|
@@ -1367,7 +1380,7 @@ void OnRevisionReadCompleted() | |
} | ||
|
||
_isRefreshingRevisions = false; | ||
RevisionsLoaded?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefresh)); | ||
RevisionsLoaded?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefreshRefs)); | ||
}); | ||
return; | ||
} | ||
|
@@ -1433,7 +1446,7 @@ void OnRevisionReadCompleted() | |
|
||
SetPage(_gridView); | ||
_isRefreshingRevisions = false; | ||
RevisionsLoaded?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefresh)); | ||
RevisionsLoaded?.Invoke(this, new RevisionLoadEventArgs(this, UICommands, getUnfilteredRefs, getStashRevs, forceRefreshRefs)); | ||
HighlightRevisionsByAuthor(GetSelectedRevisions()); | ||
|
||
await TaskScheduler.Default; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nit] For any trace I'd add a prefix that would help identifying the source, e.g.