private IEnumerable<ICommitLogEntryViewModel> GetCommits(UncommittedChangesViewModel workingDirectory) { var branchHeads = Repository.Branches.ToLookup(b => b.Tip.Id, b => b.Name); var tags = Repository.Tags.ToLookup(b => b.Target.Id, b => b.Name); GraphEntry previous = workingDirectory.GraphEntry; var commitLog = Repository.Commits.QueryBy(new CommitFilter() { Since = Repository.Refs.Where(r => !r.CanonicalName.StartsWith("refs/stash")) }); foreach (var commit in commitLog) { var current = new RevisionViewModel(Repository) { RevisionId = commit.Id, Message = commit.MessageShort, Author = $"{commit.Author.Name} <{commit.Author.Email}>", Hash = commit.Sha, Created = commit.Author.When, Labels = branchHeads[commit.Id].Concat(tags[commit.Id]).ToList(), GraphEntry = GraphEntry.FromCommit(previous, commit) }; if (current.RevisionId == workingDirectory.ParentCommitId) { baseRevision = current; baseRevision.GraphEntry.IsCurrent = !workingDirectory.HasContent; baseRevision.GraphEntry.IsFirst = !workingDirectory.HasContent; } yield return current; previous = current.GraphEntry; } }
private async Task LoadCommitsAsync() { uncommitted = new UncommittedChangesViewModel(Repository) { GraphEntry = GraphEntry.FromWorkingDirectory(Repository.Head.Tip) }; await uncommitted.LoadWorkingDirectoryStatusAsync(); var allRevisions = new ObservableCollection<ICommitLogEntryViewModel>(await Task.Run(() => GetCommits(uncommitted))); allRevisions.Insert(0, uncommitted); Commits.Clear(); Commits.AddRange(allRevisions); }