Skip to content

Commit 1b49fb4

Browse files
committed
HistorySize.contents(): indent reference group lines hierarchically
1 parent 164961a commit 1b49fb4

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

sizes/output.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"strconv"
8+
"strings"
89

910
"github.com/github/git-sizer/counts"
1011
"github.com/github/git-sizer/git"
@@ -218,6 +219,26 @@ func (i *item) MarshalJSON() ([]byte, error) {
218219
return json.Marshal(stat)
219220
}
220221

222+
// Indented returns an `item` that is just like `i`, but indented by
223+
// `depth` more levels.
224+
func (i *item) Indented(depth int) tableContents {
225+
return &indentedItem{
226+
tableContents: i,
227+
depth: depth,
228+
}
229+
}
230+
231+
type indentedItem struct {
232+
tableContents
233+
depth int
234+
}
235+
236+
func (i *indentedItem) Emit(t *table) {
237+
subTable := t.indented("", i.depth)
238+
i.tableContents.Emit(subTable)
239+
t.addSection(subTable)
240+
}
241+
221242
type Threshold float64
222243

223244
// Methods to implement pflag.Value:
@@ -365,16 +386,20 @@ func (s HistorySize) TableString(
365386
return t.generateHeader() + t.buf.String() + t.footnotes.String()
366387
}
367388

368-
func (t *table) subTable(sectionHeader string) *table {
389+
func (t *table) indented(sectionHeader string, depth int) *table {
369390
return &table{
370391
threshold: t.threshold,
371392
nameStyle: t.nameStyle,
372393
sectionHeader: sectionHeader,
373394
footnotes: t.footnotes,
374-
indent: t.indent + 1,
395+
indent: t.indent + depth,
375396
}
376397
}
377398

399+
func (t *table) subTable(sectionHeader string) *table {
400+
return t.indented(sectionHeader, 1)
401+
}
402+
378403
func (t *table) addSection(subTable *table) {
379404
if subTable.buf.Len() > 0 {
380405
if t.buf.Len() == 0 {
@@ -449,14 +474,13 @@ func (s HistorySize) contents(refGroups []RefGroup) tableContents {
449474
if !ok {
450475
continue
451476
}
452-
rgis = append(
453-
rgis,
454-
I(
455-
fmt.Sprintf("refgroup.%s", rg.Symbol), rg.Name,
456-
fmt.Sprintf("The number of references in group '%s'", rg.Symbol),
457-
nil, *count, metric, "", 25000,
458-
),
477+
rgi := I(
478+
fmt.Sprintf("refgroup.%s", rg.Symbol), rg.Name,
479+
fmt.Sprintf("The number of references in group '%s'", rg.Symbol),
480+
nil, *count, metric, "", 25000,
459481
)
482+
indent := strings.Count(string(rg.Symbol), ".")
483+
rgis = append(rgis, rgi.Indented(indent))
460484
}
461485

462486
return S(

0 commit comments

Comments
 (0)