feature: allows to toggle -w option (ignore whitespace changes) while blaming a file (#1838)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-01-21 12:01:07 +08:00
parent 0bf22f5f76
commit 4d14c79a19
6 changed files with 36 additions and 8 deletions

View File

@@ -10,12 +10,19 @@ namespace SourceGit.Commands
[GeneratedRegex(@"^\^?([0-9a-f]+)\s+(.*)\s+\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)")]
private static partial Regex REG_FORMAT();
public Blame(string repo, string file, string revision)
public Blame(string repo, string file, string revision, bool ignoreWhitespace)
{
WorkingDirectory = repo;
Context = repo;
Args = $"blame -f -t {revision} -- {file.Quoted()}";
RaiseError = false;
var builder = new StringBuilder();
builder.Append("blame -f -t ");
if (ignoreWhitespace)
builder.Append("-w ");
builder.Append(revision).Append(" -- ").Append(file.Quoted());
Args = builder.ToString();
}
public async Task<Models.BlameData> ReadAsync()

View File

@@ -54,6 +54,7 @@
<x:String x:Key="Text.Bisect.WaitingForRange">Bisecting. Mark current commit as good or bad and checkout another one.</x:String>
<x:String x:Key="Text.Blame" xml:space="preserve">Blame</x:String>
<x:String x:Key="Text.Blame.BlameOnPreviousRevision" xml:space="preserve">Blame on Previous Revision</x:String>
<x:String x:Key="Text.Blame.IgnoreWhitespace">Ignore whitespace changes</x:String>
<x:String x:Key="Text.Blame.TypeNotSupported" xml:space="preserve">BLAME ON THIS FILE IS NOT SUPPORTED!!!</x:String>
<x:String x:Key="Text.BranchCM.Checkout" xml:space="preserve">Checkout ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.CompareTwo" xml:space="preserve">Compare selected 2 branches</x:String>

View File

@@ -58,6 +58,7 @@
<x:String x:Key="Text.Bisect.WaitingForRange">二分定位进行中。请标记当前的提交是 '正确' 还是 '错误',然后检出另一个提交。</x:String>
<x:String x:Key="Text.Blame" xml:space="preserve">逐行追溯(blame)</x:String>
<x:String x:Key="Text.Blame.BlameOnPreviousRevision" xml:space="preserve">对当前版本的前一版本执行逐行追溯操作</x:String>
<x:String x:Key="Text.Blame.IgnoreWhitespace">忽略空白符变化</x:String>
<x:String x:Key="Text.Blame.TypeNotSupported" xml:space="preserve">选中文件不支持该操作!!!</x:String>
<x:String x:Key="Text.BranchCM.Checkout" xml:space="preserve">检出(checkout) ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.CompareTwo" xml:space="preserve">比较选中的 2 个分支</x:String>

View File

@@ -58,6 +58,7 @@
<x:String x:Key="Text.Bisect.WaitingForRange">二分搜尋進行中。請標記目前的提交為「良好」或「錯誤」,然後簽出另一個提交。</x:String>
<x:String x:Key="Text.Blame" xml:space="preserve">逐行溯源 (blame)</x:String>
<x:String x:Key="Text.Blame.BlameOnPreviousRevision" xml:space="preserve">對上一個版本執行逐行溯源</x:String>
<x:String x:Key="Text.Blame.IgnoreWhitespace">忽略空白符號變化</x:String>
<x:String x:Key="Text.Blame.TypeNotSupported" xml:space="preserve">所選擇的檔案不支援該操作!</x:String>
<x:String x:Key="Text.BranchCM.Checkout" xml:space="preserve">簽出 (checkout) ${0}$...</x:String>
<x:String x:Key="Text.BranchCM.CompareTwo" xml:space="preserve">比較所選的 2 個分支</x:String>

View File

@@ -16,6 +16,16 @@ namespace SourceGit.ViewModels
private set => SetProperty(ref _file, value);
}
public bool IgnoreWhitespace
{
get => _ignoreWhitespace;
set
{
if (SetProperty(ref _ignoreWhitespace, value))
SetBlameData(_navigationHistory[0]);
}
}
public Models.Commit Revision
{
get => _revision;
@@ -181,7 +191,7 @@ namespace SourceGit.ViewModels
Task.Run(async () =>
{
var result = await new Commands.Blame(_repo, rev.File, rev.SHA)
var result = await new Commands.Blame(_repo, rev.File, rev.SHA, _ignoreWhitespace)
.ReadAsync()
.ConfigureAwait(false);
@@ -207,6 +217,7 @@ namespace SourceGit.ViewModels
private string _repo;
private string _file;
private bool _ignoreWhitespace = false;
private Models.Commit _revision;
private Models.Commit _prevRevision;
private CancellationTokenSource _cancellationSource = null;

View File

@@ -12,7 +12,7 @@
Icon="/App.ico"
Title="{DynamicResource Text.Blame}"
MinWidth="1280" MinHeight="720">
<Grid RowDefinitions="Auto,24,*">
<Grid RowDefinitions="Auto,28,*,36">
<!-- TitleBar -->
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
<!-- Bottom border -->
@@ -80,23 +80,23 @@
<Button Grid.Column="5"
Classes="icon_button"
IsEnabled="{Binding PrevRevision, Converter={x:Static ObjectConverters.IsNotNull}}"
Width="18" Margin="4,0,0,0"
Width="28" Margin="4,0,0,0"
Command="{Binding GotoPrevRevision}"
ToolTip.Tip="{DynamicResource Text.Blame.BlameOnPreviousRevision}">
<Path Width="12" Height="12" Data="{StaticResource Icons.GotoParent}"/>
<Path Width="14" Height="14" Data="{StaticResource Icons.GotoParent}"/>
</Button>
</Grid>
</Border>
<!-- Body -->
<Grid Grid.Row="2" Background="{DynamicResource Brush.Contents}">
<Grid Grid.Row="2">
<!-- Blame View -->
<v:BlameTextEditor HorizontalScrollBarVisibility="Auto"
VerticalScrollBarVisibility="Auto"
Margin="4,0,4,4"
BorderBrush="{DynamicResource Brush.Border2}"
BorderThickness="1"
Background="Transparent"
Background="{DynamicResource Brush.Contents}"
Foreground="{DynamicResource Brush.FG1}"
FontFamily="{DynamicResource Fonts.Monospace}"
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
@@ -123,5 +123,12 @@
<!-- Loading -->
<v:LoadingIcon Width="48" Height="48" IsVisible="{Binding Data, Converter={x:Static ObjectConverters.IsNull}}"/>
</Grid>
<!-- Option -->
<Grid Grid.Row="3" Margin="8,0" Height="32" VerticalAlignment="Top">
<CheckBox Content="{DynamicResource Text.Blame.IgnoreWhitespace}"
IsChecked="{Binding IgnoreWhitespace, Mode=TwoWay}"
ToolTip.Tip="-w"/>
</Grid>
</Grid>
</v:ChromelessWindow>