예제 #1
0
        private ITagPicker PrepareTagPicker(
            ITagPickingOptions tagPickingOptions,
            IEnumerable <ITagInfo> tagInfos)
        {
            ITagPicker tagPicker = _tagPickerFactory.CreateTagPicker(tagPickingOptions);

            tagPicker.PreProcessAllTags(tagInfos);
            return(tagPicker);
        }
예제 #2
0
        private void Run(TagPickerTestCase testCase)
        {
            INode MockNode(string hash, DateTimeOffset?date)
            {
                ICommit commit = new CommitStub(hash, date ?? DateTimeOffset.MinValue);
                INode   node   = new NodeStub(commit);

                return(node);
            }

            IBranch MockBranch(string name)
            {
                if (string.IsNullOrWhiteSpace(name))
                {
                    return(null);
                }

                return(new Branch(name, null));
            }

            ITagPickingOptions tpo = TagPickingOptions.Set(
                testCase.Mode,
                testCase.TakeCount,
                testCase.IncludeOrphanedTags);
            TagPicker p = new TagPicker(tpo);

            ITag ta = new Tag(testCase.TagAName, null);
            ITag tb = new Tag(testCase.TagBName, null);
            ITag tc = new Tag(testCase.TagCName, null);

            INode na = MockNode("na", testCase.CommitADate);
            INode nb = MockNode("nb", testCase.CommitBDate);
            INode nc = MockNode("nc", testCase.CommitCDate);

            IBranch ba = MockBranch(testCase.BranchAName);
            IBranch bb = MockBranch(testCase.BranchBName);
            IBranch bc = MockBranch(testCase.BranchCName);

            var tagInfos = new[]
            {
                new TagInfo(ta, na, ba),
                new TagInfo(tb, nb, bb),
                new TagInfo(tc, nc, bc)
            };

            p.PreProcessAllTags(tagInfos);

            Assert.Equal(testCase.ExpectedTagAPicked, p.CheckIfTagShouldBePicked(ta));
            Assert.Equal(testCase.ExpectedTagBPicked, p.CheckIfTagShouldBePicked(tb));
            Assert.Equal(testCase.ExpectedTagCPicked, p.CheckIfTagShouldBePicked(tc));
        }
예제 #3
0
        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);
        }
예제 #4
0
        /// <summary>
        ///     Adds tags, but only those that are permitted by the tag picker.
        /// </summary>
        private void AddTags(IEnumerable <ITag> tags, ITagPickingOptions tagPickingOptions, ITree tree)
        {
            ITagInfo[] tagInfos = tags.Select(t => CreateTagInfo(t, tree)).ToArray();

            // Prepare picker.
            ITagPicker tagPicker = PrepareTagPicker(tagPickingOptions, tagInfos);

            // Now tags.
            foreach (ITagInfo tagInfo in tagInfos)
            {
                ITag tag = tagInfo.Tag;

                if (!tagPicker.CheckIfTagShouldBePicked(tag))
                {
                    continue;
                }

                tree.AddTag(tag);
            }
        }
예제 #5
0
        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}.");
            }
        }
예제 #6
0
 public TagPicker(ITagPickingOptions options)
 {
     _options    = options;
     _tagsToPick = new HashSet <ITag>();
 }
예제 #7
0
 public ITagPicker CreateTagPicker(ITagPickingOptions options)
 {
     return(_maker(options));
 }