Skip to content

Commit 05e05d1

Browse files
committed
ScanRepositoryUsingGraph(): take a meter.Progress argument
Take a `meter.Progress` argument rather than a boolean, to give the caller more control about if/how progress is reported.
1 parent 731aade commit 05e05d1

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

git-sizer.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import (
88
"os"
99
"runtime/pprof"
1010
"strconv"
11+
"time"
1112

1213
"github.com/spf13/pflag"
1314

1415
"github.com/github/git-sizer/git"
1516
"github.com/github/git-sizer/internal/refopts"
1617
"github.com/github/git-sizer/isatty"
18+
"github.com/github/git-sizer/meter"
1719
"github.com/github/git-sizer/sizes"
1820
)
1921

@@ -269,7 +271,12 @@ func mainImplementation(args []string) error {
269271
return err
270272
}
271273

272-
historySize, err := sizes.ScanRepositoryUsingGraph(repo, rg, nameStyle, progress)
274+
var progressMeter meter.Progress = meter.NoProgressMeter
275+
if progress {
276+
progressMeter = meter.NewProgressMeter(os.Stderr, 100*time.Millisecond)
277+
}
278+
279+
historySize, err := sizes.ScanRepositoryUsingGraph(repo, rg, nameStyle, progressMeter)
273280
if err != nil {
274281
return fmt.Errorf("error scanning repository: %w", err)
275282
}

git_sizer_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/github/git-sizer/counts"
2020
"github.com/github/git-sizer/git"
2121
"github.com/github/git-sizer/internal/testutils"
22+
"github.com/github/git-sizer/meter"
2223
"github.com/github/git-sizer/sizes"
2324
)
2425

@@ -548,7 +549,7 @@ func TestBomb(t *testing.T) {
548549

549550
h, err := sizes.ScanRepositoryUsingGraph(
550551
repo.Repository(t),
551-
refGrouper{}, sizes.NameStyleFull, false,
552+
refGrouper{}, sizes.NameStyleFull, meter.NoProgressMeter,
552553
)
553554
require.NoError(t, err)
554555

@@ -621,7 +622,7 @@ func TestTaggedTags(t *testing.T) {
621622

622623
h, err := sizes.ScanRepositoryUsingGraph(
623624
repo.Repository(t),
624-
refGrouper{}, sizes.NameStyleNone, false,
625+
refGrouper{}, sizes.NameStyleNone, meter.NoProgressMeter,
625626
)
626627
require.NoError(t, err, "scanning repository")
627628
assert.Equal(t, counts.Count32(3), h.MaxTagDepth, "tag depth")
@@ -643,7 +644,7 @@ func TestFromSubdir(t *testing.T) {
643644

644645
h, err := sizes.ScanRepositoryUsingGraph(
645646
repo.Repository(t),
646-
refGrouper{}, sizes.NameStyleNone, false,
647+
refGrouper{}, sizes.NameStyleNone, meter.NoProgressMeter,
647648
)
648649
require.NoError(t, err, "scanning repository")
649650
assert.Equal(t, counts.Count32(2), h.MaxPathDepth, "max path depth")
@@ -696,7 +697,7 @@ func TestSubmodule(t *testing.T) {
696697
// Analyze the main repo:
697698
h, err := sizes.ScanRepositoryUsingGraph(
698699
mainRepo.Repository(t),
699-
refGrouper{}, sizes.NameStyleNone, false,
700+
refGrouper{}, sizes.NameStyleNone, meter.NoProgressMeter,
700701
)
701702
require.NoError(t, err, "scanning repository")
702703
assert.Equal(t, counts.Count32(2), h.UniqueBlobCount, "unique blob count")
@@ -709,7 +710,7 @@ func TestSubmodule(t *testing.T) {
709710
}
710711
h, err = sizes.ScanRepositoryUsingGraph(
711712
submRepo2.Repository(t),
712-
refGrouper{}, sizes.NameStyleNone, false,
713+
refGrouper{}, sizes.NameStyleNone, meter.NoProgressMeter,
713714
)
714715
require.NoError(t, err, "scanning repository")
715716
assert.Equal(t, counts.Count32(2), h.UniqueBlobCount, "unique blob count")

sizes/graph.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"io"
8-
"os"
98
"sync"
10-
"time"
119

1210
"github.com/github/git-sizer/counts"
1311
"github.com/github/git-sizer/git"
@@ -66,15 +64,10 @@ type refSeen struct {
6664
//
6765
// It returns the size data for the repository.
6866
func ScanRepositoryUsingGraph(
69-
repo *git.Repository, rg RefGrouper, nameStyle NameStyle, progress bool,
67+
repo *git.Repository, rg RefGrouper, nameStyle NameStyle,
68+
progressMeter meter.Progress,
7069
) (HistorySize, error) {
7170
graph := NewGraph(rg, nameStyle)
72-
var progressMeter meter.Progress
73-
if progress {
74-
progressMeter = meter.NewProgressMeter(os.Stderr, 100*time.Millisecond)
75-
} else {
76-
progressMeter = meter.NoProgressMeter
77-
}
7871

7972
refIter, err := repo.NewReferenceIter()
8073
if err != nil {

0 commit comments

Comments
 (0)