Skip to content

Commit 66f2aab

Browse files
committed
code_review: review for PR (#147)
* code style * localizations for zh_CN
1 parent e00bc4e commit 66f2aab

File tree

11 files changed

+42
-50
lines changed

11 files changed

+42
-50
lines changed

src/Commands/QueryBranches.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public partial class QueryBranches : Command
88
{
99
private const string PREFIX_LOCAL = "refs/heads/";
1010
private const string PREFIX_REMOTE = "refs/remotes/";
11+
private const string PREFIX_DETACHED = "(HEAD detached at";
1112

1213
[GeneratedRegex(@"^(\d+)\s(\d+)$")]
1314
private static partial Regex REG_AHEAD_BEHIND();
@@ -52,9 +53,9 @@ protected override void OnReadline(string line)
5253
if (refName.EndsWith("/HEAD", StringComparison.Ordinal))
5354
return;
5455

55-
if (refName.StartsWith("(HEAD detached at"))
56+
if (refName.StartsWith(PREFIX_DETACHED, StringComparison.Ordinal))
5657
{
57-
branch.isHead = true;
58+
branch.IsHead = true;
5859
}
5960

6061
if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal))

src/Models/Branch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ public class Branch
1010
public string Upstream { get; set; }
1111
public string UpstreamTrackStatus { get; set; }
1212
public string Remote { get; set; }
13-
public bool isHead { get; set; }
13+
public bool IsHead { get; set; }
1414
}
1515
}

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@
5656
<x:String x:Key="Text.Checkout" xml:space="preserve">Checkout Branch</x:String>
5757
<x:String x:Key="Text.Checkout.Commit" xml:space="preserve">Checkout Commit</x:String>
5858
<x:String x:Key="Text.Checkout.Commit.Warning" xml:space="preserve">Warning: By doing a commit checkout, your Head will be detached</x:String>
59+
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">Commit :</x:String>
5960
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">Branch :</x:String>
60-
<x:String x:Key="Text.Checkout.CommitTarget.Sha" xml:space="preserve">Commit SHA :</x:String>
61-
<x:String x:Key="Text.Checkout.CommitTarget.ShortSha" xml:space="preserve">Commit Short SHA :</x:String>
6261
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">Local Changes :</x:String>
6362
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">Stash &amp; Reapply</x:String>
6463
<x:String x:Key="Text.Checkout.LocalChanges.Discard" xml:space="preserve">Discard</x:String>

src/Resources/Locales/zh_CN.axaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
<x:String x:Key="Text.ChangeDisplayMode.List" xml:space="preserve">列表模式</x:String>
5555
<x:String x:Key="Text.ChangeDisplayMode.Tree" xml:space="preserve">树形模式</x:String>
5656
<x:String x:Key="Text.Checkout" xml:space="preserve">检出(checkout)分支</x:String>
57+
<x:String x:Key="Text.Checkout.Commit" xml:space="preserve">检出(checkout)提交</x:String>
58+
<x:String x:Key="Text.Checkout.Commit.Warning" xml:space="preserve">注意:执行该操作后,当前HEAD会变为游离(detached)状态!</x:String>
59+
<x:String x:Key="Text.Checkout.Commit.Target" xml:space="preserve">提交 :</x:String>
5760
<x:String x:Key="Text.Checkout.Target" xml:space="preserve">目标分支 :</x:String>
5861
<x:String x:Key="Text.Checkout.LocalChanges" xml:space="preserve">未提交更改 :</x:String>
5962
<x:String x:Key="Text.Checkout.LocalChanges.StashAndReply" xml:space="preserve">贮藏(stash)并自动恢复</x:String>
@@ -73,6 +76,7 @@
7376
<x:String x:Key="Text.Clone.RemoteURL" xml:space="preserve">远程仓库 :</x:String>
7477
<x:String x:Key="Text.Close" xml:space="preserve">关闭</x:String>
7578
<x:String x:Key="Text.CommitCM.CherryPick" xml:space="preserve">挑选(cherry-pick)此提交</x:String>
79+
<x:String x:Key="Text.CommitCM.Checkout" xml:space="preserve">检出提交${0}</x:String>
7680
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">复制提交指纹</x:String>
7781
<x:String x:Key="Text.CommitCM.Rebase" xml:space="preserve">变基(rebase)${0}$到此处</x:String>
7882
<x:String x:Key="Text.CommitCM.Reset" xml:space="preserve">重置(reset)${0}$到此处</x:String>

