/// <summary> /// Try to locate the local git repo and open the revision of the source file /// that writes the log entry. /// </summary> /// <param name="sha">The git commit SHA.</param> /// <param name="filePath">The full file path that generates the log item or error event.</param> /// <returns> /// The file path of the source file revision. /// null: Operation is cancelled or failed to open the file revision. /// </returns> /// <exception cref="FileNotFoundException">Does not find the revision of file.</exception> private static async Task <EnvDTE.Window> SearchGitRepoAndOpenFileAsync(string sha, string filePath) { if (s_localCache.ContainsKey(sha)) { return(await OpenGitFileAsync(s_localCache[sha], filePath)); } else { // There is a chance the file is built from local git repo root. if (await SearchCommitAtPathAsync(Path.GetDirectoryName(filePath), sha)) { return(await OpenGitFileAsync(s_localCache[sha], filePath)); } } IEnumerable <string> gitPaths = VsGitData.GetLocalRepositories(GoogleCloudExtensionPackage.VsVersion); if (gitPaths != null) { foreach (var path in gitPaths) { if (await SearchCommitAtPathAsync(path, sha)) { return(await OpenGitFileAsync(s_localCache[sha], filePath)); } } } return(null); }
/// <summary> /// The list of local git repositories that Visual Studio remembers. /// </summary> /// <returns> /// A list of local repositories. /// Empty list is returned, never return null. /// </returns> private async Task <List <GitRepository> > GetLocalGitRepositoriesAsync() { List <GitRepository> localRepos = new List <GitRepository>(); var repos = VsGitData.GetLocalRepositories(GoogleCloudExtensionPackage.Instance.VsVersion); if (repos != null) { var localRepoTasks = repos.Where(r => !string.IsNullOrWhiteSpace(r)) .Select(GitRepository.GetGitCommandWrapperForPathAsync); localRepos.AddRange((await Task.WhenAll(localRepoTasks)).Where(r => r != null)); } return(localRepos); }