public async Task <CommitDetails> GetAsync(CommitSha commitSha, GitStatus status) { if (commitSha == CommitSha.NoCommits) { return(new CommitDetails(new CommitFile[0], null)); } // Get fresh list of uncomitted files or try to get them from cach, otherwise get from repo if (commitSha == CommitSha.Uncommitted || !commitsFiles.TryGetValue(commitSha, out CommitDetails commitDetails)) { nextIdToGet = commitSha; await currentTask; if (nextIdToGet != commitSha) { // This commit id is no longer relevant return(new CommitDetails(new CommitFile[0], null)); } string message = (commitSha == CommitSha.Uncommitted || commitSha == CommitSha.NoCommits) ? null : (await gitCommitService.GetCommitMessageAsync(commitSha.Sha, CancellationToken.None)).Or(null); Task <R <IReadOnlyList <GitFile> > > commitsFilesForCommitTask = CommitsFilesForCommitTask(commitSha, status); GitConflicts conflicts = GitConflicts.None; if (commitSha == CommitSha.Uncommitted && status.HasConflicts) { conflicts = (await gitStatusService.GetConflictsAsync(CancellationToken.None)).Or(GitConflicts.None); } currentTask = commitsFilesForCommitTask; if ((await commitsFilesForCommitTask).HasValue(out var commitsFilesForCommit)) { var files = commitsFilesForCommit.Select(f => { GitConflictFile conflict = conflicts.Files.FirstOrDefault(cf => cf.FilePath == f.FilePath); return(new CommitFile(f, conflict)); }) .ToList(); commitDetails = new CommitDetails(files, message); // Cache the list of files commitsFiles[commitSha] = commitDetails; return(commitDetails); } Log.Error($"Failed to get files for {commitSha}"); return(new CommitDetails(new CommitFile[0], message)); } return(commitDetails); }
public CommitFile(GitFile gitFile, GitConflictFile conflict = null) { this.gitFile = gitFile; Conflict = conflict ?? new GitConflictFile(null, gitFile.FilePath, null, null, null, GitFileStatus.Modified); }