refactor: use existing QueryFileContent command
Some checks are pending
Continuous Integration / Build (push) Waiting to run
Continuous Integration / Prepare version string (push) Waiting to run
Continuous Integration / Package (push) Blocked by required conditions

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-06-04 21:30:08 +08:00
parent ed496a41fb
commit f716c5ee1e
No known key found for this signature in database

View file

@ -13,12 +13,8 @@ namespace SourceGit.Commands
var isLFSFiltered = new IsLFSFiltered(repo, revision, file).Result(); var isLFSFiltered = new IsLFSFiltered(repo, revision, file).Result();
if (isLFSFiltered) if (isLFSFiltered)
{ {
var tmpFile = saveTo + ".tmp"; var pointerStream = QueryFileContent.Run(repo, revision, file);
if (ExecCmd(repo, $"show {revision}:\"{file}\"", tmpFile)) ExecCmd(repo, $"lfs smudge", saveTo, pointerStream);
{
ExecCmd(repo, $"lfs smudge", saveTo, tmpFile);
}
File.Delete(tmpFile);
} }
else else
{ {
@ -26,7 +22,7 @@ namespace SourceGit.Commands
} }
} }
private static bool ExecCmd(string repo, string args, string outputFile, string inputFile = null) private static bool ExecCmd(string repo, string args, string outputFile, Stream input = null)
{ {
var starter = new ProcessStartInfo(); var starter = new ProcessStartInfo();
starter.WorkingDirectory = repo; starter.WorkingDirectory = repo;
@ -45,21 +41,8 @@ namespace SourceGit.Commands
{ {
var proc = new Process() { StartInfo = starter }; var proc = new Process() { StartInfo = starter };
proc.Start(); proc.Start();
if (input != null)
if (inputFile != null) proc.StandardInput.Write(new StreamReader(input).ReadToEnd());
{
using (StreamReader sr = new StreamReader(inputFile))
{
while (true)
{
var line = sr.ReadLine();
if (line == null)
break;
proc.StandardInput.WriteLine(line);
}
}
}
proc.StandardOutput.BaseStream.CopyTo(sw); proc.StandardOutput.BaseStream.CopyTo(sw);
proc.WaitForExit(); proc.WaitForExit();
var rs = proc.ExitCode == 0; var rs = proc.ExitCode == 0;