mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-21 05:10:25 +08:00
code_style: move some codes from App to Models.InteractiveRebaseJobCollection
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -6,7 +6,6 @@ using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@@ -488,23 +487,7 @@ namespace SourceGit
|
||||
|
||||
using var stream = File.OpenRead(jobsFile);
|
||||
var collection = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.InteractiveRebaseJobCollection);
|
||||
using var writer = new StreamWriter(file);
|
||||
foreach (var job in collection.Jobs)
|
||||
{
|
||||
var code = job.Action switch
|
||||
{
|
||||
Models.InteractiveRebaseAction.Pick => 'p',
|
||||
Models.InteractiveRebaseAction.Edit => 'e',
|
||||
Models.InteractiveRebaseAction.Reword => 'r',
|
||||
Models.InteractiveRebaseAction.Squash => 's',
|
||||
Models.InteractiveRebaseAction.Fixup => 'f',
|
||||
_ => 'd'
|
||||
};
|
||||
writer.WriteLine($"{code} {job.SHA}");
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
|
||||
collection.WriteTodoList(file);
|
||||
exitCode = 0;
|
||||
return true;
|
||||
}
|
||||
@@ -535,27 +518,8 @@ namespace SourceGit
|
||||
var onto = File.ReadAllText(ontoFile).Trim();
|
||||
using var stream = File.OpenRead(jobsFile);
|
||||
var collection = JsonSerializer.Deserialize(stream, JsonCodeGen.Default.InteractiveRebaseJobCollection);
|
||||
if (!collection.Onto.Equals(onto) || !collection.OrigHead.Equals(origHead))
|
||||
return true;
|
||||
|
||||
var done = File.ReadAllText(doneFile).Trim().Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
||||
if (done.Length == 0)
|
||||
return true;
|
||||
|
||||
var current = done[^1].Trim();
|
||||
var match = REG_REBASE_TODO().Match(current);
|
||||
if (!match.Success)
|
||||
return true;
|
||||
|
||||
var sha = match.Groups[1].Value;
|
||||
foreach (var job in collection.Jobs)
|
||||
{
|
||||
if (job.SHA.StartsWith(sha))
|
||||
{
|
||||
File.WriteAllText(file, job.Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (collection.Onto.StartsWith(onto, StringComparison.OrdinalIgnoreCase) && collection.OrigHead.StartsWith(origHead, StringComparison.OrdinalIgnoreCase))
|
||||
collection.WriteCommitMessage(doneFile, file);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -806,9 +770,6 @@ namespace SourceGit
|
||||
return trimmed.Count > 0 ? string.Join(',', trimmed) : string.Empty;
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^[a-z]+\s+([a-fA-F0-9]{4,64})(\s+.*)?$")]
|
||||
private static partial Regex REG_REBASE_TODO();
|
||||
|
||||
private Models.IpcChannel _ipcChannel = null;
|
||||
private ViewModels.Launcher _launcher = null;
|
||||
private ResourceDictionary _activeLocale = null;
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
@@ -34,10 +37,55 @@ namespace SourceGit.Models
|
||||
public string Message { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class InteractiveRebaseJobCollection
|
||||
public partial class InteractiveRebaseJobCollection
|
||||
{
|
||||
public string OrigHead { get; set; } = string.Empty;
|
||||
public string Onto { get; set; } = string.Empty;
|
||||
public List<InteractiveRebaseJob> Jobs { get; set; } = new List<InteractiveRebaseJob>();
|
||||
|
||||
public void WriteTodoList(string todoFile)
|
||||
{
|
||||
using var writer = new StreamWriter(todoFile);
|
||||
foreach (var job in Jobs)
|
||||
{
|
||||
var code = job.Action switch
|
||||
{
|
||||
InteractiveRebaseAction.Pick => 'p',
|
||||
InteractiveRebaseAction.Edit => 'e',
|
||||
InteractiveRebaseAction.Reword => 'r',
|
||||
InteractiveRebaseAction.Squash => 's',
|
||||
InteractiveRebaseAction.Fixup => 'f',
|
||||
_ => 'd'
|
||||
};
|
||||
writer.WriteLine($"{code} {job.SHA}");
|
||||
}
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
|
||||
public void WriteCommitMessage(string doneFile, string msgFile)
|
||||
{
|
||||
var done = File.ReadAllText(doneFile).Trim().Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
|
||||
if (done.Length == 0)
|
||||
return;
|
||||
|
||||
var current = done[^1].Trim();
|
||||
var match = REG_REBASE_TODO().Match(current);
|
||||
if (!match.Success)
|
||||
return;
|
||||
|
||||
var sha = match.Groups[1].Value;
|
||||
foreach (var job in Jobs)
|
||||
{
|
||||
if (job.SHA.StartsWith(sha))
|
||||
{
|
||||
File.WriteAllText(msgFile, job.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[GeneratedRegex(@"^[a-z]+\s+([a-fA-F0-9]{4,64})(\s+.*)?$")]
|
||||
private static partial Regex REG_REBASE_TODO();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user