Change the way to preview binary in CommitViewer

This commit is contained in:
leo 2020-07-13 20:41:17 +08:00
parent 261b4d635c
commit 689b02cd61
3 changed files with 34 additions and 17 deletions

View file

@ -190,19 +190,19 @@ namespace SourceGit.Git {
/// <param name="repo"></param>
/// <param name="file"></param>
/// <returns></returns>
public string GetTextFileContent(Repository repo, string file) {
public string GetTextFileContent(Repository repo, string file, out bool isBinary) {
var data = new List<string>();
var isBinary = false;
var count = 0;
var binary = false;
var errs = repo.RunCommand($"show {SHA}:\"{file}\"", line => {
if (isBinary) return;
if (binary) return;
count++;
if (data.Count >= 1000) return;
if (line.IndexOf('\0') >= 0) {
isBinary = true;
binary = true;
data.Clear();
data.Add("BINARY FILE PREVIEW NOT SUPPORTED!");
return;
@ -211,11 +211,13 @@ namespace SourceGit.Git {
data.Add(line);
});
if (!isBinary && count > 1000) {
if (!binary && count > 1000) {
data.Add("...");
data.Add($"Total {count} lines. Hide {count-1000} lines.");
}
isBinary = binary;
if (errs != null) App.RaiseError(errs);
return string.Join("\n", data);
}