コード例 #1
0
        CommitGraph GenerateGraphFromCommits(IEnumerable <Commit> commits, string activeRefName, IEnumerable <Commit> unreachableCommits)
        {
            commits = commits.ToList();

            var graph = new CommitGraph();

            var commitVertices = commits.Select(c => new Vertex(c))
                                 .Union(unreachableCommits.Select(c => new Vertex(c)
            {
                Orphan = true
            }))
                                 .ToList();

            // Add all the vertices
            foreach (var commitVertex in commitVertices)
            {
                graph.AddVertex(commitVertex);

                if (commitVertex.Commit.Refs == null)
                {
                    continue;
                }
                foreach (var refName in commitVertex.Commit.Refs)
                {
                    var refVertex = new Vertex(new Reference
                    {
                        Name     = refName,
                        IsActive = refName == activeRefName
                    });
                    graph.AddVertex(refVertex);
                    graph.AddEdge(new CommitEdge(refVertex, commitVertex));
                }
            }

            // Add all the edges
            foreach (var commitVertex in commitVertices.Where(c => c.Commit.ParentHashes != null))
            {
                foreach (var parentHash in commitVertex.Commit.ParentHashes)
                {
                    var parentVertex = commitVertices.SingleOrDefault(c => c.Commit.Hash == parentHash);
                    if (parentVertex != null)
                    {
                        graph.AddEdge(new CommitEdge(commitVertex, parentVertex));
                    }
                }
            }

            return(graph);
        }
コード例 #2
0
ファイル: ViewModel.cs プロジェクト: rhwy/GitViz
        CommitGraph GenerateGraphFromCommits(IEnumerable<Commit> commits, string activeRefName, IEnumerable<Commit> unreachableCommits)
        {
            commits = commits.ToList();

            var graph = new CommitGraph();

            var commitVertices = commits.Select(c => new Vertex(c))
                .Union(unreachableCommits.Select(c => new Vertex(c) { Orphan = true }))
                .ToList();

            // Add all the vertices
            foreach (var commitVertex in commitVertices)
            {
                graph.AddVertex(commitVertex);

                if (commitVertex.Commit.Refs == null) continue;
                foreach (var refName in commitVertex.Commit.Refs)
                {
                    var refVertex = new Vertex(new Reference
                    {
                        Name = refName,
                        IsActive = refName == activeRefName
                    });
                    graph.AddVertex(refVertex);
                    graph.AddEdge(new CommitEdge(refVertex, commitVertex));
                }
            }

            // Add all the edges
            foreach (var commitVertex in commitVertices.Where(c => c.Commit.ParentHashes != null))
            {
                foreach (var parentHash in commitVertex.Commit.ParentHashes)
                {
                    var parentVertex = commitVertices.SingleOrDefault(c => c.Commit.Hash == parentHash);
                    if (parentVertex != null) graph.AddEdge(new CommitEdge(commitVertex, parentVertex));
                }
            }

            return graph;
        }
コード例 #3
0
ファイル: ViewModel.cs プロジェクト: Jan-Thes/GitViz
        CommitGraph GenerateGraphFromCommits(IEnumerable <Commit> commits, string activeRefName, IEnumerable <Commit> unreachableCommits)
        {
            commits = commits.ToList();

            var           graph = new CommitGraph();
            List <Vertex> commitVertices;

            if (unreachableCommits != null)
            {
                commitVertices = commits.Select(c => new Vertex(c))
                                 .Union(unreachableCommits.Select(c => new Vertex(c)
                {
                    Orphan = true
                }))
                                 .ToList();
            }
            else
            {
                commitVertices = commits.Select(c => new Vertex(c))
                                 .ToList();
            }

            // Add all the vertices
            var headVertex = new Vertex(new Reference
            {
                Name = Reference.HEAD,
            });

            foreach (var commitVertex in commitVertices)
            {
                graph.AddVertex(commitVertex);

                if (commitVertex.Commit.Refs == null)
                {
                    continue;
                }
                var isHeadHere = false;
                var isHeadSet  = false;
                foreach (var refName in commitVertex.Commit.Refs)
                {
                    if (refName == Reference.HEAD)
                    {
                        isHeadHere = true;
                        graph.AddVertex(headVertex);
                        continue;
                    }
                    var refVertex = new Vertex(new Reference
                    {
                        Name     = refName,
                        IsActive = refName == activeRefName
                    });
                    graph.AddVertex(refVertex);
                    graph.AddEdge(new CommitEdge(refVertex, commitVertex));
                    if (!refVertex.Reference.IsActive)
                    {
                        continue;
                    }
                    isHeadSet = true;
                    graph.AddEdge(new CommitEdge(headVertex, refVertex));
                }
                if (isHeadHere && !isHeadSet)
                {
                    graph.AddEdge(new CommitEdge(headVertex, commitVertex));
                }
            }

            // Add all the edges
            foreach (var commitVertex in commitVertices.Where(c => c.Commit.ParentHashes != null))
            {
                foreach (var parentHash in commitVertex.Commit.ParentHashes)
                {
                    var parentVertex = commitVertices.SingleOrDefault(c => c.Commit.Hash == parentHash);
                    if (parentVertex != null)
                    {
                        graph.AddEdge(new CommitEdge(commitVertex, parentVertex));
                    }
                }
            }

            return(graph);
        }