optimize<WorkingCopyChanges>: use reset --hard instead of checkout/clean if all changes be selected to be discard

This commit is contained in:
leo 2023-08-24 17:17:37 +08:00
parent 0a7a0bff42
commit 79b5136a46

View file

@ -384,6 +384,14 @@ namespace SourceGit.Views.Widgets {
IsStaging = false; IsStaging = false;
} }
private void Disard(List<Models.Change> changes) {
if (changes.Count >= Changes.Count) {
new Popups.Discard(repo, null).Show();
} else {
new Popups.Discard(repo, changes).Show();
}
}
private async void SaveAsPatch(string saveTo, List<Models.Change> changes) { private async void SaveAsPatch(string saveTo, List<Models.Change> changes) {
var stream = new FileStream(saveTo, FileMode.Create); var stream = new FileStream(saveTo, FileMode.Create);
var writer = new StreamWriter(stream); var writer = new StreamWriter(stream);
@ -427,7 +435,7 @@ namespace SourceGit.Views.Widgets {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.Discard"); discard.Header = App.Text("FileCM.Discard");
discard.Click += (o, e) => { discard.Click += (o, e) => {
new Popups.Discard(repo, changes).Show(); Disard(changes);
e.Handled = true; e.Handled = true;
}; };
@ -498,7 +506,7 @@ namespace SourceGit.Views.Widgets {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.DiscardMulti", changes.Count); discard.Header = App.Text("FileCM.DiscardMulti", changes.Count);
discard.Click += (o, e) => { discard.Click += (o, e) => {
new Popups.Discard(repo, changes).Show(); Disard(changes);
e.Handled = true; e.Handled = true;
}; };
@ -565,7 +573,7 @@ namespace SourceGit.Views.Widgets {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.Discard"); discard.Header = App.Text("FileCM.Discard");
discard.Click += (o, e) => { discard.Click += (o, e) => {
new Popups.Discard(repo, changes).Show(); Disard(changes);
e.Handled = true; e.Handled = true;
}; };
@ -635,7 +643,7 @@ namespace SourceGit.Views.Widgets {
var discard = new MenuItem(); var discard = new MenuItem();
discard.Header = App.Text("FileCM.DiscardMulti", changes.Count); discard.Header = App.Text("FileCM.DiscardMulti", changes.Count);
discard.Click += (o, e) => { discard.Click += (o, e) => {
new Popups.Discard(repo, changes).Show(); Disard(changes);
e.Handled = true; e.Handled = true;
}; };