-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathDirHistories.cs
More file actions
101 lines (86 loc) · 2.86 KB
/
DirHistories.cs
File metadata and controls
101 lines (86 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class DirHistories : ObservableObject
{
public string Title
{
get;
}
public bool IsLoading
{
get => _isLoading;
private set => SetProperty(ref _isLoading, value);
}
public List<Models.Commit> Commits
{
get => _commits;
private set => SetProperty(ref _commits, value);
}
public Models.Commit SelectedCommit
{
get => _selectedCommit;
set
{
if (SetProperty(ref _selectedCommit, value))
Detail.Commit = value;
}
}
public CommitDetail Detail
{
get => _detail;
}
public DirHistories(Repository repo, string dir, string revision = null)
{
if (!string.IsNullOrEmpty(revision))
Title = $"{dir} @ {revision}";
else
Title = dir;
_repo = repo;
_detail = new CommitDetail(repo, null);
_detail.SearchChangeFilter = dir;
Task.Run(async () =>
{
var argsBuilder = new StringBuilder();
argsBuilder
.Append("--date-order -n 10000 ")
.Append(revision ?? string.Empty)
.Append(" -- ")
.Append(dir.Quoted());
var commits = await new Commands.QueryCommits(_repo.FullPath, argsBuilder.ToString(), false)
.GetResultAsync()
.ConfigureAwait(false);
Dispatcher.UIThread.Post(() =>
{
Commits = commits;
IsLoading = false;
if (commits.Count > 0)
SelectedCommit = commits[0];
});
});
}
public void NavigateToCommit(Models.Commit commit)
{
_repo.NavigateToCommit(commit.SHA);
}
public string GetCommitFullMessage(Models.Commit commit)
{
var sha = commit.SHA;
if (_cachedCommitFullMessage.TryGetValue(sha, out var msg))
return msg;
msg = new Commands.QueryCommitFullMessage(_repo.FullPath, sha).GetResult();
_cachedCommitFullMessage[sha] = msg;
return msg;
}
private Repository _repo = null;
private bool _isLoading = true;
private List<Models.Commit> _commits = [];
private Models.Commit _selectedCommit = null;
private CommitDetail _detail = null;
private Dictionary<string, string> _cachedCommitFullMessage = new();
}
}