mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature<Cleanup>: add toolbar button to run git gc
and git lfs prune
This commit is contained in:
parent
bc404de937
commit
b04c94ccc1
9 changed files with 103 additions and 1 deletions
21
src/Commands/GC.cs
Normal file
21
src/Commands/GC.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
/// <summary>
|
||||
/// GC
|
||||
/// </summary>
|
||||
public class GC : Command {
|
||||
private Action<string> handler;
|
||||
|
||||
public GC(string repo, Action<string> onProgress) {
|
||||
Cwd = repo;
|
||||
Args = "gc";
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
handler?.Invoke(line);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
|
@ -7,6 +8,21 @@ namespace SourceGit.Commands {
|
|||
public class LFS {
|
||||
private string repo;
|
||||
|
||||
private class PruneCmd : Command {
|
||||
private Action<string> handler;
|
||||
|
||||
public PruneCmd(string repo, Action<string> onProgress) {
|
||||
Cwd = repo;
|
||||
Args = "lfs prune";
|
||||
TraitErrorAsOutput = true;
|
||||
handler = onProgress;
|
||||
}
|
||||
|
||||
public override void OnReadline(string line) {
|
||||
handler?.Invoke(line);
|
||||
}
|
||||
}
|
||||
|
||||
public LFS(string repo) {
|
||||
this.repo = repo;
|
||||
}
|
||||
|
@ -27,5 +43,9 @@ namespace SourceGit.Commands {
|
|||
var rs = cmd.ReadToEnd();
|
||||
return rs.Output.Contains("filter\0lfs");
|
||||
}
|
||||
|
||||
public void Prune(Action<string> onProgress) {
|
||||
new PruneCmd(repo, onProgress).Exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
<Geometry x:Key="Icon.Conflict">M352 64h320L960 352v320L672 960h-320L64 672v-320L352 64zm161 363L344 256 260 341 429 512l-169 171L344 768 513 597 682 768l85-85L598 512l169-171L682 256 513 427z</Geometry>
|
||||
<Geometry x:Key="Icon.Clear">M899 870l-53-306H864c14 0 26-12 26-26V346c0-14-12-26-26-26H618V138c0-14-12-26-26-26H432c-14 0-26 12-26 26v182H160c-14 0-26 12-26 26v192c0 14 12 26 26 26h18l-53 306c0 2 0 3 0 4c0 14 12 26 26 26h723c2 0 3 0 4 0c14-2 24-16 21-30zM204 390h272V182h72v208h272v104H204V390zm468 440V674c0-4-4-8-8-8h-48c-4 0-8 4-8 8v156H416V674c0-4-4-8-8-8h-48c-4 0-8 4-8 8v156H203l45-260H776l45 260H672z</Geometry>
|
||||
<Geometry x:Key="Icon.Error">M512 64C265 64 64 265 64 512s201 448 448 448s448-201 448-448S759 64 512 64zm238 642-46 46L512 558 318 750l-46-46L467 512 274 318l46-46L512 467l194-194 46 46L558 512l193 194z</Geometry>
|
||||
|
||||
<Geometry x:Key="Icon.Clean">M797 829a49 49 0 1049 49 49 49 0 00-49-49zm147-114A49 49 0 10992 764a49 49 0 00-49-49zM928 861a49 49 0 1049 49A49 49 0 00928 861zm-5-586L992 205 851 64l-71 71a67 67 0 00-94 0l235 235a67 67 0 000-94zm-853 128a32 32 0 00-32 50 1291 1291 0 0075 112L288 552c20 0 25 21 8 37l-93 86a1282 1282 0 00120 114l100-32c19-6 28 15 14 34l-40 55c26 19 53 36 82 53a89 89 0 00115-20 1391 1391 0 00256-485l-188-188s-306 224-595 198z</Geometry>
|
||||
|
||||
<Geometry x:Key="Icon.List">M0 33h1024v160H0zM0 432h1024v160H0zM0 831h1024v160H0z</Geometry>
|
||||
<Geometry x:Key="Icon.Tree">M1024 610v-224H640v48H256V224h128V0H0v224h128v752h512v48h384V800H640v48H256V562h384v48z</Geometry>
|
||||
<Geometry x:Key="Icon.Grid">M30 271l241 0 0-241-241 0 0 241zM392 271l241 0 0-241-241 0 0 241zM753 30l0 241 241 0 0-241-241 0zM30 632l241 0 0-241-241 0 0 241zM392 632l241 0 0-241-241 0 0 241zM753 632l241 0 0-241-241 0 0 241zM30 994l241 0 0-241-241 0 0 241zM392 994l241 0 0-241-241 0 0 241zM753 994l241 0 0-241-241 0 0 241z</Geometry>
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
<sys:String x:Key="Text.Dashboard.Refresh">Refresh</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Search">Search Commit</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Statistics">Statistics</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Clean">Cleanup(GC & Prune)</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Configure">Configure this repository</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Workspace">WORKSPACE</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.LocalBranches">LOCAL BRANCHES</sys:String>
|
||||
|
|
|
@ -121,6 +121,7 @@
|
|||
<sys:String x:Key="Text.Dashboard.Refresh">重新加载</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Search">查找提交</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Statistics">提交统计</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Clean">清理本仓库(GC)</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Configure">配置本仓库</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.Workspace">工作区</sys:String>
|
||||
<sys:String x:Key="Text.Dashboard.LocalBranches">本地分支</sys:String>
|
||||
|
|
12
src/Views/Popups/Cleanup.xaml
Normal file
12
src/Views/Popups/Cleanup.xaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
<controls:PopupWidget x:Class="SourceGit.Views.Popups.Cleanup"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="800" Height="100">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</controls:PopupWidget>
|
34
src/Views/Popups/Cleanup.xaml.cs
Normal file
34
src/Views/Popups/Cleanup.xaml.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using System.Threading.Tasks;
|
||||
|
||||
namespace SourceGit.Views.Popups {
|
||||
/// <summary>
|
||||
/// 清理仓库
|
||||
/// </summary>
|
||||
public partial class Cleanup : Controls.PopupWidget {
|
||||
private string repo;
|
||||
|
||||
public Cleanup(string repo) {
|
||||
this.repo = repo;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public override string GetTitle() {
|
||||
return App.Text("Dashboard.Clean");
|
||||
}
|
||||
|
||||
public override Task<bool> Start() {
|
||||
UpdateProgress(GetTitle());
|
||||
|
||||
return Task.Run(() => {
|
||||
Models.Watcher.SetEnabled(repo, false);
|
||||
new Commands.GC(repo, UpdateProgress).Exec();
|
||||
|
||||
var lfs = new Commands.LFS(repo);
|
||||
if (lfs.IsEnabled()) lfs.Prune(UpdateProgress);
|
||||
|
||||
Models.Watcher.SetEnabled(repo, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -122,6 +122,13 @@
|
|||
ToolTip="{DynamicResource Text.Dashboard.Refresh}"
|
||||
Click="TriggerRefresh"/>
|
||||
|
||||
<controls:IconButton
|
||||
Margin="8,0"
|
||||
Padding="0,8"
|
||||
Icon="{DynamicResource Icon.Clean}"
|
||||
ToolTip="{DynamicResource Text.Dashboard.Clean}"
|
||||
Click="OpenCleanup"/>
|
||||
|
||||
<controls:IconButton
|
||||
Margin="8,0"
|
||||
Padding="0,8"
|
||||
|
|
|
@ -413,6 +413,11 @@ namespace SourceGit.Views.Widgets {
|
|||
dialog.ShowDialog();
|
||||
}
|
||||
|
||||
private void OpenCleanup(object sender, RoutedEventArgs e) {
|
||||
new Popups.Cleanup(repo.Path).ShowAndStart();
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OpenConfigure(object sender, RoutedEventArgs e) {
|
||||
new Popups.Configure(repo.Path).Show();
|
||||
e.Handled = true;
|
||||
|
|
Loading…
Reference in a new issue