public ContributorsModel GetContributors(String path) { var cfg = UserConfiguration.Current; if (!cfg.AllowContributors) { return(null); } var commit = GetCommitByPath(ref path, out var referenceName); if (commit == null) { return(null); } var contributorsAccessor = GitCacheAccessor.Singleton(new ContributorsAccessor(_repoId, _repository, commit)); var contributors = contributorsAccessor.Result.Value; contributors.OrderedCommits = contributors.OrderedCommits .Take(UserConfiguration.Current.Contributors) .ToArray(); var statistics = new RepositoryStatisticsModel { Current = contributors }; statistics.Current.Branch = referenceName; if (_repository.Head.Tip != commit) { contributorsAccessor = GitCacheAccessor.Singleton(new ContributorsAccessor(_repoId, _repository, _repository.Head.Tip)); statistics.Default = contributorsAccessor.Result.Value; statistics.Default.Branch = _repository.Head.FriendlyName; } var key = CalcBranchesKey(true); var repositorySizeAccessor = GitCacheAccessor.Singleton(new RepositorySizeAccessor(_repoId, _repository, key)); statistics.RepositorySize = repositorySizeAccessor.Result.Value; var model = new ContributorsModel { Name = Name, Statistics = statistics, }; return(model); }
public Information(MainViewModel viewModel) { this.viewModel = viewModel; InitializeComponent(); DataContext = new ContributorsModel(); }
public ContributorsModel GetContributors(string path) { string referenceName; var commit = GetCommitByPath(ref path, out referenceName); if (commit == null) { return(null); } var ancestors = _repository.Commits .QueryBy(new CommitFilter { Since = commit }); var contributors = GitCache.Get <ContributorCommitsModel[]>(commit.Sha, "contributors"); if (contributors == null) { contributors = ancestors.GroupBy(s => s.Author.ToString()) .Select(s => new ContributorCommitsModel { Author = s.Key, CommitsCount = s.Count(), }) .OrderByDescending(s => s.CommitsCount) .ThenBy(s => s.Author, new StringLogicalComparer()) .ToArray(); GitCache.Set(commit.Sha, "contributors", contributors); } var statistics = new RepositoryStatisticsModel(); var stats = GitCache.Get <RepositoryStatisticsModel.Statistics>(commit.Sha, "statistics"); int size; if (stats == null) { stats = new RepositoryStatisticsModel.Statistics { Branch = referenceName, Commits = ancestors.Count(), Contributors = ancestors.Select(s => s.Author.ToString()).Distinct().Count(), Files = FilesInCommit(commit, out size), SourceSize = size, }; GitCache.Set(commit.Sha, "statistics", stats); } statistics.Current = stats; if (_repository.Head.Tip != commit) { commit = _repository.Head.Tip; stats = GitCache.Get <RepositoryStatisticsModel.Statistics>(commit.Sha, "statistics"); if (stats == null) { ancestors = _repository.Commits.QueryBy(new CommitFilter { Since = commit }); stats = new RepositoryStatisticsModel.Statistics { Branch = _repository.Head.Name, Commits = ancestors.Count(), Contributors = ancestors.Select(s => s.Author.ToString()).Distinct().Count(), Files = FilesInCommit(commit, out size), SourceSize = size, }; GitCache.Set(commit.Sha, "statistics", stats); } statistics.Default = stats; } var sha = CalcBranchesSha(true); var sizeOfRepo = GitCache.Get <long>(sha, "size"); if (sizeOfRepo == 0) { sizeOfRepo = SizeOfRepository(); GitCache.Set(sha, "size", sizeOfRepo); } statistics.RepositorySize = sizeOfRepo; var model = new ContributorsModel { RepositoryName = Name, Contributors = contributors, Statistics = statistics, }; return(model); }