2024-04-07 18:57:41 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.Commands
|
|
|
|
|
{
|
2024-04-07 18:57:41 -07:00
|
|
|
|
public static class QueryFileContent
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-07 18:57:41 -07:00
|
|
|
|
public static Stream Run(string repo, string revision, string file)
|
2024-03-17 18:37:06 -07:00
|
|
|
|
{
|
2024-04-07 18:57:41 -07:00
|
|
|
|
var starter = new ProcessStartInfo();
|
|
|
|
|
starter.WorkingDirectory = repo;
|
|
|
|
|
starter.FileName = Native.OS.GitExecutable;
|
|
|
|
|
starter.Arguments = $"show {revision}:\"{file}\"";
|
|
|
|
|
starter.UseShellExecute = false;
|
|
|
|
|
starter.CreateNoWindow = true;
|
|
|
|
|
starter.WindowStyle = ProcessWindowStyle.Hidden;
|
|
|
|
|
starter.RedirectStandardOutput = true;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-04-07 19:24:28 -07:00
|
|
|
|
var stream = new MemoryStream();
|
2024-04-07 18:57:41 -07:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var proc = new Process() { StartInfo = starter };
|
|
|
|
|
proc.Start();
|
|
|
|
|
proc.StandardOutput.BaseStream.CopyTo(stream);
|
|
|
|
|
proc.WaitForExit();
|
|
|
|
|
proc.Close();
|
2021-04-29 05:05:55 -07:00
|
|
|
|
|
2024-04-07 18:57:41 -07:00
|
|
|
|
stream.Position = 0;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
App.RaiseException(repo, $"Failed to query file content: {e}");
|
|
|
|
|
}
|
2024-04-07 19:24:28 -07:00
|
|
|
|
|
|
|
|
|
return stream;
|
2021-04-29 05:05:55 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-31 01:54:29 -07:00
|
|
|
|
}
|