/
vasiukoff
/
sg
Обзор
Документация
Войти
/
vasiukoff
/
sg
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/Commands/QueryFileContent.cs
68 строк
3 KB
leo
code_style: remove warnings reported by JetBrains Rider
21 авг 2025, 18:38
21 авг 2025, 18:38
a2f47df
Код
Авторство
О чём код?
using System; using System.Diagnostics; using System.IO; using System.Threading.Tasks; namespace SourceGit.Commands { public static class QueryFileContent { public static async Task<Stream> RunAsync(string repo, string revision, string file) { var starter = new ProcessStartInfo(); starter.WorkingDirectory = repo; starter.FileName = Native.OS.GitExecutable; starter.Arguments = $"show {revision}:{file.Quoted()}"; starter.UseShellExecute = false; starter.CreateNoWindow = true; starter.WindowStyle = ProcessWindowStyle.Hidden; starter.RedirectStandardOutput = true; var stream = new MemoryStream(); try { using var proc = Process.Start(starter)!; await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false); await proc.WaitForExitAsync().ConfigureAwait(false); } catch (Exception e) { App.RaiseException(repo, $"Failed to query file content: {e}"); } stream.Position = 0; return stream; } public static async Task<Stream> FromLFSAsync(string repo, string oid, long size) { var starter = new ProcessStartInfo(); starter.WorkingDirectory = repo; starter.FileName = Native.OS.GitExecutable; starter.Arguments = "lfs smudge"; starter.UseShellExecute = false; starter.CreateNoWindow = true; starter.WindowStyle = ProcessWindowStyle.Hidden; starter.RedirectStandardInput = true; starter.RedirectStandardOutput = true; var stream = new MemoryStream(); try { using var proc = Process.Start(starter)!; await proc.StandardInput.WriteLineAsync("version https://git-lfs.github.com/spec/v1").ConfigureAwait(false); await proc.StandardInput.WriteLineAsync($"oid sha256:{oid}").ConfigureAwait(false); await proc.StandardInput.WriteLineAsync($"size {size}").ConfigureAwait(false); await proc.StandardOutput.BaseStream.CopyToAsync(stream).ConfigureAwait(false); await proc.WaitForExitAsync().ConfigureAwait(false); } catch (Exception e) { App.RaiseException(repo, $"Failed to query file content: {e}"); } stream.Position = 0; return stream; } } }