mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 20:24:59 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
44
src/Commands/SaveRevisionFile.cs
Normal file
44
src/Commands/SaveRevisionFile.cs
Normal file
|
@ -0,0 +1,44 @@
|
|||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
/// <summary>
|
||||
/// 保存指定版本的文件
|
||||
/// </summary>
|
||||
public class SaveRevisionFile {
|
||||
private string cwd = "";
|
||||
private string bat = "";
|
||||
|
||||
public SaveRevisionFile(string repo, string path, string sha, string saveTo) {
|
||||
var tmp = Path.GetTempFileName();
|
||||
var cmd = $"\"{Models.Preference.Instance.Git.Path}\" --no-pager ";
|
||||
|
||||
var isLFS = new IsLFSFiltered(repo, path).Result();
|
||||
if (isLFS) {
|
||||
cmd += $"show {sha}:\"{path}\" > {tmp}.lfs\n";
|
||||
cmd += $"\"{Models.Preference.Instance.Git.Path}\" --no-pager lfs smudge < {tmp}.lfs > \"{saveTo}\"\n";
|
||||
} else {
|
||||
cmd += $"show {sha}:\"{path}\" > \"{saveTo}\"\n";
|
||||
}
|
||||
|
||||
cwd = repo;
|
||||
bat = tmp + ".bat";
|
||||
|
||||
File.WriteAllText(bat, cmd);
|
||||
}
|
||||
|
||||
public void Exec() {
|
||||
var starter = new ProcessStartInfo();
|
||||
starter.FileName = bat;
|
||||
starter.WorkingDirectory = cwd;
|
||||
starter.CreateNoWindow = true;
|
||||
starter.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
|
||||
var proc = Process.Start(starter);
|
||||
proc.WaitForExit();
|
||||
proc.Close();
|
||||
|
||||
File.Delete(bat);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue