public BranchPicker(IBranchPickingOptions options, ILogger <BranchPicker> logger) { _logger = logger; _logger.Debug("Loading exclude branches regular expressions."); _excludeRegices = CreateRegices(options.ExcludeBranchesRegices); _logger.Debug("Finished loading exclude branches regular expressions."); _logger.Debug("Loading include branches regular expressions."); _includeRegices = CreateRegices(options.IncludeBranchesRegices); _logger.Debug("Finished loading include branches regular expressions."); }
public ITree Build( IRepositoryData repository, IRemote remoteToUse, IBranchesKnowledge branchesKnowledge, IBranchPickingOptions branchPickingOptions, ITagPickingOptions tagPickingOptions) { ITree tree = new Tree(); tree.SetCommits(repository.Commits); AddBranches(branchesKnowledge, repository.Commits, branchPickingOptions, tree); AddTags(repository.Tags, tagPickingOptions, tree); return(tree); }
private void AddBranches( IBranchesKnowledge branchesKnowledge, ICommitsData commitsData, IBranchPickingOptions branchPickingOptions, ITree tree) { // Branches in the writing order. IBranch[] branchesOrdered = branchesKnowledge.EnumerateBranchesInLogicalOrder().ToArray(); IBranchPicker branchPicker = _branchPickerFactory.CreateBranchPicker(branchPickingOptions); // Filter them so that we get only those we want to write. IBranch[] branchesFiltered = branchesOrdered.Where(b => branchPicker.ShouldBePicked(b.Label)).ToArray(); var commitsSet = new HashSet <ICommit>(commitsData); foreach (IBranch b in branchesFiltered) { ICommit tip = commitsData.GetByHash(b.Tip); var hashesInBranch = new List <IHash>(commitsSet.Count / 3); IEnumerable <ICommit> upTheTree = commitsData.EnumerateUpTheHistoryFrom(tip); foreach (ICommit commit in upTheTree) { if (!commitsSet.Contains(commit)) { break; } hashesInBranch.Add(commit.Hash); commitsSet.Remove(commit); } hashesInBranch.Reverse(); tree.AddBranch(b, hashesInBranch); } }
protected override void RunInternal() { // Get the immutable repository information. IRepositoryData repositoryData = _loader.LoadFrom(_repositoryDir.FullName); // Pick the remote to work on. IRemote remoteToUse = _remoteHelper.PickRemote(repositoryData, Options.RemoteToUse); // Create the tree. IBranchingStrategy strategy = _strategyProvider.GetStrategy(Options.LesserBranchesRegex); IBranch[] allBranches = repositoryData.Branches.GetFor(remoteToUse).ToArray(); IBranchesKnowledge branchesKnowledge = strategy.CreateKnowledge(allBranches); // Options for building the tree. ITagPickingOptions tagPickingOptions = TagPickingOptions.Set( Options.TagPickingMode, Options.TagCount, Options.IncludeOrphanedTags); IBranchPickingOptions branchPickingOptions = BranchPickingOptions.Set( Options.IncludeBranchesRegices, Options.ExcludeBranchesRegices); ITree tree = _treeBuilder.Build( repositoryData, remoteToUse, branchesKnowledge, branchPickingOptions, tagPickingOptions); SimplifyTree(tree); string tempPath = _fileSystem.Path.GetTempFileName(); tempPath = _fileSystem.Path.ChangeExtension(tempPath, "gv"); // Rendering options. TreeRenderingOptions renderingOptions = TreeRenderingOptions.Default; renderingOptions.ForceTreatAsGitHub = Options.ForceTreatAsGitHub; // ReSharper disable once AssignNullToNotNullAttribute using (IFileStream fileStream = _fileSystem.File.OpenWrite(tempPath)) { using (IStreamWriter textWriter = _textWriterFactory.CreateStreamWriter(fileStream)) { IGraphVizWriter graphVizWriter = _graphVizFactory.CreateGraphVizWriter(textWriter); ITreeRenderer treeRenderer = _treeRendererFactory.CreateRenderer(graphVizWriter); treeRenderer.Render(tree, remoteToUse, branchesKnowledge, renderingOptions); } } string targetPath = PrepareTargetPath(); string graphVizCommand = _appPathProvider.GetProperAppPath(ExternalApp.GraphViz); string graphVizArgs = $@"""{tempPath}"" -T{_outputFormat} -o""{targetPath}"""; Log.Debug($"Starting GraphViz with arguments: [{graphVizArgs}]."); int code = _processRunner.Execute(graphVizCommand, graphVizArgs); if (code != 0) { Log.Fatal("GraphViz execution failed."); } else { Log.Info("GraphViz execution succeeded."); Log.Info($"Saved to {targetPath}."); } }
public IBranchPicker CreateBranchPicker(IBranchPickingOptions options) { return(_maker(options)); }