private static ConcurrentStack <Commit> ReadCommitsFromRefs(string vcsPath) { var refs = Refs.ReadAll(vcsPath); var addedCommits = new ConcurrentDictionary <ObjectHash, bool>(); var result = new ConcurrentStack <Commit>(); Parallel.ForEach(refs, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount }, @ref => { var gitObject = @ref is TagRef tag ? GitObjectFactory.ReadGitObject(vcsPath, new ObjectHash(tag.CommitHash)) : GitObjectFactory.ReadGitObject(vcsPath, new ObjectHash(@ref.Hash)); while (gitObject is Tag tagObject) { gitObject = GitObjectFactory.ReadGitObject(vcsPath, new ObjectHash(tagObject.Object)); } // Tags pointing to trees are ignored if (gitObject.Type == GitObjectType.Commit && addedCommits.TryAdd(gitObject.Hash, true)) { result.Push((Commit)gitObject); } }); return(result); }
static void Main(string[] args) { if (!CommandLineOptions.TryParse(args, out var options)) { return; } PackReader.InitializePackFiles(options.RepositoryPath); if (options.FixTrees) { var defectiveCommits = FindCommitsWithDuplicateTreeEntries(options.RepositoryPath).ToList(); var rewrittenCommits = FixDefectiveCommits(options.RepositoryPath, defectiveCommits); if (rewrittenCommits.Any()) { Refs.Update(options.RepositoryPath, rewrittenCommits); } } else if (options.FilesToDelete.Any() || options.FoldersToDelete.Any()) { using (var task = new DeletionTask(options.RepositoryPath, options.FilesToDelete, options.FoldersToDelete, options.ProtectRefs)) task.Run(); } else if (options.RemoveEmptyCommits) { using (var removeEmptyCommitsTask = new RemoveEmptyCommitsTask(options.RepositoryPath)) removeEmptyCommitsTask.Run(); } else if (!string.IsNullOrWhiteSpace(options.ContributorMappingFile)) { using (var rewriteContributorTask = new RewriteContributorTask(options.RepositoryPath, options.ContributorMappingFile)) rewriteContributorTask.Run(); } else if (options.ListContributorNames) { foreach (var contributor in CommitWalker.CommitsRandomOrder(options.RepositoryPath) .SelectMany(commit => new[] { commit.GetAuthorName(), commit.GetCommitterName() }) .Distinct() .AsParallel() .OrderBy(x => x)) { Console.WriteLine(contributor); } } }