diff options
author | Vsevolod Kukol <sevoku@microsoft.com> | 2019-03-08 18:56:32 +0300 |
---|---|---|
committer | Vsevolod Kukol <sevoku@microsoft.com> | 2019-03-08 20:58:55 +0300 |
commit | d5872d9c7ee950a052edcfd7b9ab507f1f2a03aa (patch) | |
tree | af853ea467b8fc1a9a4ccbd1c9abba3cba4efa3b /main | |
parent | 50dbfca093343c69c100ef5102ddce9f788a0f27 (diff) |
[Git] Freeze FileService during critical operations
Fixes VSTS #715153
Fixes VSTS #807462
Fixes VSTS #750282
Diffstat (limited to 'main')
-rw-r--r-- | main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs | 119 |
1 files changed, 74 insertions, 45 deletions
diff --git a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs index cc80abceda..74d54d9510 100644 --- a/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs +++ b/main/src/addins/VersionControl/MonoDevelop.VersionControl.Git/MonoDevelop.VersionControl.Git/GitRepository.cs @@ -492,7 +492,12 @@ namespace MonoDevelop.VersionControl.Git { if (hasUICallbacks) EnsureBackgroundThread (); - blockingOperationFactory.StartNew (action).RunWaitAndCapture (); + try { + FileService.FreezeEvents (); + blockingOperationFactory.StartNew (action).RunWaitAndCapture (); + } finally { + FileService.ThawEvents (); + } } internal void RunBlockingOperation (FilePath localPath, Action<LibGit2Sharp.Repository> action, bool hasUICallbacks = false) @@ -500,7 +505,12 @@ namespace MonoDevelop.VersionControl.Git EnsureInitialized (); if (hasUICallbacks) EnsureBackgroundThread (); - blockingOperationFactory.StartNew (() => action (GetRepository (localPath))).RunWaitAndCapture (); + try { + FileService.FreezeEvents (); + blockingOperationFactory.StartNew (() => action (GetRepository (localPath))).RunWaitAndCapture (); + } finally { + FileService.ThawEvents (); + } } internal T RunBlockingOperation<T> (Func<T> action, bool hasUICallbacks = false) @@ -508,7 +518,12 @@ namespace MonoDevelop.VersionControl.Git EnsureInitialized (); if (hasUICallbacks) EnsureBackgroundThread (); - return blockingOperationFactory.StartNew (action).RunWaitAndCapture (); + try { + FileService.FreezeEvents (); + return blockingOperationFactory.StartNew (action).RunWaitAndCapture (); + } finally { + FileService.ThawEvents (); + } } internal T RunBlockingOperation<T> (FilePath localPath, Func<LibGit2Sharp.Repository, T> action, bool hasUICallbacks = false) @@ -516,7 +531,12 @@ namespace MonoDevelop.VersionControl.Git EnsureInitialized (); if (hasUICallbacks) EnsureBackgroundThread (); - return blockingOperationFactory.StartNew (() => action (GetRepository (localPath))).RunWaitAndCapture (); + try { + FileService.FreezeEvents (); + return blockingOperationFactory.StartNew (() => action (GetRepository (localPath))).RunWaitAndCapture (); + } finally { + FileService.ThawEvents (); + } } LibGit2Sharp.Repository GetRepository (FilePath localPath) @@ -967,6 +987,7 @@ namespace MonoDevelop.VersionControl.Git bool CommonPreMergeRebase (GitUpdateOptions options, ProgressMonitor monitor, out int stashIndex) { + FileService.FreezeEvents (); stashIndex = -1; monitor.Step (1); @@ -1026,22 +1047,26 @@ namespace MonoDevelop.VersionControl.Git void CommonPostMergeRebase(int stashIndex, GitUpdateOptions options, ProgressMonitor monitor, Commit oldHead) { - if ((options & GitUpdateOptions.SaveLocalChanges) == GitUpdateOptions.SaveLocalChanges) { - monitor.Step (1); - - // Restore local changes - if (stashIndex != -1) { - monitor.Log.WriteLine (GettextCatalog.GetString ("Restoring local changes")); - ApplyStash (monitor, stashIndex); - // FIXME: No StashApplyStatus.Conflicts here. - if (RootRepository.Index.Conflicts.Any () && !ConflictResolver (RootRepository, monitor, oldHead, string.Empty)) - PopStash (monitor, stashIndex); - else - RunBlockingOperation (() => RootRepository.Stashes.Remove (stashIndex)); + try { + if ((options & GitUpdateOptions.SaveLocalChanges) == GitUpdateOptions.SaveLocalChanges) { monitor.Step (1); + + // Restore local changes + if (stashIndex != -1) { + monitor.Log.WriteLine (GettextCatalog.GetString ("Restoring local changes")); + ApplyStash (monitor, stashIndex); + // FIXME: No StashApplyStatus.Conflicts here. + if (RootRepository.Index.Conflicts.Any () && !ConflictResolver (RootRepository, monitor, oldHead, string.Empty)) + PopStash (monitor, stashIndex); + else + RunBlockingOperation (() => RootRepository.Stashes.Remove (stashIndex)); + monitor.Step (1); + } } + } finally { + FileService.ThawEvents (); + monitor.EndTask (); } - monitor.EndTask (); } public void Rebase (string branch, GitUpdateOptions options, ProgressMonitor monitor) @@ -1685,42 +1710,46 @@ namespace MonoDevelop.VersionControl.Git return false; monitor.BeginTask (GettextCatalog.GetString ("Switching to branch {0}", branch), GitService.StashUnstashWhenSwitchingBranches ? 4 : 2); - - if (GitService.StashUnstashWhenSwitchingBranches) { - // Remove the stash for this branch, if exists - string currentBranch = RootRepository.Head.FriendlyName; - stashIndex = RunOperation (() => GetStashForBranch (RootRepository.Stashes, currentBranch)); - if (stashIndex != -1) - RunBlockingOperation (() => RootRepository.Stashes.Remove (stashIndex)); - - if (!TryCreateStash (monitor, GetStashName (currentBranch), out stash)) - return false; - - monitor.Step (1); - } + FileService.FreezeEvents (); try { - int progress = 0; - RunBlockingOperation (() => LibGit2Sharp.Commands.Checkout (RootRepository, branch, new CheckoutOptions { - OnCheckoutProgress = (path, completedSteps, totalSteps) => OnCheckoutProgress (completedSteps, totalSteps, monitor, ref progress), - OnCheckoutNotify = (string path, CheckoutNotifyFlags flags) => RefreshFile (path, flags), - CheckoutNotifyFlags = refreshFlags, - }), true); - } finally { - // Restore the branch stash if (GitService.StashUnstashWhenSwitchingBranches) { - stashIndex = RunOperation (() => GetStashForBranch (RootRepository.Stashes, branch)); + // Remove the stash for this branch, if exists + string currentBranch = RootRepository.Head.FriendlyName; + stashIndex = RunOperation (() => GetStashForBranch (RootRepository.Stashes, currentBranch)); if (stashIndex != -1) - PopStash (monitor, stashIndex); + RunBlockingOperation (() => RootRepository.Stashes.Remove (stashIndex)); + + if (!TryCreateStash (monitor, GetStashName (currentBranch), out stash)) + return false; + monitor.Step (1); } - } - Runtime.RunInMainThread (() => { - BranchSelectionChanged?.Invoke (this, EventArgs.Empty); - }).Ignore (); + try { + int progress = 0; + RunBlockingOperation (() => LibGit2Sharp.Commands.Checkout (RootRepository, branch, new CheckoutOptions { + OnCheckoutProgress = (path, completedSteps, totalSteps) => OnCheckoutProgress (completedSteps, totalSteps, monitor, ref progress), + OnCheckoutNotify = (string path, CheckoutNotifyFlags flags) => RefreshFile (path, flags), + CheckoutNotifyFlags = refreshFlags, + }), true); + } finally { + // Restore the branch stash + if (GitService.StashUnstashWhenSwitchingBranches) { + stashIndex = RunOperation (() => GetStashForBranch (RootRepository.Stashes, branch)); + if (stashIndex != -1) + PopStash (monitor, stashIndex); + monitor.Step (1); + } + } - monitor.EndTask (); + Runtime.RunInMainThread (() => { + BranchSelectionChanged?.Invoke (this, EventArgs.Empty); + }).Ignore (); + } finally { + monitor.EndTask (); + FileService.ThawEvents (); + } return true; } |