enhance: unified all file-path normalization - use char-replace, trim trailing slash

This commit is contained in:
Göran W 2025-06-03 16:45:00 +02:00 committed by leo
parent 54c05ac35a
commit 88c38b4139
No known key found for this signature in database
8 changed files with 15 additions and 17 deletions

View file

@ -157,7 +157,7 @@ namespace SourceGit.Models
if (string.IsNullOrEmpty(e.Name)) if (string.IsNullOrEmpty(e.Name))
return; return;
var name = e.Name.Replace("\\", "/"); var name = e.Name.Replace('\\', '/').TrimEnd('/');
if (name.Contains("fsmonitor--daemon/", StringComparison.Ordinal) || if (name.Contains("fsmonitor--daemon/", StringComparison.Ordinal) ||
name.EndsWith(".lock", StringComparison.Ordinal) || name.EndsWith(".lock", StringComparison.Ordinal) ||
name.StartsWith("lfs/", StringComparison.Ordinal)) name.StartsWith("lfs/", StringComparison.Ordinal))
@ -205,7 +205,7 @@ namespace SourceGit.Models
if (string.IsNullOrEmpty(e.Name)) if (string.IsNullOrEmpty(e.Name))
return; return;
var name = e.Name.Replace("\\", "/"); var name = e.Name.Replace('\\', '/').TrimEnd('/');
if (name.Equals(".git", StringComparison.Ordinal) || if (name.Equals(".git", StringComparison.Ordinal) ||
name.StartsWith(".git/", StringComparison.Ordinal) || name.StartsWith(".git/", StringComparison.Ordinal) ||
name.EndsWith("/.git", StringComparison.Ordinal)) name.EndsWith("/.git", StringComparison.Ordinal))

View file

@ -128,7 +128,7 @@ namespace SourceGit.ViewModels
if (count <= 3) if (count <= 3)
{ {
var submoduleDiff = new Models.SubmoduleDiff(); var submoduleDiff = new Models.SubmoduleDiff();
var submoduleRoot = $"{_repo}/{_option.Path}".Replace("\\", "/"); var submoduleRoot = $"{_repo}/{_option.Path}".Replace('\\', '/').TrimEnd('/');
isSubmodule = true; isSubmodule = true;
for (int i = 1; i < count; i++) for (int i = 1; i < count; i++)
{ {

View file

@ -421,7 +421,7 @@ namespace SourceGit.ViewModels
foreach (var page in Pages) foreach (var page in Pages)
{ {
var id = page.Node.Id.Replace("\\", "/"); var id = page.Node.Id.Replace('\\', '/').TrimEnd('/');
if (id == pageId) if (id == pageId)
{ {
page.Notifications.Add(notification); page.Notifications.Add(notification);

View file

@ -455,9 +455,7 @@ namespace SourceGit.ViewModels
public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode) public RepositoryNode FindOrAddNodeByRepositoryPath(string repo, RepositoryNode parent, bool shouldMoveNode)
{ {
var normalized = repo.Replace('\\', '/'); var normalized = repo.Replace('\\', '/').TrimEnd('/');
if (normalized.EndsWith("/"))
normalized = normalized.TrimEnd('/');
var node = FindNodeRecursive(normalized, RepositoryNodes); var node = FindNodeRecursive(normalized, RepositoryNodes);
if (node == null) if (node == null)

View file

@ -30,7 +30,7 @@ namespace SourceGit.ViewModels
{ {
if (value != null) if (value != null)
{ {
var normalized = value.Replace('\\', '/'); var normalized = value.Replace('\\', '/').TrimEnd('/');
SetProperty(ref _fullpath, normalized); SetProperty(ref _fullpath, normalized);
} }
else else
@ -499,7 +499,7 @@ namespace SourceGit.ViewModels
{ {
// For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR. // For worktrees, we need to watch the $GIT_COMMON_DIR instead of the $GIT_DIR.
var gitDirForWatcher = _gitDir; var gitDirForWatcher = _gitDir;
if (_gitDir.Replace("\\", "/").IndexOf("/worktrees/", StringComparison.Ordinal) > 0) if (_gitDir.Replace('\\', '/').IndexOf("/worktrees/", StringComparison.Ordinal) > 0)
{ {
var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result(); var commonDir = new Commands.QueryGitCommonDir(_fullpath).Result();
if (!string.IsNullOrEmpty(commonDir)) if (!string.IsNullOrEmpty(commonDir))
@ -1387,7 +1387,7 @@ namespace SourceGit.ViewModels
return; return;
var root = Path.GetFullPath(Path.Combine(_fullpath, submodule)); var root = Path.GetFullPath(Path.Combine(_fullpath, submodule));
var normalizedPath = root.Replace("\\", "/"); var normalizedPath = root.Replace('\\', '/').TrimEnd('/');
var node = Preferences.Instance.FindNode(normalizedPath); var node = Preferences.Instance.FindNode(normalizedPath);
if (node == null) if (node == null)

View file

@ -13,7 +13,7 @@ namespace SourceGit.ViewModels
get => _id; get => _id;
set set
{ {
var normalized = value.Replace('\\', '/'); var normalized = value.Replace('\\', '/').TrimEnd('/');
SetProperty(ref _id, normalized); SetProperty(ref _id, normalized);
} }
} }

View file

@ -46,11 +46,11 @@ namespace SourceGit.ViewModels
Dispatcher.UIThread.Invoke(() => Dispatcher.UIThread.Invoke(() =>
{ {
var normalizedRoot = rootDir.FullName.Replace("\\", "/").TrimEnd('/'); var normalizedRoot = rootDir.FullName.Replace('\\', '/').TrimEnd('/');
foreach (var f in found) foreach (var f in found)
{ {
var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace("\\", "/").TrimEnd('/'); var parent = new DirectoryInfo(f.Path).Parent!.FullName.Replace('\\', '/').TrimEnd('/');
if (parent.Equals(normalizedRoot, StringComparison.Ordinal)) if (parent.Equals(normalizedRoot, StringComparison.Ordinal))
{ {
Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false); Preferences.Instance.FindOrAddNodeByRepositoryPath(f.Path, null, false);
@ -93,7 +93,7 @@ namespace SourceGit.ViewModels
CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}..."); CallUIThread(() => ProgressDescription = $"Scanning {subdir.FullName}...");
var normalizedSelf = subdir.FullName.Replace("\\", "/").TrimEnd('/'); var normalizedSelf = subdir.FullName.Replace('\\', '/').TrimEnd('/');
if (_managed.Contains(normalizedSelf)) if (_managed.Contains(normalizedSelf))
continue; continue;
@ -103,7 +103,7 @@ namespace SourceGit.ViewModels
var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd(); var test = new Commands.QueryRepositoryRootPath(subdir.FullName).ReadToEnd();
if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut)) if (test.IsSuccess && !string.IsNullOrEmpty(test.StdOut))
{ {
var normalized = test.StdOut.Trim().Replace("\\", "/").TrimEnd('/'); var normalized = test.StdOut.Trim().Replace('\\', '/').TrimEnd('/');
if (!_managed.Contains(normalized)) if (!_managed.Contains(normalized))
outs.Add(new FoundRepository(normalized, false)); outs.Add(new FoundRepository(normalized, false));
} }

View file

@ -780,7 +780,7 @@ namespace SourceGit.ViewModels
byParentFolder.IsVisible = !isRooted; byParentFolder.IsVisible = !isRooted;
byParentFolder.Click += (_, e) => byParentFolder.Click += (_, e) =>
{ {
var dir = Path.GetDirectoryName(change.Path)!.Replace("\\", "/"); var dir = Path.GetDirectoryName(change.Path)!.Replace('\\', '/').TrimEnd('/');
Commands.GitIgnore.Add(_repo.FullPath, dir + "/"); Commands.GitIgnore.Add(_repo.FullPath, dir + "/");
e.Handled = true; e.Handled = true;
}; };
@ -802,7 +802,7 @@ namespace SourceGit.ViewModels
byExtensionInSameFolder.IsVisible = !isRooted; byExtensionInSameFolder.IsVisible = !isRooted;
byExtensionInSameFolder.Click += (_, e) => byExtensionInSameFolder.Click += (_, e) =>
{ {
var dir = Path.GetDirectoryName(change.Path)!.Replace("\\", "/"); var dir = Path.GetDirectoryName(change.Path)!.Replace('\\', '/').TrimEnd('/');
Commands.GitIgnore.Add(_repo.FullPath, $"{dir}/*{extension}"); Commands.GitIgnore.Add(_repo.FullPath, $"{dir}/*{extension}");
e.Handled = true; e.Handled = true;
}; };