Skip to content

Commit 164961a

Browse files
committed
HistorySize: output counts of references per reference group
1 parent 0351697 commit 164961a

3 files changed

Lines changed: 44 additions & 9 deletions

File tree

git-sizer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func mainImplementation(args []string) error {
494494
case 1:
495495
j, err = json.MarshalIndent(historySize, "", " ")
496496
case 2:
497-
j, err = historySize.JSON(threshold, nameStyle)
497+
j, err = historySize.JSON(rg.Groups(), threshold, nameStyle)
498498
default:
499499
return fmt.Errorf("JSON version must be 1 or 2")
500500
}
@@ -503,7 +503,10 @@ func mainImplementation(args []string) error {
503503
}
504504
fmt.Printf("%s\n", j)
505505
} else {
506-
io.WriteString(os.Stdout, historySize.TableString(threshold, nameStyle))
506+
io.WriteString(
507+
os.Stdout,
508+
historySize.TableString(rg.Groups(), threshold, nameStyle),
509+
)
507510
}
508511

509512
return nil

sizes/graph.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type refSeen struct {
4949
func ScanRepositoryUsingGraph(
5050
repo *git.Repository, rg RefGrouper, nameStyle NameStyle, progress bool,
5151
) (HistorySize, error) {
52-
graph := NewGraph(nameStyle)
52+
graph := NewGraph(rg, nameStyle)
5353
var progressMeter meter.Progress
5454
if progress {
5555
progressMeter = meter.NewProgressMeter(100 * time.Millisecond)
@@ -383,6 +383,8 @@ func ScanRepositoryUsingGraph(
383383
type Graph struct {
384384
repo *git.Repository
385385

386+
rg RefGrouper
387+
386388
blobLock sync.Mutex
387389
blobSizes map[git.OID]BlobSize
388390

@@ -404,8 +406,10 @@ type Graph struct {
404406
pathResolver PathResolver
405407
}
406408

407-
func NewGraph(nameStyle NameStyle) *Graph {
409+
func NewGraph(rg RefGrouper, nameStyle NameStyle) *Graph {
408410
return &Graph{
411+
rg: rg,
412+
409413
blobSizes: make(map[git.OID]BlobSize),
410414

411415
treeRecords: make(map[git.OID]*treeRecord),

sizes/output.go

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,10 @@ type table struct {
345345
buf bytes.Buffer
346346
}
347347

348-
func (s HistorySize) TableString(threshold Threshold, nameStyle NameStyle) string {
349-
contents := s.contents()
348+
func (s HistorySize) TableString(
349+
refGroups []RefGroup, threshold Threshold, nameStyle NameStyle,
350+
) string {
351+
contents := s.contents(refGroups)
350352
t := table{
351353
threshold: threshold,
352354
nameStyle: nameStyle,
@@ -422,19 +424,41 @@ func (t *table) formatRow(
422424
)
423425
}
424426

425-
func (s HistorySize) JSON(threshold Threshold, nameStyle NameStyle) ([]byte, error) {
426-
contents := s.contents()
427+
func (s HistorySize) JSON(
428+
refGroups []RefGroup, threshold Threshold, nameStyle NameStyle,
429+
) ([]byte, error) {
430+
contents := s.contents(refGroups)
427431
items := make(map[string]*item)
428432
contents.CollectItems(items)
429433
j, err := json.MarshalIndent(items, "", " ")
430434
return j, err
431435
}
432436

433-
func (s HistorySize) contents() tableContents {
437+
func (s HistorySize) contents(refGroups []RefGroup) tableContents {
434438
S := newSection
435439
I := newItem
436440
metric := counts.Metric
437441
binary := counts.Binary
442+
443+
var rgis []tableContents
444+
for _, rg := range refGroups {
445+
if rg.Symbol == "" {
446+
continue
447+
}
448+
count, ok := s.ReferenceGroups[rg.Symbol]
449+
if !ok {
450+
continue
451+
}
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+
),
459+
)
460+
}
461+
438462
return S(
439463
"",
440464
S(
@@ -484,6 +508,10 @@ func (s HistorySize) contents() tableContents {
484508
I("referenceCount", "Count",
485509
"The total number of references",
486510
nil, s.ReferenceCount, metric, "", 25e3),
511+
S(
512+
"",
513+
rgis...,
514+
),
487515
),
488516
),
489517

0 commit comments

Comments
 (0)