Skip to content

Commit

Permalink
graphviz: don't draw edges multiple times
Browse files Browse the repository at this point in the history
From a patch from Ian Godin <iangodin@gmail.com>.
  • Loading branch information
evmar committed Feb 14, 2012
1 parent a1ea9c2 commit 5106642
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/graphviz.cc
Expand Up @@ -19,11 +19,11 @@
#include "graph.h"

void GraphViz::AddTarget(Node* node) {
if (visited_.find(node) != visited_.end())
if (visited_nodes_.find(node) != visited_nodes_.end())
return;

printf("\"%p\" [label=\"%s\"]\n", node, node->path().c_str());
visited_.insert(node);
visited_nodes_.insert(node);

Edge* edge = node->in_edge();

Expand All @@ -33,6 +33,10 @@ void GraphViz::AddTarget(Node* node) {
return;
}

if (visited_edges_.find(edge) != visited_edges_.end())
return;
visited_edges_.insert(edge);

if (edge->inputs_.size() == 1 && edge->outputs_.size() == 1) {
// Can draw simply.
// Note extra space before label text -- this is cosmetic and feels
Expand Down
4 changes: 3 additions & 1 deletion src/graphviz.h
Expand Up @@ -19,14 +19,16 @@
using namespace std;

struct Node;
struct Edge;

/// Runs the process of creating GraphViz .dot file output.
struct GraphViz {
void Start();
void AddTarget(Node* node);
void Finish();

set<Node*> visited_;
set<Node*> visited_nodes_;
set<Edge*> visited_edges_;
};

#endif // NINJA_GRAPHVIZ_H_

0 comments on commit 5106642

Please sign in to comment.