src/SourceGit.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,4 @@
4444
<TrimmerRootAssembly Include="SourceGit" />
4545
<TrimmerRootAssembly Include="Avalonia.Themes.Fluent" />
4646
</ItemGroup>
47-
48-
<ItemGroup>
49-
<Compile Update="Views\CheckoutCommit.axaml.cs">
50-
<DependentUpon>CheckoutCommit.axaml</DependentUpon>
51-
<SubType>Code</SubType>
52-
</Compile>
53-
</ItemGroup>
5447
</Project>

src/ViewModels/BranchTreeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ private void MakeBranchNode(Models.Branch branch, List<BranchTreeNode> roots, Di
223223
lastFolder.Children.Add(new BranchTreeNode()
224224
{
225225
Name = Path.GetFileName(branch.Name),
226-
Type = branch.isHead ? BranchTreeNodeType.DetachedHead : BranchTreeNodeType.Branch,
226+
Type = branch.IsHead ? BranchTreeNodeType.DetachedHead : BranchTreeNodeType.Branch,
227227
Backend = branch,
228228
IsExpanded = false,
229229
IsFiltered = isFiltered,

src/ViewModels/CheckoutCommit.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace SourceGit.ViewModels
44
{
55
public class CheckoutCommit: Popup
66
{
7-
public string Commit
7+
public Models.Commit Commit
88
{
99
get;
1010
private set;
@@ -21,7 +21,7 @@ public bool AutoStash
2121
set => SetProperty(ref _autoStash, value);
2222
}
2323

24-
public CheckoutCommit(Repository repo, string commit)
24+
public CheckoutCommit(Repository repo, Models.Commit commit)
2525
{
2626
_repo = repo;
2727
Commit = commit;
@@ -31,7 +31,7 @@ public CheckoutCommit(Repository repo, string commit)
3131
public override Task<bool> Sure()
3232
{
3333
_repo.SetWatcherEnabled(false);
34-
ProgressDescription = $"Checkout Commit '{Commit}' ...";
34+
ProgressDescription = $"Checkout Commit '{Commit.SHA}' ...";
3535

3636
return Task.Run(() =>
3737
{
@@ -64,7 +64,7 @@ public override Task<bool> Sure()
6464
}
6565

6666
SetProgressDescription("Checkout commit ...");
67-
var rs = new Commands.Checkout(_repo.FullPath).Commit(Commit, SetProgressDescription);
67+
var rs = new Commands.Checkout(_repo.FullPath).Commit(Commit.SHA, SetProgressDescription);
6868

6969
if (needPopStash)
7070
{

src/ViewModels/Histories.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Globalization;
54
using System.Threading.Tasks;
65

76
using Avalonia.Controls;
8-
using Avalonia.Data.Converters;
97
using Avalonia.Platform.Storage;
108
using Avalonia.Threading;
119

@@ -238,15 +236,11 @@ public ContextMenu MakeContextMenu()
238236
menu.Items.Add(reset);
239237

240238
var checkoutCommit = new MenuItem();
241-
242-
var shortSha = Converters.StringConverters.ToShortSHA
243-
.Convert(commit.SHA, typeof(string), null, CultureInfo.CurrentCulture);
244-
245-
checkoutCommit.Header = new Views.NameHighlightedTextBlock("CommitCM.Checkout", shortSha);
239+
checkoutCommit.Header = new Views.NameHighlightedTextBlock("CommitCM.Checkout", commit.SHA.Substring(0, 10));
246240
checkoutCommit.Icon = App.CreateMenuIcon("Icons.Check");
247241
checkoutCommit.Click += (o, e) =>
248242
{
249-
_repo.CheckoutCommit(commit.SHA);
243+
_repo.CheckoutCommit(commit);
250244
e.Handled = true;
251245
};
252246
menu.Items.Add(checkoutCommit);

src/ViewModels/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ public void CheckoutLocalBranch(string branch)
722722
PopupHost.ShowAndStartPopup(new Checkout(this, branch));
723723
}
724724

725-
public void CheckoutCommit(string commit)
725+
public void CheckoutCommit(Models.Commit commit)
726726
{
727727
if (!PopupHost.CanCreatePopup())
728728
return;

src/Views/CheckoutCommit.axaml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,38 @@
1010
<StackPanel Orientation="Vertical" Margin="8,0">
1111
<TextBlock FontSize="18"
1212
Classes="bold"
13-
Text="{DynamicResource Text.Checkout.Commit}"/>
13+
Text="{DynamicResource Text.Checkout.Commit}" />
1414

15-
<TextBlock FontSize="14"
16-
TextWrapping="Wrap"
17-
Classes="italic"
18-
Text="{DynamicResource Text.Checkout.Commit.Warning}"/>
19-
20-
<TextBlock TextWrapping="Wrap" Margin="0,16,0,0">
21-
<TextBlock Classes="bold" Grid.Row="0" Grid.Column="0"
22-
Text="{DynamicResource Text.Checkout.CommitTarget.Sha}"/>
23-
<TextBlock TextWrapping="Wrap" Text="{Binding Commit}"/>
24-
(<TextBlock Classes="italic" TextWrapping="Wrap" Text="{Binding Commit, Converter={x:Static c:StringConverters.ToShortSHA}}"/>)
25-
</TextBlock>
26-
27-
<StackPanel Margin="0, 26, 0, 0" Grid.Row="1" Grid.Column="1" Orientation="Vertical" IsVisible="{Binding HasLocalChanges}">
15+
<TextBlock Margin="0,8,0,16"
16+
Text="{DynamicResource Text.Checkout.Commit.Warning}"
17+
TextWrapping="Wrap"
18+
Foreground="{DynamicResource Brush.FG2}"
19+
FontStyle="Italic"/>
20+
21+
<Grid RowDefinitions="32,Auto" ColumnDefinitions="120,*">
22+
<TextBlock Grid.Row="0" Grid.Column="0"
23+
HorizontalAlignment="Right" VerticalAlignment="Center"
24+
Margin="0,0,8,0"
25+
Text="{DynamicResource Text.Checkout.Commit.Target}" />
26+
<StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
27+
<Path Width="14" Height="14" Margin="0,8,0,0" Data="{StaticResource Icons.Commit}" />
28+
<TextBlock Classes="monospace" Foreground="DarkOrange" VerticalAlignment="Center" Margin="8,0" Text="{Binding Commit.SHA, Converter={x:Static c:StringConverters.ToShortSHA}}" />
29+
<TextBlock Text="{Binding Commit.Subject}"/>
30+
</StackPanel>
31+
2832
<TextBlock Grid.Row="1" Grid.Column="0"
29-
HorizontalAlignment="Left" VerticalAlignment="Center"
33+
HorizontalAlignment="Right" VerticalAlignment="Center"
3034
Margin="0,0,8,0"
31-
Text="{DynamicResource Text.Checkout.LocalChanges}"/>
32-
33-
<StackPanel Margin="0, 13, 0, 0" Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
35+
Text="{DynamicResource Text.Checkout.LocalChanges}"
36+
IsVisible="{Binding HasLocalChanges}"/>
37+
<StackPanel Grid.Row="1" Grid.Column="1" Height="32" Orientation="Horizontal" IsVisible="{Binding HasLocalChanges}">
3438
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.StashAndReply}"
3539
GroupName="LocalChanges"
36-
IsChecked="{Binding AutoStash, Mode=TwoWay}"/>
40+
IsChecked="{Binding AutoStash, Mode=TwoWay}" />
3741
<RadioButton Content="{DynamicResource Text.Checkout.LocalChanges.Discard}"
3842
GroupName="LocalChanges"
39-
Margin="8,0,0,0"/>
43+
Margin="8,0,0,0" />
4044
</StackPanel>
41-
</StackPanel>
42-
43-
45+
</Grid>
4446
</StackPanel>
4547
</UserControl>

0 commit comments

Comments
 (0)