From a89760c7a57c61303ef3c1f5fbfb5305ccf71cf4 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 8 Mar 2024 09:57:29 +0800 Subject: [PATCH] refactor: change the way to refresh repository's data. * mark dirty instead of calling refresh method directly * force mark branches data dirty after remotes changed --- src/Models/Watcher.cs | 8 ++++++-- src/ViewModels/AddRemote.cs | 5 ++++- src/ViewModels/DeleteRemote.cs | 5 ++++- src/ViewModels/Repository.cs | 14 ++++++++++---- src/ViewModels/WorkingCopy.cs | 10 +++++----- src/Views/TextDiffView.axaml.cs | 8 ++++---- 6 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Models/Watcher.cs b/src/Models/Watcher.cs index 74441dc7..c26d9673 100644 --- a/src/Models/Watcher.cs +++ b/src/Models/Watcher.cs @@ -53,8 +53,12 @@ namespace SourceGit.Models { } } - public void MarkWorkingCopyRefreshed() { - _updateWC = 0; + public void MarkBranchDirtyManually() { + _updateBranch = DateTime.Now.ToFileTime() - 1; + } + + public void MarkWorkingCopyDirtyManually() { + _updateWC = DateTime.Now.ToFileTime() - 1; } public void Dispose() { diff --git a/src/ViewModels/AddRemote.cs b/src/ViewModels/AddRemote.cs index f20422b7..8d80046d 100644 --- a/src/ViewModels/AddRemote.cs +++ b/src/ViewModels/AddRemote.cs @@ -70,7 +70,10 @@ namespace SourceGit.ViewModels { new Commands.Config(_repo.FullPath).Set($"remote.{_name}.sshkey", SSHKey); } } - CallUIThread(() => _repo.SetWatcherEnabled(true)); + CallUIThread(() => { + _repo.MarkBranchesDirtyManually(); + _repo.SetWatcherEnabled(true); + }); return succ; }); } diff --git a/src/ViewModels/DeleteRemote.cs b/src/ViewModels/DeleteRemote.cs index 513865ba..83cea173 100644 --- a/src/ViewModels/DeleteRemote.cs +++ b/src/ViewModels/DeleteRemote.cs @@ -19,7 +19,10 @@ namespace SourceGit.ViewModels { return Task.Run(() => { var succ = new Commands.Remote(_repo.FullPath).Delete(Remote.Name); - CallUIThread(() => _repo.SetWatcherEnabled(true)); + CallUIThread(() => { + _repo.MarkBranchesDirtyManually(); + _repo.SetWatcherEnabled(true); + }); return succ; }); } diff --git a/src/ViewModels/Repository.cs b/src/ViewModels/Repository.cs index 85b5131e..f190d7f8 100644 --- a/src/ViewModels/Repository.cs +++ b/src/ViewModels/Repository.cs @@ -306,6 +306,14 @@ namespace SourceGit.ViewModels { if (_watcher != null) _watcher.SetEnabled(enabled); } + public void MarkBranchesDirtyManually() { + if (_watcher != null) _watcher.MarkBranchDirtyManually(); + } + + public void MarkWorkingCopyDirtyManually() { + if (_watcher != null) _watcher.MarkWorkingCopyDirtyManually(); + } + public void NavigateToCommit(string sha) { if (_histories != null) { SelectedViewIndex = 0; @@ -357,7 +365,7 @@ namespace SourceGit.ViewModels { } else if (File.Exists(otherMerge)) { mode = "merge"; } else { - await Task.Run(RefreshWorkingCopyChanges); + MarkWorkingCopyDirtyManually(); return; } @@ -394,7 +402,7 @@ namespace SourceGit.ViewModels { } else if (File.Exists(Path.Combine(_gitDir, "MERGE_HEAD"))) { cmd.Args = "merge --abort"; } else { - await Task.Run(RefreshWorkingCopyChanges); + MarkWorkingCopyDirtyManually(); return; } @@ -491,8 +499,6 @@ namespace SourceGit.ViewModels { HasUnsolvedConflict = hasUnsolvedConflict; OnPropertyChanged(nameof(WorkingCopyChangesCount)); }); - - _watcher.MarkWorkingCopyRefreshed(); } public void RefreshStashes() { diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 47ef5bd0..9ed133b3 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -246,7 +246,7 @@ namespace SourceGit.ViewModels { await Task.Run(() => new Commands.Add(_repo.FullPath, step).Exec()); } } - _repo.RefreshWorkingCopyChanges(); + _repo.MarkWorkingCopyDirtyManually(); _repo.SetWatcherEnabled(true); IsStaging = false; } @@ -266,7 +266,7 @@ namespace SourceGit.ViewModels { await Task.Run(() => new Commands.Reset(_repo.FullPath, step).Exec()); } } - _repo.RefreshWorkingCopyChanges(); + _repo.MarkWorkingCopyDirtyManually(); _repo.SetWatcherEnabled(true); IsUnstaging = false; } @@ -296,7 +296,7 @@ namespace SourceGit.ViewModels { if (succ) { await Task.Run(() => new Commands.Add(_repo.FullPath, [ctx.Change]).Exec()); } - _repo.RefreshWorkingCopyChanges(); + _repo.MarkWorkingCopyDirtyManually(); _repo.SetWatcherEnabled(true); } } @@ -308,7 +308,7 @@ namespace SourceGit.ViewModels { if (succ) { await Task.Run(() => new Commands.Add(_repo.FullPath, [ctx.Change]).Exec()); } - _repo.RefreshWorkingCopyChanges(); + _repo.MarkWorkingCopyDirtyManually(); _repo.SetWatcherEnabled(true); } } @@ -362,7 +362,7 @@ namespace SourceGit.ViewModels { PopupHost.ShowAndStartPopup(new Push(_repo, null)); } } - _repo.RefreshWorkingCopyChanges(); + _repo.MarkWorkingCopyDirtyManually(); _repo.SetWatcherEnabled(true); IsCommitting = false; } diff --git a/src/Views/TextDiffView.axaml.cs b/src/Views/TextDiffView.axaml.cs index 8c412b04..15e9c1a9 100644 --- a/src/Views/TextDiffView.axaml.cs +++ b/src/Views/TextDiffView.axaml.cs @@ -734,7 +734,7 @@ namespace SourceGit.Views { new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index").Exec(); File.Delete(tmpFile); - repo.RefreshWorkingCopyChanges(); + repo.MarkWorkingCopyDirtyManually(); repo.SetWatcherEnabled(true); e.Handled = true; }; @@ -760,7 +760,7 @@ namespace SourceGit.Views { new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--reverse").Exec(); File.Delete(tmpFile); - repo.RefreshWorkingCopyChanges(); + repo.MarkWorkingCopyDirtyManually(); repo.SetWatcherEnabled(true); e.Handled = true; }; @@ -788,7 +788,7 @@ namespace SourceGit.Views { new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--cache --index --reverse").Exec(); File.Delete(tmpFile); - repo.RefreshWorkingCopyChanges(); + repo.MarkWorkingCopyDirtyManually(); repo.SetWatcherEnabled(true); e.Handled = true; }; @@ -814,7 +814,7 @@ namespace SourceGit.Views { new Commands.Apply(ctx.RepositoryPath, tmpFile, true, "nowarn", "--index --reverse").Exec(); File.Delete(tmpFile); - repo.RefreshWorkingCopyChanges(); + repo.MarkWorkingCopyDirtyManually(); repo.SetWatcherEnabled(true); e.Handled = true; };