示例#1
0
        private RepositoryInformation ProcessSingleRepo(WritableRepositoryInformation repo)
        {
            if (_repoCache.TryGetCachedVersion(repo, out var cachedVersion))
            {
                return(cachedVersion);
            }

            using (_telemetry.TrackIndexRepositoryDuration(repo.Id))
                using (_logger.BeginScope("Starting indexing for repo {Name}", repo.Id))
                    using (var fetchedRepo = _repoFetcher.FetchRepo(repo))
                    {
                        IReadOnlyList <GitFileInfo> files;
                        using (_telemetry.TrackListFilesDuration(repo.Id))
                        {
                            _logger.LogInformation("Finding files in repo {Name}...", repo.Id);

                            files = fetchedRepo.GetFileInfos();
                        }

                        var filePaths = files.Where(ShouldCheckOutFile).Select(x => x.Path).ToList();

                        IReadOnlyList <ICheckedOutFile> checkedOutFiles;
                        using (_telemetry.TrackCheckOutFilesDuration(repo.Id))
                        {
                            _logger.LogInformation(
                                "Checking out {FileCount} files from repo {Name}",
                                filePaths.Count,
                                repo.Id);

                            checkedOutFiles = fetchedRepo.CheckoutFiles(filePaths);
                        }

                        foreach (var cfgFile in checkedOutFiles)
                        {
                            var dependencies = _configFileParser.Parse(cfgFile);
                            repo.AddDependencies(dependencies);
                        }

                        _logger.LogInformation("Finished indexing repo {Name}", repo.Id);
                    }

            var result = repo.ToRepositoryInformation();

            _repoCache.Persist(result);
            return(result);
        }