mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-22 12:45:00 +00:00
refactor<*>: rewrite all codes...
This commit is contained in:
parent
89ff8aa744
commit
30ab8ae954
342 changed files with 17208 additions and 19633 deletions
50
src/Commands/QueryFileSizeChange.cs
Normal file
50
src/Commands/QueryFileSizeChange.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System.IO;
|
||||
|
||||
namespace SourceGit.Commands {
|
||||
/// <summary>
|
||||
/// 查询文件大小变化
|
||||
/// </summary>
|
||||
public class QueryFileSizeChange {
|
||||
|
||||
class QuerySizeCmd : Command {
|
||||
public QuerySizeCmd(string repo, string path, string revision) {
|
||||
Cwd = repo;
|
||||
Args = $"cat-file -s {revision}:\"{path}\"";
|
||||
}
|
||||
|
||||
public long Result() {
|
||||
string data = ReadToEnd().Output;
|
||||
long size;
|
||||
if (!long.TryParse(data, out size)) size = 0;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
private Models.FileSizeChange change = new Models.FileSizeChange();
|
||||
|
||||
public QueryFileSizeChange(string repo, string[] revisions, string path, string orgPath) {
|
||||
if (revisions.Length == 0) {
|
||||
change.NewSize = new FileInfo(Path.Combine(repo, path)).Length;
|
||||
change.OldSize = new QuerySizeCmd(repo, path, "HEAD").Result();
|
||||
} else if (revisions.Length == 1) {
|
||||
change.NewSize = new QuerySizeCmd(repo, path, "HEAD").Result();
|
||||
if (string.IsNullOrEmpty(orgPath)) {
|
||||
change.OldSize = new QuerySizeCmd(repo, path, revisions[0]).Result();
|
||||
} else {
|
||||
change.OldSize = new QuerySizeCmd(repo, orgPath, revisions[0]).Result();
|
||||
}
|
||||
} else {
|
||||
change.NewSize = new QuerySizeCmd(repo, path, revisions[0]).Result();
|
||||
if (string.IsNullOrEmpty(orgPath)) {
|
||||
change.OldSize = new QuerySizeCmd(repo, path, revisions[1]).Result();
|
||||
} else {
|
||||
change.OldSize = new QuerySizeCmd(repo, orgPath, revisions[1]).Result();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Models.FileSizeChange Result() {
|
||||
return change;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue