mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-23 20:47:25 -08:00
enhance: force using StringComparison.Ordinal
This commit is contained in:
parent
cd2ecb109a
commit
f6eb1281b5
12 changed files with 23 additions and 19 deletions
|
@ -38,7 +38,7 @@ namespace SourceGit.Commands {
|
||||||
if (_result.IsBinary) return;
|
if (_result.IsBinary) return;
|
||||||
if (string.IsNullOrEmpty(line)) return;
|
if (string.IsNullOrEmpty(line)) return;
|
||||||
|
|
||||||
if (line.IndexOf('\0') >= 0) {
|
if (line.IndexOf('\0', StringComparison.Ordinal) >= 0) {
|
||||||
_result.IsBinary = true;
|
_result.IsBinary = true;
|
||||||
_result.LineInfos.Clear();
|
_result.LineInfos.Clear();
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace SourceGit.Commands {
|
||||||
if (output.IsSuccess) {
|
if (output.IsSuccess) {
|
||||||
var lines = output.StdOut.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
var lines = output.StdOut.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (var line in lines) {
|
foreach (var line in lines) {
|
||||||
var idx = line.IndexOf('=');
|
var idx = line.IndexOf('=', StringComparison.Ordinal);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
var key = line.Substring(0, idx).Trim();
|
var key = line.Substring(0, idx).Trim();
|
||||||
var val = line.Substring(idx+1).Trim();
|
var val = line.Substring(idx+1).Trim();
|
||||||
|
|
|
@ -36,14 +36,14 @@ namespace SourceGit.Commands {
|
||||||
|
|
||||||
var branch = new Models.Branch();
|
var branch = new Models.Branch();
|
||||||
var refName = parts[0];
|
var refName = parts[0];
|
||||||
if (refName.EndsWith("/HEAD")) return;
|
if (refName.EndsWith("/HEAD", StringComparison.Ordinal)) return;
|
||||||
|
|
||||||
if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) {
|
if (refName.StartsWith(PREFIX_LOCAL, StringComparison.Ordinal)) {
|
||||||
branch.Name = refName.Substring(PREFIX_LOCAL.Length);
|
branch.Name = refName.Substring(PREFIX_LOCAL.Length);
|
||||||
branch.IsLocal = true;
|
branch.IsLocal = true;
|
||||||
} else if (refName.StartsWith(PREFIX_REMOTE, StringComparison.Ordinal)) {
|
} else if (refName.StartsWith(PREFIX_REMOTE, StringComparison.Ordinal)) {
|
||||||
var name = refName.Substring(PREFIX_REMOTE.Length);
|
var name = refName.Substring(PREFIX_REMOTE.Length);
|
||||||
var shortNameIdx = name.IndexOf('/');
|
var shortNameIdx = name.IndexOf('/', StringComparison.Ordinal);
|
||||||
if (shortNameIdx < 0) return;
|
if (shortNameIdx < 0) return;
|
||||||
|
|
||||||
branch.Remote = name.Substring(0, shortNameIdx);
|
branch.Remote = name.Substring(0, shortNameIdx);
|
||||||
|
|
|
@ -51,7 +51,7 @@ namespace SourceGit.Commands {
|
||||||
current = new Models.Commit();
|
current = new Models.Commit();
|
||||||
line = line.Substring(7);
|
line = line.Substring(7);
|
||||||
|
|
||||||
var decoratorStart = line.IndexOf('(');
|
var decoratorStart = line.IndexOf('(', StringComparison.Ordinal);
|
||||||
if (decoratorStart < 0) {
|
if (decoratorStart < 0) {
|
||||||
current.SHA = line.Trim();
|
current.SHA = line.Trim();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
namespace SourceGit.Models {
|
using System;
|
||||||
|
|
||||||
|
namespace SourceGit.Models {
|
||||||
public enum ChangeViewMode {
|
public enum ChangeViewMode {
|
||||||
List,
|
List,
|
||||||
Grid,
|
Grid,
|
||||||
|
@ -36,12 +38,12 @@
|
||||||
WorkTree = workTree;
|
WorkTree = workTree;
|
||||||
|
|
||||||
if (index == ChangeState.Renamed || workTree == ChangeState.Renamed) {
|
if (index == ChangeState.Renamed || workTree == ChangeState.Renamed) {
|
||||||
var idx = Path.IndexOf('\t');
|
var idx = Path.IndexOf('\t', StringComparison.Ordinal);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
OriginalPath = Path.Substring(0, idx);
|
OriginalPath = Path.Substring(0, idx);
|
||||||
Path = Path.Substring(idx + 1);
|
Path = Path.Substring(idx + 1);
|
||||||
} else {
|
} else {
|
||||||
idx = Path.IndexOf(" -> ");
|
idx = Path.IndexOf(" -> ", StringComparison.Ordinal);
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
OriginalPath = Path.Substring(0, idx);
|
OriginalPath = Path.Substring(0, idx);
|
||||||
Path = Path.Substring(idx + 4);
|
Path = Path.Substring(idx + 4);
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace SourceGit.Models {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void ParseUserAndTime(string data, ref User user, ref ulong time) {
|
public static void ParseUserAndTime(string data, ref User user, ref ulong time) {
|
||||||
var userEndIdx = data.IndexOf('>');
|
var userEndIdx = data.IndexOf('>', StringComparison.Ordinal);
|
||||||
if (userEndIdx < 0) return;
|
if (userEndIdx < 0) return;
|
||||||
|
|
||||||
var timeEndIdx = data.IndexOf(' ', userEndIdx + 2);
|
var timeEndIdx = data.IndexOf(' ', userEndIdx + 2);
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace SourceGit.Models {
|
||||||
if (Caches.ContainsKey(data)) {
|
if (Caches.ContainsKey(data)) {
|
||||||
return Caches[data];
|
return Caches[data];
|
||||||
} else {
|
} else {
|
||||||
var nameEndIdx = data.IndexOf('<');
|
var nameEndIdx = data.IndexOf('<', System.StringComparison.Ordinal);
|
||||||
var name = nameEndIdx >= 2 ? data.Substring(0, nameEndIdx - 1) : string.Empty;
|
var name = nameEndIdx >= 2 ? data.Substring(0, nameEndIdx - 1) : string.Empty;
|
||||||
var email = data.Substring(nameEndIdx + 1);
|
var email = data.Substring(nameEndIdx + 1);
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ namespace SourceGit.Models {
|
||||||
} else if (name.Equals("HEAD", StringComparison.Ordinal) ||
|
} else if (name.Equals("HEAD", StringComparison.Ordinal) ||
|
||||||
name.StartsWith("refs/heads/", StringComparison.Ordinal) ||
|
name.StartsWith("refs/heads/", StringComparison.Ordinal) ||
|
||||||
name.StartsWith("refs/remotes/", StringComparison.Ordinal) ||
|
name.StartsWith("refs/remotes/", StringComparison.Ordinal) ||
|
||||||
name.StartsWith("worktrees/")) {
|
name.StartsWith("worktrees/", StringComparison.Ordinal)) {
|
||||||
_updateBranch = DateTime.Now.AddSeconds(.5).ToFileTime();
|
_updateBranch = DateTime.Now.AddSeconds(.5).ToFileTime();
|
||||||
} else if (name.StartsWith("objects/", StringComparison.Ordinal) || name.Equals("index", StringComparison.Ordinal)) {
|
} else if (name.StartsWith("objects/", StringComparison.Ordinal) || name.Equals("index", StringComparison.Ordinal)) {
|
||||||
_updateWC = DateTime.Now.AddSeconds(1).ToFileTime();
|
_updateWC = DateTime.Now.AddSeconds(1).ToFileTime();
|
||||||
|
|
|
@ -360,14 +360,14 @@ namespace SourceGit.ViewModels {
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = new Commands.QueryFileContent(_repo, _commit.SHA, file.Path).Result();
|
var content = new Commands.QueryFileContent(_repo, _commit.SHA, file.Path).Result();
|
||||||
if (content.StartsWith("version https://git-lfs.github.com/spec/", StringComparison.OrdinalIgnoreCase)) {
|
if (content.StartsWith("version https://git-lfs.github.com/spec/", StringComparison.Ordinal)) {
|
||||||
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
var obj = new Models.RevisionLFSObject() { Object = new Models.LFSObject() };
|
||||||
var lines = content.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
var lines = content.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (lines.Length == 3) {
|
if (lines.Length == 3) {
|
||||||
foreach (var line in lines) {
|
foreach (var line in lines) {
|
||||||
if (line.StartsWith("oid sha256:")) {
|
if (line.StartsWith("oid sha256:", StringComparison.Ordinal)) {
|
||||||
obj.Object.Oid = line.Substring(11);
|
obj.Object.Oid = line.Substring(11);
|
||||||
} else if (line.StartsWith("size ")) {
|
} else if (line.StartsWith("size ", StringComparison.Ordinal)) {
|
||||||
obj.Object.Size = long.Parse(line.Substring(5));
|
obj.Object.Size = long.Parse(line.Substring(5));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels {
|
namespace SourceGit.ViewModels {
|
||||||
|
@ -19,7 +20,7 @@ namespace SourceGit.ViewModels {
|
||||||
var expanded = changes.Count <= 50;
|
var expanded = changes.Count <= 50;
|
||||||
|
|
||||||
foreach (var c in changes) {
|
foreach (var c in changes) {
|
||||||
var sepIdx = c.Path.IndexOf('/');
|
var sepIdx = c.Path.IndexOf('/', StringComparison.Ordinal);
|
||||||
if (sepIdx == -1) {
|
if (sepIdx == -1) {
|
||||||
nodes.Add(new FileTreeNode() {
|
nodes.Add(new FileTreeNode() {
|
||||||
FullPath = c.Path,
|
FullPath = c.Path,
|
||||||
|
@ -80,7 +81,7 @@ namespace SourceGit.ViewModels {
|
||||||
var expanded = files.Count <= 50;
|
var expanded = files.Count <= 50;
|
||||||
|
|
||||||
foreach (var f in files) {
|
foreach (var f in files) {
|
||||||
var sepIdx = f.Path.IndexOf('/');
|
var sepIdx = f.Path.IndexOf('/', StringComparison.Ordinal);
|
||||||
if (sepIdx == -1) {
|
if (sepIdx == -1) {
|
||||||
nodes.Add(new FileTreeNode() {
|
nodes.Add(new FileTreeNode() {
|
||||||
FullPath = f.Path,
|
FullPath = f.Path,
|
||||||
|
@ -139,7 +140,7 @@ namespace SourceGit.ViewModels {
|
||||||
foreach (var node in nodes) {
|
foreach (var node in nodes) {
|
||||||
if (node.FullPath == path) return node;
|
if (node.FullPath == path) return node;
|
||||||
|
|
||||||
if (node.IsFolder && path.StartsWith(node.FullPath + "/")) {
|
if (node.IsFolder && path.StartsWith(node.FullPath + "/", StringComparison.Ordinal)) {
|
||||||
var foundInChildren = SelectByPath(node.Children, path);
|
var foundInChildren = SelectByPath(node.Children, path);
|
||||||
if (foundInChildren != null) {
|
if (foundInChildren != null) {
|
||||||
node.IsExpanded = true;
|
node.IsExpanded = true;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
using Avalonia.Platform.Storage;
|
using Avalonia.Platform.Storage;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
@ -72,7 +73,7 @@ namespace SourceGit.ViewModels {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NavigateTo(string commitSHA) {
|
public void NavigateTo(string commitSHA) {
|
||||||
var commit = _commits.Find(x => x.SHA.StartsWith(commitSHA));
|
var commit = _commits.Find(x => x.SHA.StartsWith(commitSHA, StringComparison.Ordinal));
|
||||||
if (commit != null) {
|
if (commit != null) {
|
||||||
AutoSelectedCommit = commit;
|
AutoSelectedCommit = commit;
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ namespace SourceGit.ViewModels {
|
||||||
var limits = $"-{Preference.Instance.MaxHistoryCommits} ";
|
var limits = $"-{Preference.Instance.MaxHistoryCommits} ";
|
||||||
var validFilters = new List<string>();
|
var validFilters = new List<string>();
|
||||||
foreach (var filter in Filters) {
|
foreach (var filter in Filters) {
|
||||||
if (filter.StartsWith("refs/")) {
|
if (filter.StartsWith("refs/", StringComparison.Ordinal)) {
|
||||||
if (_branches.FindIndex(x => x.FullName == filter) >= 0) validFilters.Add(filter);
|
if (_branches.FindIndex(x => x.FullName == filter) >= 0) validFilters.Add(filter);
|
||||||
} else {
|
} else {
|
||||||
if (_tags.FindIndex(t => t.Name == filter) >= 0) validFilters.Add(filter);
|
if (_tags.FindIndex(t => t.Name == filter) >= 0) validFilters.Add(filter);
|
||||||
|
|
Loading…
Reference in a new issue