Skip to content

Commit f5d7b04

Browse files
authored
Fix breaking changes count (#48)
* Accurately count the number of breaking changes We previously related the number of breaking changes with the number of breaking changes printed (which was capped at 500). By abstracting the printing mechanism to understand its own capacity, we get an accurate count of the number of conflicts without increasing code complexity in the display mechanism. * Add a `make install` target * Nit: max -> remaining
1 parent 4416eea commit f5d7b04

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
VERSION=$(shell git describe --tags)
1+
VERSION:=$(shell git describe --tags)
2+
LDFLAGS=-ldflags="-X github.com/pulumi/schema-tools/version.Version=$(VERSION)"
23

34
test:
45
go test ./...
56

67
build:
7-
go build \
8-
-ldflags="-X github.com/pulumi/schema-tools/version.Version=$(VERSION)"
8+
go build $(LDFLAGS)
99

1010
lint:
1111
golangci-lint run
12+
13+
install:
14+
go install $(LDFLAGS)

internal/util/diagtree/diagtree.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,37 @@ func (m *Node) levelPrefix(level int) string {
7070
return strings.Repeat(" ", (level-2)*2) + "- "
7171
}
7272

73+
type cappedWriter struct {
74+
// The number of remaining writes before we hit the cap.
75+
remaining int
76+
out io.Writer
77+
}
78+
79+
func (c *cappedWriter) incr() {
80+
if c.remaining > 0 {
81+
c.remaining--
82+
}
83+
}
84+
85+
func (c *cappedWriter) Write(p []byte) (n int, err error) {
86+
if c.remaining > 0 {
87+
return c.out.Write(p)
88+
}
89+
// We pretend we finished the write, but we do nothing.
90+
return len(p), nil
91+
}
92+
7393
func (m *Node) Display(out io.Writer, max int) int {
74-
return m.display(out, 0, true, max)
94+
writer := &cappedWriter{max, out}
95+
return m.display(writer, 0, true)
7596
}
7697

77-
func (m *Node) display(out io.Writer, level int, prefix bool, max int) int {
98+
func (m *Node) display(out *cappedWriter, level int, prefix bool) int {
7899
write := func(s string) {
79100
_, err := out.Write([]byte(s))
80101
contract.AssertNoErrorf(err, "failed to write display")
81102
}
82-
if m == nil || !m.doDisplay || max <= 0 {
103+
if m == nil || !m.doDisplay {
83104
// Nothing to display
84105
return 0
85106
}
@@ -102,12 +123,13 @@ func (m *Node) display(out io.Writer, level int, prefix bool, max int) int {
102123
}
103124

104125
write(display)
126+
out.incr()
105127
}
106128

107129
if level > 1 && m.Severity == None {
108130
if s := m.uniqueSuccessor(); s != nil {
109131
write(": ")
110-
return s.display(out, level, false, max-displayed) + displayed
132+
return s.display(out, level, false) + displayed
111133
}
112134
}
113135

@@ -132,7 +154,7 @@ func (m *Node) display(out io.Writer, level int, prefix bool, max int) int {
132154
}
133155
didEndLine = true
134156
}
135-
n := m.subfields[i].display(out, level+1, true, max-displayed)
157+
n := m.subfields[i].display(out, level+1, true)
136158
displayed += n
137159
}
138160

0 commit comments

Comments
 (0)