optimize<Stash>: new stash push implementation - untracked file will be added before stash

This commit is contained in:
leo 2021-04-30 14:21:52 +08:00
parent c25ea618d0
commit 18df69b703
8 changed files with 108 additions and 91 deletions

View file

@ -62,7 +62,7 @@ namespace SourceGit.Views.Popups {
if (AutoStash) {
var changes = new Commands.LocalChanges(repo).Result();
if (changes.Count > 0) {
if (!new Commands.Stash(repo).Push(null, "NEWBRANCH_AUTO_STASH", true)) {
if (!new Commands.Stash(repo).Push(changes, "NEWBRANCH_AUTO_STASH")) {
return false;
}
} else {

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
namespace SourceGit.Views.Popups {
@ -9,14 +10,14 @@ namespace SourceGit.Views.Popups {
/// </summary>
public partial class Stash : Controls.PopupWidget {
private string repo = null;
private List<string> files = null;
private List<Models.Change> changes = null;
public Stash(string repo, List<string> files) {
public Stash(string repo, List<Models.Change> changes) {
this.repo = repo;
this.files = files;
this.changes = changes;
InitializeComponent();
chkIncludeUntracked.IsEnabled = files == null || files.Count == 0;
chkIncludeUntracked.IsEnabled = changes == null || changes.Count == 0;
}
public override string GetTitle() {
@ -29,15 +30,21 @@ namespace SourceGit.Views.Popups {
return Task.Run(() => {
Models.Watcher.SetEnabled(repo, false);
if (files == null || files.Count == 0) {
new Commands.Stash(repo).Push(null, message, includeUntracked);
} else {
for (int i = 0; i < files.Count; i += 10) {
var count = Math.Min(10, files.Count - i);
var step = files.GetRange(i, count);
new Commands.Stash(repo).Push(step, message, includeUntracked);
if (changes == null || changes.Count == 0) {
changes = new Commands.LocalChanges(repo).Result();
}
var jobs = new List<Models.Change>();
foreach (var c in changes) {
if (c.WorkTree == Models.Change.Status.Added || c.WorkTree == Models.Change.Status.Untracked) {
if (includeUntracked) jobs.Add(c);
} else {
jobs.Add(c);
}
}
new Commands.Stash(repo).Push(changes, message);
Models.Watcher.SetEnabled(repo, true);
return true;
});

View file

@ -27,8 +27,14 @@
<!-- Stashes List Group -->
<Border Grid.Row="0" BorderBrush="{StaticResource Brush.Border0}" BorderThickness="0,0,0,1">
<StackPanel Orientation="Horizontal">
<Path
Margin="4,0"
Width="12" Height="12"
Fill="{StaticResource Brush.FG2}"
Data="{StaticResource Icon.Stashes}"/>
<TextBlock
Margin="6,0,0,0"
Margin="4,0,0,0"
Text="{StaticResource Text.Stashes.Stashes}"
Foreground="{StaticResource Brush.FG2}"
FontWeight="Bold"/>
@ -71,25 +77,19 @@
<!-- Change List Group -->
<Border Grid.Row="2" BorderBrush="{StaticResource Brush.Border0}" BorderThickness="0,1">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal">
<Path
Margin="4,0"
Width="12" Height="12"
Fill="{StaticResource Brush.FG2}"
Data="{StaticResource Icon.File}"/>
<TextBlock
Grid.Column="0"
Margin="6,0,0,0"
Margin="4,0,0,0"
Text="{StaticResource Text.Stashes.Changes}"
Foreground="{StaticResource Brush.FG2}"
FontWeight="Bold"/>
<TextBlock
Grid.Column="1"
Margin="0,0,4,0"
Text="{StaticResource Text.Stashes.Changes.Tip}"
Foreground="{StaticResource Brush.FG2}"
FontFamily="Consolas"
FontSize="10"/>
</Grid>
</StackPanel>
</Border>
<!-- Changed Files -->

View file

@ -306,8 +306,8 @@ namespace SourceGit.Views.Widgets {
}
private async void SaveAsPatch(string saveTo, List<Models.Change> changes) {
FileStream stream = new FileStream(saveTo, FileMode.Create);
StreamWriter writer = new StreamWriter(stream);
var stream = new FileStream(saveTo, FileMode.Create);
var writer = new StreamWriter(stream);
foreach (var c in changes) {
await Task.Run(() => new Commands.SaveChangeToStream(repo, c, writer).Exec());
@ -353,7 +353,7 @@ namespace SourceGit.Views.Widgets {
var stash = new MenuItem();
stash.Header = App.Text("FileCM.Stash");
stash.Click += (o, e) => {
new Popups.Stash(repo, files).Show();
new Popups.Stash(repo, changes).Show();
e.Handled = true;
};
@ -416,7 +416,7 @@ namespace SourceGit.Views.Widgets {
var stash = new MenuItem();
stash.Header = App.Text("FileCM.StashMulti", changes.Count);
stash.Click += (o, e) => {
new Popups.Stash(repo, files).Show();
new Popups.Stash(repo, changes).Show();
e.Handled = true;
};
@ -475,7 +475,7 @@ namespace SourceGit.Views.Widgets {
var stash = new MenuItem();
stash.Header = App.Text("FileCM.Stash");
stash.Click += (o, e) => {
new Popups.Stash(repo, files).Show();
new Popups.Stash(repo, changes).Show();
e.Handled = true;
};
@ -538,7 +538,7 @@ namespace SourceGit.Views.Widgets {
var stash = new MenuItem();
stash.Header = App.Text("FileCM.StashMulti", changes.Count);
stash.Click += (o, e) => {
new Popups.Stash(repo, files).Show();
new Popups.Stash(repo, changes).Show();
e.Handled = true;
};