Skip to content

Commit 4d14c79

Browse files
committed
feature: allows to toggle -w option (ignore whitespace changes) while blaming a file (#1838)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 0bf22f5 commit 4d14c79

File tree

6 files changed

+36
-8
lines changed

6 files changed

+36
-8
lines changed

src/Commands/Blame.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ public partial class Blame : Command
1010
[GeneratedRegex(@"^\^?([0-9a-f]+)\s+(.*)\s+\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)")]
1111
private static partial Regex REG_FORMAT();
1212

13-
public Blame(string repo, string file, string revision)
13+
public Blame(string repo, string file, string revision, bool ignoreWhitespace)
1414
{
1515
WorkingDirectory = repo;
1616
Context = repo;
17-
Args = $"blame -f -t {revision} -- {file.Quoted()}";
1817
RaiseError = false;
18+
19+
var builder = new StringBuilder();
20+
builder.Append("blame -f -t ");
21+
if (ignoreWhitespace)
22+
builder.Append("-w ");
23+
builder.Append(revision).Append(" -- ").Append(file.Quoted());
24+
25+
Args = builder.ToString();
1926
}
2027

2128
public async Task<Models.BlameData> ReadAsync()

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<x:String x:Key="Text.Bisect.WaitingForRange">Bisecting. Mark current commit as good or bad and checkout another one.</x:String>
5555
<x:String x:Key="Text.Blame" xml:space="preserve">Blame</x:String>
5656
<x:String x:Key="Text.Blame.BlameOnPreviousRevision" xml:space="preserve">Blame on Previous Revision</x:String>
57+
<x:String x:Key="Text.Blame.IgnoreWhitespace">Ignore whitespace changes</x:String>
5758
<x:String x:Key="Text.Blame.TypeNotSupported" xml:space="preserve">BLAME ON THIS FILE IS NOT SUPPORTED!!!</x:String>
5859
<x:String x:Key="Text.BranchCM.Checkout" xml:space="preserve">Checkout ${0}$...</x:String>
5960
<x:String x:Key="Text.BranchCM.CompareTwo" xml:space="preserve">Compare selected 2 branches</x:String>

src/Resources/Locales/zh_CN.axaml

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

src/Resources/Locales/zh_TW.axaml

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

src/ViewModels/Blame.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public string File
1616
private set => SetProperty(ref _file, value);
1717
}
1818

19+
public bool IgnoreWhitespace
20+
{
21+
get => _ignoreWhitespace;
22+
set
23+
{
24+
if (SetProperty(ref _ignoreWhitespace, value))
25+
SetBlameData(_navigationHistory[0]);
26+
}
27+
}
28+
1929
public Models.Commit Revision
2030
{
2131
get => _revision;
@@ -181,7 +191,7 @@ private void SetBlameData(RevisionInfo rev)
181191

182192
Task.Run(async () =>
183193
{
184-
var result = await new Commands.Blame(_repo, rev.File, rev.SHA)
194+
var result = await new Commands.Blame(_repo, rev.File, rev.SHA, _ignoreWhitespace)
185195
.ReadAsync()
186196
.ConfigureAwait(false);
187197

@@ -207,6 +217,7 @@ public RevisionInfo(string file, string sha)
207217

208218
private string _repo;
209219
private string _file;
220+
private bool _ignoreWhitespace = false;
210221
private Models.Commit _revision;
211222
private Models.Commit _prevRevision;
212223
private CancellationTokenSource _cancellationSource = null;

src/Views/Blame.axaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Icon="/App.ico"
1313
Title="{DynamicResource Text.Blame}"
1414
MinWidth="1280" MinHeight="720">
15-
<Grid RowDefinitions="Auto,24,*">
15+
<Grid RowDefinitions="Auto,28,*,36">
1616
<!-- TitleBar -->
1717
<Grid Grid.Row="0" Height="28" IsVisible="{Binding !#ThisControl.UseSystemWindowFrame}">
1818
<!-- Bottom border -->
@@ -80,23 +80,23 @@
8080
<Button Grid.Column="5"
8181
Classes="icon_button"
8282
IsEnabled="{Binding PrevRevision, Converter={x:Static ObjectConverters.IsNotNull}}"
83-
Width="18" Margin="4,0,0,0"
83+
Width="28" Margin="4,0,0,0"
8484
Command="{Binding GotoPrevRevision}"
8585
ToolTip.Tip="{DynamicResource Text.Blame.BlameOnPreviousRevision}">
86-
<Path Width="12" Height="12" Data="{StaticResource Icons.GotoParent}"/>
86+
<Path Width="14" Height="14" Data="{StaticResource Icons.GotoParent}"/>
8787
</Button>
8888
</Grid>
8989
</Border>
9090

9191
<!-- Body -->
92-
<Grid Grid.Row="2" Background="{DynamicResource Brush.Contents}">
92+
<Grid Grid.Row="2">
9393
<!-- Blame View -->
9494
<v:BlameTextEditor HorizontalScrollBarVisibility="Auto"
9595
VerticalScrollBarVisibility="Auto"
9696
Margin="4,0,4,4"
9797
BorderBrush="{DynamicResource Brush.Border2}"
9898
BorderThickness="1"
99-
Background="Transparent"
99+
Background="{DynamicResource Brush.Contents}"
100100
Foreground="{DynamicResource Brush.FG1}"
101101
FontFamily="{DynamicResource Fonts.Monospace}"
102102
FontSize="{Binding Source={x:Static vm:Preferences.Instance}, Path=EditorFontSize}"
@@ -123,5 +123,12 @@
123123
<!-- Loading -->
124124
<v:LoadingIcon Width="48" Height="48" IsVisible="{Binding Data, Converter={x:Static ObjectConverters.IsNull}}"/>
125125
</Grid>
126+
127+
<!-- Option -->
128+
<Grid Grid.Row="3" Margin="8,0" Height="32" VerticalAlignment="Top">
129+
<CheckBox Content="{DynamicResource Text.Blame.IgnoreWhitespace}"
130+
IsChecked="{Binding IgnoreWhitespace, Mode=TwoWay}"
131+
ToolTip.Tip="-w"/>
132+
</Grid>
126133
</Grid>
127134
</v:ChromelessWindow>

0 commit comments

Comments
 (0)