feature<TextDiffView>: supports line staging/unstaging in working copy diff view

This commit is contained in:
leo 2024-02-27 21:13:52 +08:00
parent 91ef4e44a4
commit 671e46f8b3
10 changed files with 443 additions and 46 deletions

View file

@ -1,11 +1,12 @@
namespace SourceGit.Commands {
public class Apply : Command {
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode) {
public Apply(string repo, string file, bool ignoreWhitespace, string whitespaceMode, string extra) {
WorkingDirectory = repo;
Context = repo;
Args = "apply ";
if (ignoreWhitespace) Args += "--ignore-whitespace ";
else Args += $"--whitespace={whitespaceMode} ";
if (!string.IsNullOrEmpty(extra)) Args += $"{extra} ";
Args += $"\"{file}\"";
}
}

View file

@ -65,11 +65,11 @@ namespace SourceGit.Commands {
_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, "", ""));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
} else {
if (line.Length == 0) {
ProcessInlineHighlights();
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Normal, "", $"{_oldLine}", $"{_newLine}"));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Normal, "", _oldLine, _newLine));
_oldLine++;
_newLine++;
return;
@ -77,10 +77,10 @@ namespace SourceGit.Commands {
var ch = line[0];
if (ch == '-') {
_deleted.Add(new Models.TextDiffLine(Models.TextDiffLineType.Deleted, line.Substring(1), $"{_oldLine}", ""));
_deleted.Add(new Models.TextDiffLine(Models.TextDiffLineType.Deleted, line.Substring(1), _oldLine, 0));
_oldLine++;
} else if (ch == '+') {
_added.Add(new Models.TextDiffLine(Models.TextDiffLineType.Added, line.Substring(1), "", $"{_newLine}"));
_added.Add(new Models.TextDiffLine(Models.TextDiffLineType.Added, line.Substring(1), 0, _newLine));
_newLine++;
} else if (ch != '\\') {
ProcessInlineHighlights();
@ -88,7 +88,7 @@ namespace SourceGit.Commands {
if (match.Success) {
_oldLine = int.Parse(match.Groups[1].Value);
_newLine = int.Parse(match.Groups[2].Value);
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, "", ""));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Indicator, line, 0, 0));
} else {
if (line.StartsWith(PREFIX_LFS)) {
_result.IsLFS = true;
@ -96,7 +96,7 @@ namespace SourceGit.Commands {
return;
}
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Normal, line.Substring(1), $"{_oldLine}", $"{_newLine}"));
_result.TextDiff.Lines.Add(new Models.TextDiffLine(Models.TextDiffLineType.Normal, line.Substring(1), _oldLine, _newLine));
_oldLine++;
_newLine++;
}

View file

@ -0,0 +1,23 @@
using System.Text.RegularExpressions;
namespace SourceGit.Commands {
public class QueryStagedFileBlobGuid : Command {
private static readonly Regex REG_FORMAT = new Regex(@"^\d+\s+([0-9a-f]+)\s+.*$");
public QueryStagedFileBlobGuid(string repo, string file) {
WorkingDirectory = repo;
Context = repo;
Args = $"ls-files -s -- \"{file}\"";
}
public string Result() {
var rs = ReadToEnd();
var match = REG_FORMAT.Match(rs.StdOut.Trim());
if (match.Success) {
return match.Groups[1].Value;
}
return string.Empty;
}
}
}