mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-11-01 13:13:21 -07:00
Source Generated Regex
This commit is contained in:
parent
f93dec5e6a
commit
c0a079de41
19 changed files with 101 additions and 64 deletions
|
@ -2,9 +2,11 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class AssumeUnchanged {
|
public partial class AssumeUnchanged {
|
||||||
class ViewCommand : Command {
|
partial class ViewCommand : Command {
|
||||||
private static readonly Regex REG = new Regex(@"^(\w)\s+(.+)$");
|
|
||||||
|
[GeneratedRegex(@"^(\w)\s+(.+)$")]
|
||||||
|
private static partial Regex REG();
|
||||||
|
|
||||||
public ViewCommand(string repo) {
|
public ViewCommand(string repo) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -18,7 +20,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG.Match(line);
|
var match = REG().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
if (match.Groups[1].Value == "h") {
|
if (match.Groups[1].Value == "h") {
|
||||||
|
|
|
@ -3,8 +3,10 @@ using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class Blame : Command {
|
public partial class Blame : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^\^?([0-9a-f]+)\s+.*\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)");
|
|
||||||
|
[GeneratedRegex(@"^\^?([0-9a-f]+)\s+.*\((.*)\s+(\d+)\s+[\-\+]?\d+\s+\d+\) (.*)")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
private static readonly DateTime UTC_START = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
private static readonly DateTime UTC_START = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).ToLocalTime();
|
||||||
|
|
||||||
public Blame(string repo, string file, string revision) {
|
public Blame(string repo, string file, string revision) {
|
||||||
|
@ -44,7 +46,7 @@ namespace SourceGit.Commands {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
_content.AppendLine(match.Groups[4].Value);
|
_content.AppendLine(match.Groups[4].Value);
|
||||||
|
|
|
@ -6,7 +6,7 @@ using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class Command {
|
public partial class Command {
|
||||||
public class CancelToken {
|
public class CancelToken {
|
||||||
public bool Requested { get; set; } = false;
|
public bool Requested { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ namespace SourceGit.Commands {
|
||||||
if (e.Data.StartsWith("remote: Counting objects:", StringComparison.Ordinal)) return;
|
if (e.Data.StartsWith("remote: Counting objects:", StringComparison.Ordinal)) return;
|
||||||
if (e.Data.StartsWith("remote: Compressing objects:", StringComparison.Ordinal)) return;
|
if (e.Data.StartsWith("remote: Compressing objects:", StringComparison.Ordinal)) return;
|
||||||
if (e.Data.StartsWith("Filtering content:", StringComparison.Ordinal)) return;
|
if (e.Data.StartsWith("Filtering content:", StringComparison.Ordinal)) return;
|
||||||
if (_progressRegex.IsMatch(e.Data)) return;
|
if (_progressRegex().IsMatch(e.Data)) return;
|
||||||
errs.Add(e.Data);
|
errs.Add(e.Data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -142,6 +142,7 @@ namespace SourceGit.Commands {
|
||||||
|
|
||||||
protected virtual void OnReadline(string line) { }
|
protected virtual void OnReadline(string line) { }
|
||||||
|
|
||||||
private static readonly Regex _progressRegex = new Regex(@"\d+%");
|
[GeneratedRegex(@"\d+%")]
|
||||||
|
private static partial Regex _progressRegex();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,8 +2,9 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class CompareRevisions : Command {
|
public partial class CompareRevisions : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
|
|
||||||
public CompareRevisions(string repo, string start, string end) {
|
public CompareRevisions(string repo, string start, string end) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -18,7 +19,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var change = new Models.Change() { Path = match.Groups[2].Value };
|
var change = new Models.Change() { Path = match.Groups[2].Value };
|
||||||
|
|
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class Diff : Command {
|
public partial class Diff : Command {
|
||||||
private static readonly Regex REG_INDICATOR = new Regex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@");
|
[GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")]
|
||||||
|
private static partial Regex REG_INDICATOR();
|
||||||
private static readonly string PREFIX_LFS_NEW = "+version https://git-lfs.github.com/spec/";
|
private static readonly string PREFIX_LFS_NEW = "+version https://git-lfs.github.com/spec/";
|
||||||
private static readonly string PREFIX_LFS_DEL = "-version https://git-lfs.github.com/spec/";
|
private static readonly string PREFIX_LFS_DEL = "-version https://git-lfs.github.com/spec/";
|
||||||
private static readonly string PREFIX_LFS_MODIFY = " version https://git-lfs.github.com/spec/";
|
private static readonly string PREFIX_LFS_MODIFY = " version https://git-lfs.github.com/spec/";
|
||||||
|
@ -57,7 +58,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_result.TextDiff.Lines.Count == 0) {
|
if (_result.TextDiff.Lines.Count == 0) {
|
||||||
var match = REG_INDICATOR.Match(line);
|
var match = REG_INDICATOR().Match(line);
|
||||||
if (!match.Success) {
|
if (!match.Success) {
|
||||||
if (line.StartsWith("Binary", StringComparison.Ordinal)) _result.IsBinary = true;
|
if (line.StartsWith("Binary", StringComparison.Ordinal)) _result.IsBinary = true;
|
||||||
return;
|
return;
|
||||||
|
@ -96,7 +97,7 @@ namespace SourceGit.Commands {
|
||||||
_newLine++;
|
_newLine++;
|
||||||
} else if (ch != '\\') {
|
} else if (ch != '\\') {
|
||||||
ProcessInlineHighlights();
|
ProcessInlineHighlights();
|
||||||
var match = REG_INDICATOR.Match(line);
|
var match = REG_INDICATOR().Match(line);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
_oldLine = int.Parse(match.Groups[1].Value);
|
_oldLine = int.Parse(match.Groups[1].Value);
|
||||||
_newLine = int.Parse(match.Groups[2].Value);
|
_newLine = int.Parse(match.Groups[2].Value);
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class IsBinary : Command {
|
public partial class IsBinary : Command {
|
||||||
private static readonly Regex REG_TEST = new Regex(@"^\-\s+\-\s+.*$");
|
[GeneratedRegex(@"^\-\s+\-\s+.*$")]
|
||||||
|
private static partial Regex REG_TEST();
|
||||||
|
|
||||||
public IsBinary(string repo, string commit, string path) {
|
public IsBinary(string repo, string commit, string path) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -12,7 +13,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Result() {
|
public bool Result() {
|
||||||
return REG_TEST.IsMatch(ReadToEnd().StdOut);
|
return REG_TEST().IsMatch(ReadToEnd().StdOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,12 @@ using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryBranches : Command {
|
public partial class QueryBranches : Command {
|
||||||
private static readonly string PREFIX_LOCAL = "refs/heads/";
|
private static readonly string PREFIX_LOCAL = "refs/heads/";
|
||||||
private static readonly string PREFIX_REMOTE = "refs/remotes/";
|
private static readonly string PREFIX_REMOTE = "refs/remotes/";
|
||||||
private static readonly Regex REG_AHEAD_BEHIND = new Regex(@"^(\d+)\s(\d+)$");
|
|
||||||
|
[GeneratedRegex(@"^(\d+)\s(\d+)$")]
|
||||||
|
private static partial Regex REG_AHEAD_BEHIND();
|
||||||
|
|
||||||
public QueryBranches(string repo) {
|
public QueryBranches(string repo) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -71,7 +73,7 @@ namespace SourceGit.Commands {
|
||||||
var rs = cmd.ReadToEnd();
|
var rs = cmd.ReadToEnd();
|
||||||
if (!rs.IsSuccess) return string.Empty;
|
if (!rs.IsSuccess) return string.Empty;
|
||||||
|
|
||||||
var match = REG_AHEAD_BEHIND.Match(rs.StdOut);
|
var match = REG_AHEAD_BEHIND().Match(rs.StdOut);
|
||||||
if (!match.Success) return string.Empty;
|
if (!match.Success) return string.Empty;
|
||||||
|
|
||||||
var ahead = int.Parse(match.Groups[1].Value);
|
var ahead = int.Parse(match.Groups[1].Value);
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryCommitChanges : Command {
|
public partial class QueryCommitChanges : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
|
|
||||||
public QueryCommitChanges(string repo, string commitSHA) {
|
public QueryCommitChanges(string repo, string commitSHA) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -18,7 +19,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var change = new Models.Change() { Path = match.Groups[2].Value };
|
var change = new Models.Change() { Path = match.Groups[2].Value };
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryFileSize : Command {
|
public partial class QueryFileSize : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$");
|
|
||||||
|
[GeneratedRegex(@"^\d+\s+\w+\s+[0-9a-f]+\s+(\d+)\s+.*$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
|
|
||||||
public QueryFileSize(string repo, string file, string revision) {
|
public QueryFileSize(string repo, string file, string revision) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -15,7 +17,7 @@ namespace SourceGit.Commands {
|
||||||
|
|
||||||
var rs = ReadToEnd();
|
var rs = ReadToEnd();
|
||||||
if (rs.IsSuccess) {
|
if (rs.IsSuccess) {
|
||||||
var match = REG_FORMAT.Match(rs.StdOut);
|
var match = REG_FORMAT().Match(rs.StdOut);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
return long.Parse(match.Groups[1].Value);
|
return long.Parse(match.Groups[1].Value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@ using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryLocalChanges : Command {
|
public partial class QueryLocalChanges : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
private static readonly string[] UNTRACKED = [ "no", "all" ];
|
private static readonly string[] UNTRACKED = [ "no", "all" ];
|
||||||
|
|
||||||
public QueryLocalChanges(string repo, bool includeUntracked = true) {
|
public QueryLocalChanges(string repo, bool includeUntracked = true) {
|
||||||
|
@ -19,7 +20,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
if (line.EndsWith("/", StringComparison.Ordinal)) return; // Ignore changes with git-worktree
|
if (line.EndsWith("/", StringComparison.Ordinal)) return; // Ignore changes with git-worktree
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryRemotes : Command {
|
public partial class QueryRemotes : Command {
|
||||||
private static readonly Regex REG_REMOTE = new Regex(@"^([\w\.\-]+)\s*(\S+).*$");
|
[GeneratedRegex(@"^([\w\.\-]+)\s*(\S+).*$")]
|
||||||
|
private static partial Regex REG_REMOTE();
|
||||||
|
|
||||||
public QueryRemotes(string repo) {
|
public QueryRemotes(string repo) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -17,7 +18,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_REMOTE.Match(line);
|
var match = REG_REMOTE().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var remote = new Models.Remote() {
|
var remote = new Models.Remote() {
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryRevisionObjects : Command {
|
public partial class QueryRevisionObjects : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+(\w+)\s+([0-9a-f]+)\s+(.*)$");
|
|
||||||
|
[GeneratedRegex(@"^\d+\s+(\w+)\s+([0-9a-f]+)\s+(.*)$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
private List<Models.Object> objects = new List<Models.Object>();
|
private List<Models.Object> objects = new List<Models.Object>();
|
||||||
|
|
||||||
public QueryRevisionObjects(string repo, string sha) {
|
public QueryRevisionObjects(string repo, string sha) {
|
||||||
|
@ -18,7 +20,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var obj = new Models.Object();
|
var obj = new Models.Object();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryStagedFileBlobGuid : Command {
|
public partial class QueryStagedFileBlobGuid : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+([0-9a-f]+)\s+.*$");
|
[GeneratedRegex(@"^\d+\s+([0-9a-f]+)\s+.*$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
|
|
||||||
public QueryStagedFileBlobGuid(string repo, string file) {
|
public QueryStagedFileBlobGuid(string repo, string file) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -12,7 +13,7 @@ namespace SourceGit.Commands {
|
||||||
|
|
||||||
public string Result() {
|
public string Result() {
|
||||||
var rs = ReadToEnd();
|
var rs = ReadToEnd();
|
||||||
var match = REG_FORMAT.Match(rs.StdOut.Trim());
|
var match = REG_FORMAT().Match(rs.StdOut.Trim());
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
return match.Groups[1].Value;
|
return match.Groups[1].Value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryStashChanges : Command {
|
public partial class QueryStashChanges : Command {
|
||||||
private static readonly Regex REG_FORMAT = new Regex(@"^(\s?[\w\?]{1,4})\s+(.+)$");
|
|
||||||
|
[GeneratedRegex(@"^(\s?[\w\?]{1,4})\s+(.+)$")]
|
||||||
|
private static partial Regex REG_FORMAT();
|
||||||
|
|
||||||
public QueryStashChanges(string repo, string sha) {
|
public QueryStashChanges(string repo, string sha) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -17,7 +19,7 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT.Match(line);
|
var match = REG_FORMAT().Match(line);
|
||||||
if (!match.Success) return;
|
if (!match.Success) return;
|
||||||
|
|
||||||
var change = new Models.Change() { Path = match.Groups[2].Value };
|
var change = new Models.Change() { Path = match.Groups[2].Value };
|
||||||
|
|
|
@ -3,8 +3,10 @@ using System.Collections.Generic;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QueryStashes : Command {
|
public partial class QueryStashes : Command {
|
||||||
private static readonly Regex REG_STASH = new Regex(@"^Reflog: refs/(stash@\{\d+\}).*$");
|
|
||||||
|
[GeneratedRegex(@"^Reflog: refs/(stash@\{\d+\}).*$")]
|
||||||
|
private static partial Regex REG_STASH();
|
||||||
|
|
||||||
public QueryStashes(string repo) {
|
public QueryStashes(string repo) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -28,7 +30,7 @@ namespace SourceGit.Commands {
|
||||||
if (_current == null) return;
|
if (_current == null) return;
|
||||||
|
|
||||||
if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal)) {
|
if (line.StartsWith("Reflog: refs/stash@", StringComparison.Ordinal)) {
|
||||||
var match = REG_STASH.Match(line);
|
var match = REG_STASH().Match(line);
|
||||||
if (match.Success) _current.Name = match.Groups[1].Value;
|
if (match.Success) _current.Name = match.Groups[1].Value;
|
||||||
} else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal)) {
|
} else if (line.StartsWith("Reflog message: ", StringComparison.Ordinal)) {
|
||||||
_current.Message = line.Substring(16);
|
_current.Message = line.Substring(16);
|
||||||
|
|
|
@ -2,9 +2,11 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Commands {
|
namespace SourceGit.Commands {
|
||||||
public class QuerySubmodules : Command {
|
public partial class QuerySubmodules : Command {
|
||||||
private readonly Regex REG_FORMAT1 = new Regex(@"^[\-\+ ][0-9a-f]+\s(.*)\s\(.*\)$");
|
[GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)\s\(.*\)$")]
|
||||||
private readonly Regex REG_FORMAT2 = new Regex(@"^[\-\+ ][0-9a-f]+\s(.*)$");
|
private static partial Regex REG_FORMAT1();
|
||||||
|
[GeneratedRegex(@"^[\-\+ ][0-9a-f]+\s(.*)$")]
|
||||||
|
private static partial Regex REG_FORMAT2();
|
||||||
|
|
||||||
public QuerySubmodules(string repo) {
|
public QuerySubmodules(string repo) {
|
||||||
WorkingDirectory = repo;
|
WorkingDirectory = repo;
|
||||||
|
@ -18,13 +20,13 @@ namespace SourceGit.Commands {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnReadline(string line) {
|
protected override void OnReadline(string line) {
|
||||||
var match = REG_FORMAT1.Match(line);
|
var match = REG_FORMAT1().Match(line);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
_submodules.Add(match.Groups[1].Value);
|
_submodules.Add(match.Groups[1].Value);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match = REG_FORMAT2.Match(line);
|
match = REG_FORMAT2().Match(line);
|
||||||
if (match.Success) {
|
if (match.Success) {
|
||||||
_submodules.Add(match.Groups[1].Value);
|
_submodules.Add(match.Groups[1].Value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace SourceGit.Models {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TextDiff {
|
public partial class TextDiff {
|
||||||
public string File { get; set; } = string.Empty;
|
public string File { get; set; } = string.Empty;
|
||||||
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
|
public List<TextDiffLine> Lines { get; set; } = new List<TextDiffLine>();
|
||||||
public int MaxLineNumber = 0;
|
public int MaxLineNumber = 0;
|
||||||
|
@ -282,11 +282,14 @@ namespace SourceGit.Models {
|
||||||
builder.Append("\n");
|
builder.Append("\n");
|
||||||
System.IO.File.WriteAllText(output, builder.ToString());
|
System.IO.File.WriteAllText(output, builder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@")]
|
||||||
|
private static partial Regex indicatorRegex();
|
||||||
|
|
||||||
private bool ProcessIndicatorForPatch(StringBuilder builder, TextDiffLine indicator, int idx, int start, int end, int ignoreRemoves, int ignoreAdds, bool revert, bool tailed) {
|
private bool ProcessIndicatorForPatch(StringBuilder builder, TextDiffLine indicator, int idx, int start, int end, int ignoreRemoves, int ignoreAdds, bool revert, bool tailed) {
|
||||||
var indicatorRegex = new Regex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@");
|
|
||||||
|
|
||||||
var match = indicatorRegex.Match(indicator.Content);
|
var match = indicatorRegex().Match(indicator.Content);
|
||||||
var oldStart = int.Parse(match.Groups[1].Value);
|
var oldStart = int.Parse(match.Groups[1].Value);
|
||||||
var newStart = int.Parse(match.Groups[2].Value) + ignoreRemoves - ignoreAdds;
|
var newStart = int.Parse(match.Groups[2].Value) + ignoreRemoves - ignoreAdds;
|
||||||
var oldCount = 0;
|
var oldCount = 0;
|
||||||
|
@ -336,9 +339,8 @@ namespace SourceGit.Models {
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffLine indicator, int idx, int start, int end, int ignoreRemoves, int ignoreAdds, bool revert, bool isOldSide, bool tailed) {
|
private bool ProcessIndicatorForPatchSingleSide(StringBuilder builder, TextDiffLine indicator, int idx, int start, int end, int ignoreRemoves, int ignoreAdds, bool revert, bool isOldSide, bool tailed) {
|
||||||
var indicatorRegex = new Regex(@"^@@ \-(\d+),?\d* \+(\d+),?\d* @@");
|
|
||||||
|
|
||||||
var match = indicatorRegex.Match(indicator.Content);
|
var match = indicatorRegex().Match(indicator.Content);
|
||||||
var oldStart = int.Parse(match.Groups[1].Value);
|
var oldStart = int.Parse(match.Groups[1].Value);
|
||||||
var newStart = int.Parse(match.Groups[2].Value) + ignoreRemoves - ignoreAdds;
|
var newStart = int.Parse(match.Groups[2].Value) + ignoreRemoves - ignoreAdds;
|
||||||
var oldCount = 0;
|
var oldCount = 0;
|
||||||
|
|
|
@ -1,11 +1,20 @@
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace SourceGit.Models {
|
namespace SourceGit.Models {
|
||||||
public class Remote {
|
public partial class Remote {
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")]
|
||||||
|
private static partial Regex regex1();
|
||||||
|
|
||||||
|
[GeneratedRegex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-\.]+\.git$")]
|
||||||
|
private static partial Regex regex2();
|
||||||
|
[GeneratedRegex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$")]
|
||||||
|
private static partial Regex regex3();
|
||||||
|
|
||||||
private static readonly Regex[] URL_FORMATS = [
|
private static readonly Regex[] URL_FORMATS = [
|
||||||
new Regex(@"^http[s]?://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$"),
|
regex1(),
|
||||||
new Regex(@"^[\w\-]+@[\w\.\-]+(\:[0-9]+)?:[\w\-]+/[\w\-\.]+\.git$"),
|
regex2(),
|
||||||
new Regex(@"^ssh://([\w\-]+@)?[\w\.\-]+(\:[0-9]+)?/[\w\-]+/[\w\-\.]+\.git$"),
|
regex3(),
|
||||||
];
|
];
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
|
@ -3,8 +3,10 @@ using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SourceGit.ViewModels {
|
namespace SourceGit.ViewModels {
|
||||||
public class InitGitFlow : Popup {
|
public partial class InitGitFlow : Popup {
|
||||||
private static readonly Regex TAG_PREFIX = new Regex(@"^[\w\-/\.]+$");
|
|
||||||
|
[GeneratedRegex(@"^[\w\-/\.]+$")]
|
||||||
|
private static partial Regex TAG_PREFIX();
|
||||||
|
|
||||||
[Required(ErrorMessage = "Master branch name is required!!!")]
|
[Required(ErrorMessage = "Master branch name is required!!!")]
|
||||||
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
|
[RegularExpression(@"^[\w\-/\.]+$", ErrorMessage = "Bad branch name format!")]
|
||||||
|
@ -63,7 +65,7 @@ namespace SourceGit.ViewModels {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ValidationResult ValidateTagPrefix(string tagPrefix, ValidationContext ctx) {
|
public static ValidationResult ValidateTagPrefix(string tagPrefix, ValidationContext ctx) {
|
||||||
if (!string.IsNullOrWhiteSpace(tagPrefix) && !TAG_PREFIX.IsMatch(tagPrefix)) {
|
if (!string.IsNullOrWhiteSpace(tagPrefix) && !TAG_PREFIX().IsMatch(tagPrefix)) {
|
||||||
return new ValidationResult("Bad tag prefix format!");
|
return new ValidationResult("Bad tag prefix format!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue