Skip to content

Commit 88c38b4

Browse files
goran-wlove-linger
authored andcommitted
enhance: unified all file-path normalization - use char-replace, trim trailing slash
1 parent 54c05ac commit 88c38b4

File tree

8 files changed

+15
-17
lines changed

8 files changed

+15
-17
lines changed

src/Models/Watcher.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private void OnRepositoryChanged(object o, FileSystemEventArgs e)
157157
if (string.IsNullOrEmpty(e.Name))
158158
return;
159159

160-
var name = e.Name.Replace("\\", "/");
160+
var name = e.Name.Replace('\\', '/').TrimEnd('/');
161161
if (name.Contains("fsmonitor--daemon/", StringComparison.Ordinal) ||
162162
name.EndsWith(".lock", StringComparison.Ordinal) ||
163163
name.StartsWith("lfs/", StringComparison.Ordinal))
@@ -205,7 +205,7 @@ private void OnWorkingCopyChanged(object o, FileSystemEventArgs e)
205205
if (string.IsNullOrEmpty(e.Name))
206206
return;
207207

208-
var name = e.Name.Replace("\\", "/");
208+
var name = e.Name.Replace('\\', '/').TrimEnd('/');
209209
if (name.Equals(".git", StringComparison.Ordinal) ||
210210
name.StartsWith(".git/", StringComparison.Ordinal) ||
211211
name.EndsWith("/.git", StringComparison.Ordinal))

src/ViewModels/DiffContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private void LoadDiffContent()
128128
if (count <= 3)
129129
{
130130
var submoduleDiff = new Models.SubmoduleDiff();
131-
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/");
131+
var submoduleRoot = $"{_repo}/{_option.Path}".Replace('\\', '/').TrimEnd('/');
132132
isSubmodule = true;
133133
for (int i = 1; i < count; i++)
134134
{

src/ViewModels/Launcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public void DispatchNotification(string pageId, string message, bool isError)
421421

422422
foreach (var page in Pages)
423423
{
424-
var id = page.Node.Id.Replace("\\", "/");
424+
var id = page.Node.Id.Replace('\\', '/').TrimEnd('/');
425425
if (id == pageId)
426426
{
427427
page.Notifications.Add(notification);

src/ViewModels/Preferences.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,7 @@ public RepositoryNode FindNode(string id)
455455

456456
public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode)
457457
{
458-
var normalized = repo.Replace('\\', '/');
459-
if (normalized.EndsWith("/"))
460-
normalized = normalized.TrimEnd('/');
458+
var normalized = repo.Replace('\\', '/').TrimEnd('/');
461459

462460
var node = FindNodeRecursive(normalized, RepositoryNodes);
463461
if (node == null)

src/ViewModels/Repository.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public string FullPath
3030
{
3131
if (value != null)
3232
{
33-
var normalized = value.Replace('\\', '/');
33+
var normalized = value.Replace('\\', '/').TrimEnd('/');
3434
SetProperty(ref _fullpath, normalized);
3535
}
3636
else
@@ -499,7 +499,7 @@ public void Open()
499499
{
500500
// For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR.
501501
var gitDirForWatcher = _gitDir;
502-
if (_gitDir.Replace("\\", "/").IndexOf("/worktrees/", StringComparison.Ordinal) > 0)
502+
if (_gitDir.Replace('\\', '/').IndexOf("/worktrees/", StringComparison.Ordinal) > 0)
503503
{
504504
var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result();
505505
if (!string.IsNullOrEmpty(commonDir))
@@ -1387,7 +1387,7 @@ public void OpenSubmodule(string submodule)
13871387
return;
13881388

13891389
var root = Path.GetFullPath(Path.Combine(_fullpath, submodule));
1390-
var normalizedPath = root.Replace("\\", "/");
1390+
var normalizedPath = root.Replace('\\', '/').TrimEnd('/');
13911391

13921392
var node = Preferences.Instance.FindNode(normalizedPath);
13931393
if (node == null)

src/ViewModels/RepositoryNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public string Id
1313
get => _id;
1414
set
1515
{
16-
var normalized = value.Replace('\\', '/');
16+
var normalized = value.Replace('\\', '/').TrimEnd('/');
1717
SetProperty(ref _id, normalized);
1818
}
1919
}

src/ViewModels/ScanRepositories.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public override Task<bool> Sure()
4646

4747
Dispatcher.UIThread.Invoke(() =>
4848
{
49-
var normalizedRoot = rootDir.FullName.Replace("\\", "/").TrimEnd('/');
49+
var normalizedRoot = rootDir.FullName.Replace('\\', '/').TrimEnd('/');
5050

5151
foreach (var f in found)
5252
{
53-
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/").TrimEnd('/');
53+
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace('\\', '/').TrimEnd('/');
5454
if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
5555
{
5656
Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false);
@@ -93,7 +93,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o
9393

9494
CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}...");
9595

96-
var normalizedSelf = subdir.FullName.Replace("\\", "/").TrimEnd('/');
96+
var normalizedSelf = subdir.FullName.Replace('\\', '/').TrimEnd('/');
9797
if (_managed.Contains(normalizedSelf))
9898
continue;
9999

@@ -103,7 +103,7 @@ private void GetUnmanagedRepositories(DirectoryInfo dir, List<FoundRepository> o
103103
var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd();
104104
if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut))
105105
{
106-
var normalized = test.StdOut.Trim().Replace("\\", "/").TrimEnd('/');
106+
var normalized = test.StdOut.Trim().Replace('\\', '/').TrimEnd('/');
107107
if (!_managed.Contains(normalized))
108108
outs.Add(new FoundRepository(normalized, false));
109109
}

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
780780
byParentFolder.IsVisible = !isRooted;
781781
byParentFolder.Click += (_, e) =>
782782
{
783-
var dir = Path.GetDirectoryName(change.Path)!.Replace("\\", "/");
783+
var dir = Path.GetDirectoryName(change.Path)!.Replace('\\', '/').TrimEnd('/');
784784
Commands.GitIgnore.Add(_repo.FullPath, dir + "/");
785785
e.Handled = true;
786786
};
@@ -802,7 +802,7 @@ public ContextMenu CreateContextMenuForUnstagedChanges()
802802
byExtensionInSameFolder.IsVisible = !isRooted;
803803
byExtensionInSameFolder.Click += (_, e) =>
804804
{
805-
var dir = Path.GetDirectoryName(change.Path)!.Replace("\\", "/");
805+
var dir = Path.GetDirectoryName(change.Path)!.Replace('\\', '/').TrimEnd('/');
806806
Commands.GitIgnore.Add(_repo.FullPath, $"{dir}/*{extension}");
807807
e.Handled = true;
808808
};

0 commit comments

Comments
 (0)