[tools] cmd/digraph: use graphfmt.Dot

4 views
Skip to first unread message

Austin Clements (Gerrit)

unread,
Feb 19, 2026, 6:54:05 PM (5 days ago) Feb 19
to Alan Donovan, goph...@pubsubhelper.golang.org, Austin Clements, golang-co...@googlegroups.com
Attention needed from Alan Donovan

Austin Clements has uploaded the change for review

Austin Clements would like Alan Donovan to review this change.

Commit message

cmd/digraph: use graphfmt.Dot
Change-Id: Icddd469995974dbf9681b126330db284a95adc4f

Change diff

diff --git a/cmd/digraph/digraph.go b/cmd/digraph/digraph.go
index 5253ae8..8a7a462 100644
--- a/cmd/digraph/digraph.go
+++ b/cmd/digraph/digraph.go
@@ -29,6 +29,7 @@
"iter"

"golang.org/x/tools/internal/graph"
+ "golang.org/x/tools/internal/graph/graphfmt"
)

func usage() {
@@ -167,20 +168,6 @@
return nil
}

-func (g digraph) toDot(w *bytes.Buffer) {
- fmt.Fprintln(w, "digraph {")
- for _, src := range g.nodelist() {
- for _, dst := range g[src].sort() {
- // Dot's quoting rules appear to align with Go's for escString,
- // which is the syntax of node IDs. Labels require significantly
- // more quoting, but that appears not to be necessary if the node ID
- // is implicitly used as the label.
- fmt.Fprintf(w, "\t%q -> %q;\n", src, dst)
- }
- }
- fmt.Fprintln(w, "}")
-}
-
func parse(rd io.Reader) (digraph, error) {
g := make(digraph)

@@ -394,9 +381,7 @@
if len(args) != 1 || args[0] != "dot" {
return fmt.Errorf("usage: digraph to dot")
}
- var b bytes.Buffer
- g.toDot(&b)
- stdout.Write(b.Bytes())
+ graphfmt.Dot[string]{}.Fprint(stdout, g)

default:
return fmt.Errorf("no such command %q", cmd)
diff --git a/cmd/digraph/digraph_test.go b/cmd/digraph/digraph_test.go
index 74e61ee..153b253 100644
--- a/cmd/digraph/digraph_test.go
+++ b/cmd/digraph/digraph_test.go
@@ -387,11 +387,15 @@
in := `a b c
b "d\"\\d"
c "d\"\\d"`
- want := `digraph {
- "a" -> "b";
- "a" -> "c";
- "b" -> "d\"\\d";
- "c" -> "d\"\\d";
+ want := `digraph "" {
+n0 [label="a"];
+n1 [label="b"];
+n2 [label="c"];
+n3 [label="d\"\\d"];
+n0 -> n1;
+n0 -> n2;
+n1 -> n3;
+n2 -> n3;
}
`
defer func(in io.Reader, out io.Writer) { stdin, stdout = in, out }(stdin, stdout)

Change information

Files:
  • M cmd/digraph/digraph.go
  • M cmd/digraph/digraph_test.go
Change size: S
Delta: 2 files changed, 11 insertions(+), 22 deletions(-)
Open in Gerrit

Related details

Attention is currently required from:
  • Alan Donovan
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Icddd469995974dbf9681b126330db284a95adc4f
Gerrit-Change-Number: 747369
Gerrit-PatchSet: 1
Gerrit-Owner: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Attention: Alan Donovan <adon...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Alan Donovan (Gerrit)

unread,
Feb 23, 2026, 2:57:18 PM (2 days ago) Feb 23
to Austin Clements, goph...@pubsubhelper.golang.org, Go LUCI, golang-co...@googlegroups.com
Attention needed from Austin Clements

Alan Donovan voted Code-Review+2

Code-Review+2
Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
Submit Requirements:
  • requirement satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
  • requirement satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Icddd469995974dbf9681b126330db284a95adc4f
Gerrit-Change-Number: 747369
Gerrit-PatchSet: 1
Gerrit-Owner: Austin Clements <aus...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Austin Clements <aus...@google.com>
Gerrit-Attention: Austin Clements <aus...@google.com>
Gerrit-Comment-Date: Mon, 23 Feb 2026 19:57:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Austin Clements (Gerrit)

unread,
Feb 24, 2026, 10:03:24 PM (7 hours ago) Feb 24
to Austin Clements, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com
Attention needed from Austin Clements

Austin Clements uploaded new patchset

Austin Clements uploaded patch set #2 to this change.
Following approvals got outdated and were removed:
  • TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit

Related details

Attention is currently required from:
  • Austin Clements
Submit Requirements:
    • requirement satisfiedCode-Review
    • requirement satisfiedNo-Unresolved-Comments
    • requirement satisfiedReview-Enforcement
    • requirement is not satisfiedTryBots-Pass
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: newpatchset
    Gerrit-Project: tools
    Gerrit-Branch: master
    Gerrit-Change-Id: Icddd469995974dbf9681b126330db284a95adc4f
    Gerrit-Change-Number: 747369
    Gerrit-PatchSet: 2
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages