Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/Commands/QueryCommitStatistic.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SourceGit.Commands
{
public partial class QueryCommitStatistic : Command
{
[GeneratedRegex(@"(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?")]
private static partial Regex REG_SHORTSTAT();

public QueryCommitStatistic(string repo, string parentRevision, string targetRevision)
{
WorkingDirectory = repo;
Context = repo;
Args = $"--no-optional-locks diff --shortstat --no-color {parentRevision} {targetRevision}";
}

public async Task<(int files, int added, int deleted)> GetResultAsync()
{
var rs = await ReadToEndAsync().ConfigureAwait(false);
if (!rs.IsSuccess || string.IsNullOrWhiteSpace(rs.StdOut))
return (0, 0, 0);

var files = 0;
var added = 0;
var deleted = 0;

var match = REG_SHORTSTAT().Match(rs.StdOut.Trim());
if (match.Success)
{
if (match.Groups[1].Success)
files = int.Parse(match.Groups[1].Value);
if (match.Groups[2].Success)
added = int.Parse(match.Groups[2].Value);
if (match.Groups[3].Success)
deleted = int.Parse(match.Groups[3].Value);
}

return (files, added, deleted);
}
}
}
2 changes: 2 additions & 0 deletions src/Resources/Locales/en_US.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@
<x:String x:Key="Text.CommitCM.SaveAsPatch" xml:space="preserve">Save as Patch...</x:String>
<x:String x:Key="Text.CommitDetail.Changes" xml:space="preserve">CHANGES</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Count" xml:space="preserve">changed file(s)</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Added" xml:space="preserve">added</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Deleted" xml:space="preserve">deleted</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Search" xml:space="preserve">Search Changes...</x:String>
<x:String x:Key="Text.CommitDetail.CollapseToBottom" xml:space="preserve">Collapse details</x:String>
<x:String x:Key="Text.CommitDetail.Files" xml:space="preserve">FILES</x:String>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Locales/zh_CN.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@
<x:String x:Key="Text.CommitCM.Revert" xml:space="preserve">回滚此提交...</x:String>
<x:String x:Key="Text.CommitCM.SaveAsPatch" xml:space="preserve">另存为补丁...</x:String>
<x:String x:Key="Text.CommitDetail.Changes" xml:space="preserve">变更对比</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Added" xml:space="preserve">新增</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Count" xml:space="preserve">个文件发生变更</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Deleted" xml:space="preserve">删除</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Search" xml:space="preserve">查找变更...</x:String>
<x:String x:Key="Text.CommitDetail.CollapseToBottom" xml:space="preserve">折叠详细面板</x:String>
<x:String x:Key="Text.CommitDetail.Files" xml:space="preserve">文件列表</x:String>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Locales/zh_TW.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@
<x:String x:Key="Text.CommitCM.Revert" xml:space="preserve">復原此提交...</x:String>
<x:String x:Key="Text.CommitCM.SaveAsPatch" xml:space="preserve">另存為修補檔 (patch)...</x:String>
<x:String x:Key="Text.CommitDetail.Changes" xml:space="preserve">變更對比</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Added" xml:space="preserve">新增</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Count" xml:space="preserve">個檔案已變更</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Deleted" xml:space="preserve">刪除</x:String>
<x:String x:Key="Text.CommitDetail.Changes.Search" xml:space="preserve">搜尋變更...</x:String>
<x:String x:Key="Text.CommitDetail.CollapseToBottom" xml:space="preserve">收合詳細面板</x:String>
<x:String x:Key="Text.CommitDetail.Files" xml:space="preserve">檔案列表</x:String>
Expand Down
30 changes: 30 additions & 0 deletions src/ViewModels/CommitDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ public List<Models.Change> SelectedChanges
}
}

public int TotalAddedLines
{
get => _totalAddedLines;
set => SetProperty(ref _totalAddedLines, value);
}

public int TotalDeletedLines
{
get => _totalDeletedLines;
set => SetProperty(ref _totalDeletedLines, value);
}

public DiffContext DiffContext
{
get => _diffContext;
Expand Down Expand Up @@ -543,6 +555,22 @@ private void Refresh()
});
}
}, token);

Task.Run(async () =>
{
var (_, added, deleted) = await new Commands.QueryCommitStatistic(_repo.FullPath, _commit.FirstParentToCompare, _commit.SHA)
.GetResultAsync()
.ConfigureAwait(false);

if (!token.IsCancellationRequested)
{
Dispatcher.UIThread.Post(() =>
{
TotalAddedLines = added;
TotalDeletedLines = deleted;
});
}
}, token);
}

private async Task<Models.InlineElementCollector> ParseInlinesInMessageAsync(string message)
Expand Down Expand Up @@ -750,5 +778,7 @@ private async Task SetViewingCommitAsync(Models.Object file)
private List<string> _revisionFileSearchSuggestion = null;
private bool _canOpenRevisionFileWithDefaultEditor = false;
private Vector _scrollOffset = Vector.Zero;
private int _totalAddedLines = 0;
private int _totalDeletedLines = 0;
}
}
32 changes: 26 additions & 6 deletions src/Views/CommitChanges.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,32 @@

<!-- Summary -->
<Border Grid.Row="2" BorderBrush="{DynamicResource Brush.Border2}" BorderThickness="1,0,1,1" Background="Transparent">
<TextBlock Margin="4,0,0,0"
Foreground="{DynamicResource Brush.FG2}"
HorizontalAlignment="Left" VerticalAlignment="Center">
<Run Text="{Binding Changes.Count, Mode=OneWay}" FontWeight="Bold"/>
<Run Text="{DynamicResource Text.CommitDetail.Changes.Count}"/>
</TextBlock>
<Grid Margin="4,0,0,0" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>

<TextBlock Grid.Column="0"
Foreground="{DynamicResource Brush.FG2}"
HorizontalAlignment="Left" VerticalAlignment="Center">
<Run Text="{Binding Changes.Count, Mode=OneWay}" FontWeight="Bold"/>
<Run Text="{DynamicResource Text.CommitDetail.Changes.Count}"/>
</TextBlock>

<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="4,0,4,0" Spacing="6">
<TextBlock Foreground="Green" VerticalAlignment="Center">
<Run Text="+" FontWeight="Bold"/>
<Run Text="{Binding TotalAddedLines}" FontWeight="Bold"/>
<Run Text="{DynamicResource Text.CommitDetail.Changes.Added}"/>
</TextBlock>
<TextBlock Foreground="Red" VerticalAlignment="Center">
<Run Text="-" FontWeight="Bold"/>
<Run Text="{Binding TotalDeletedLines}" FontWeight="Bold"/>
<Run Text="{DynamicResource Text.CommitDetail.Changes.Deleted}"/>
</TextBlock>
</StackPanel>
</Grid>
</Border>
</Grid>

Expand Down