Skip to content

Commit 21db490

Browse files
committed
code_review: PR #1510
Signed-off-by: leo <[email protected]>
1 parent 71a743c commit 21db490

File tree

3 files changed

+18
-28
lines changed

3 files changed

+18
-28
lines changed

src/Models/Branch.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Text.RegularExpressions;
23

34
namespace SourceGit.Models
45
{
@@ -29,7 +30,7 @@ public enum BranchSortMode
2930
CommitterDate,
3031
}
3132

32-
public class Branch
33+
public partial class Branch
3334
{
3435
public string Name { get; set; }
3536
public string FullName { get; set; }
@@ -44,5 +45,13 @@ public class Branch
4445
public bool IsUpstreamGone { get; set; }
4546

4647
public string FriendlyName => IsLocal ? Name : $"{Remote}/{Name}";
48+
49+
[GeneratedRegex(@"\s+")]
50+
private static partial Regex REG_FIX_NAME();
51+
52+
public static string FixName(string name)
53+
{
54+
return REG_FIX_NAME().Replace(name, "-");
55+
}
4756
}
4857
}

src/ViewModels/CreateBranch.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
3-
using System.Text.RegularExpressions;
43
using System.Threading.Tasks;
54

65
namespace SourceGit.ViewModels
@@ -102,10 +101,10 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
102101
{
103102
if (!creator._allowOverwrite)
104103
{
105-
var fixedName = FixName(name);
104+
var fixedName = Models.Branch.FixName(name);
106105
foreach (var b in creator._repo.Branches)
107106
{
108-
if (b.FriendlyName == fixedName)
107+
if (b.FriendlyName.Equals(fixedName, StringComparison.Ordinal))
109108
return new ValidationResult("A branch with same name already exists!");
110109
}
111110
}
@@ -120,7 +119,7 @@ public override async Task<bool> Sure()
120119
{
121120
_repo.SetWatcherEnabled(false);
122121

123-
var fixedName = FixName(_name);
122+
var fixedName = Models.Branch.FixName(_name);
124123
var log = _repo.CreateLog($"Create Branch '{fixedName}'");
125124
Use(log);
126125

@@ -228,14 +227,6 @@ public override async Task<bool> Sure()
228227
return true;
229228
}
230229

231-
[GeneratedRegex(@"\s+")]
232-
private static partial Regex REG_FIX_NAME();
233-
234-
private static string FixName(string name)
235-
{
236-
return REG_FIX_NAME().Replace(name, "-");
237-
}
238-
239230
private readonly Repository _repo = null;
240231
private string _name = null;
241232
private readonly string _baseOnRevision = null;

src/ViewModels/RenameBranch.cs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22
using System.ComponentModel.DataAnnotations;
3-
using System.Text.RegularExpressions;
43
using System.Threading.Tasks;
54

65
namespace SourceGit.ViewModels
@@ -32,10 +31,10 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
3231
{
3332
if (ctx.ObjectInstance is RenameBranch rename)
3433
{
35-
var fixedName = FixName(name);
34+
var fixedName = Models.Branch.FixName(name);
3635
foreach (var b in rename._repo.Branches)
3736
{
38-
if (b.IsLocal && b != rename.Target && b.Name == fixedName)
37+
if (b.IsLocal && b != rename.Target && b.Name.Equals(fixedName, StringComparison.Ordinal))
3938
{
4039
return new ValidationResult("A branch with same name already exists!!!");
4140
}
@@ -47,8 +46,8 @@ public static ValidationResult ValidateBranchName(string name, ValidationContext
4746

4847
public override async Task<bool> Sure()
4948
{
50-
var fixedName = FixName(_name);
51-
if (fixedName == Target.Name)
49+
var fixedName = Models.Branch.FixName(_name);
50+
if (fixedName.Equals(Target.Name, StringComparison.Ordinal))
5251
return true;
5352

5453
_repo.SetWatcherEnabled(false);
@@ -59,9 +58,8 @@ public override async Task<bool> Sure()
5958

6059
var isCurrent = Target.IsCurrent;
6160
var oldName = Target.FullName;
62-
var succ = await Commands.Branch
63-
.RenameAsync(_repo.FullPath, Target.Name, fixedName, log);
6461

62+
var succ = await Commands.Branch.RenameAsync(_repo.FullPath, Target.Name, fixedName, log);
6563
if (succ)
6664
{
6765
foreach (var filter in _repo.Settings.HistoriesFilters)
@@ -88,14 +86,6 @@ public override async Task<bool> Sure()
8886
return succ;
8987
}
9088

91-
[GeneratedRegex(@"\s+")]
92-
private static partial Regex REG_FIX_NAME();
93-
94-
private static string FixName(string name)
95-
{
96-
return REG_FIX_NAME().Replace(name, "-");
97-
}
98-
9989
private readonly Repository _repo;
10090
private string _name;
10191
}

0 commit comments

Comments
 (0)