Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@d8cbb8045d7f43706b9177cceb36c1f91a6644d5 # v7.1.0
with:
go-version: 1.17
go-version: '1.27.4'

- name: Check out code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Expand All @@ -33,7 +33,7 @@ jobs:
go mod verify
go mod download

LINT_VERSION=1.43.0
LINT_VERSION=2.15.0
curl -fsSL https://github.com/golangci/golangci-lint/releases/download/v${LINT_VERSION}/golangci-lint-${LINT_VERSION}-linux-amd64.tar.gz | \
tar xz --strip-components 1 --wildcards \*/golangci-lint
mkdir -p bin && mv golangci-lint bin/
Expand All @@ -54,6 +54,6 @@ jobs:
assert-nothing-changed go fmt ./...
assert-nothing-changed go mod tidy

bin/golangci-lint run --out-format=github-actions --timeout=3m || STATUS=$?
bin/golangci-lint run --timeout=3m || STATUS=$?

exit $STATUS
457 changes: 62 additions & 395 deletions .golangci.toml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions git-sizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func main() {
}

func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []string) error {
var nameStyle sizes.NameStyle = sizes.NameStyleFull
nameStyle := sizes.NameStyleFull
var cpuprofile string
var jsonOutput bool
var jsonVersion int
Expand Down Expand Up @@ -219,7 +219,7 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
}

if cpuprofile != "" {
f, err := os.Create(cpuprofile)
f, err := os.Create(cpuprofile) //nolint:gosec // The user chooses the path.
if err != nil {
return fmt.Errorf("couldn't set up cpuprofile file: %w", err)
}
Expand Down Expand Up @@ -249,10 +249,10 @@ func mainImplementation(ctx context.Context, stdout, stderr io.Writer, args []st
return err
}
jsonVersion = v
if !(jsonVersion == 1 || jsonVersion == 2) {
if jsonVersion != 1 && jsonVersion != 2 {
return fmt.Errorf("JSON version (read from gitconfig) must be 1 or 2")
}
} else if !(jsonVersion == 1 || jsonVersion == 2) {
} else if jsonVersion != 1 && jsonVersion != 2 {
return fmt.Errorf("JSON version must be 1 or 2")
}
}
Expand Down
7 changes: 3 additions & 4 deletions git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
)

// ObjectType represents the type of a Git object ("blob", "tree",
Expand Down Expand Up @@ -133,17 +134,15 @@ func (repo *Repository) IsFull() (bool, error) {
}

func (repo *Repository) GitCommand(callerArgs ...string) *exec.Cmd {
args := []string{
args := slices.Concat([]string{
// Disable replace references when running our commands:
"--no-replace-objects",

// Disable the warning that grafts are deprecated, since we
// want to set the grafts file to `/dev/null` below (to
// disable grafts even where they are supported):
"-c", "advice.graftFileDeprecated=false",
}

args = append(args, callerArgs...)
}, callerArgs)

//nolint:gosec // `gitBin` is chosen carefully, and the rest of
// the args have been checked.
Expand Down
8 changes: 4 additions & 4 deletions git/gitconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func (config *Config) FullKey(key string) string {
// a component boundary (i.e., at a '.'). If yes, it returns `true`
// and the part of the key after the prefix; e.g.:
//
// configKeyMatchesPrefix("foo.bar", "foo") → true, "bar"
// configKeyMatchesPrefix("foo.bar", "foo.") → true, "bar"
// configKeyMatchesPrefix("foo.bar", "foo.bar") → true, ""
// configKeyMatchesPrefix("foo.bar", "foo.bar.") → false, ""
// configKeyMatchesPrefix("foo.bar", "foo") → true, "bar"
// configKeyMatchesPrefix("foo.bar", "foo.") → true, "bar"
// configKeyMatchesPrefix("foo.bar", "foo.bar") → true, ""
// configKeyMatchesPrefix("foo.bar", "foo.bar.") → false, ""
func configKeyMatchesPrefix(key, prefix string) (bool, string) {
if prefix == "" {
return true, key
Expand Down
12 changes: 6 additions & 6 deletions git/ref_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func (f intersection) Filter(refname string) bool {
// If `f1` is `nil`, it is treated as including nothing.
type include struct{}

func (_ include) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
func (include) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
if f1 == nil {
return f2
}
return union{f1, f2}
}

func (_ include) Inverted() Combiner {
func (include) Inverted() Combiner {
return Exclude
}

Expand All @@ -61,31 +61,31 @@ func (f union) Filter(refname string) bool {
// If `f1` is `nil`, it is treated as including everything.
type exclude struct{}

func (_ exclude) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
func (exclude) Combine(f1, f2 ReferenceFilter) ReferenceFilter {
if f1 == nil {
return inverse{f2}
}
return intersection{f1, inverse{f2}}

}

func (_ exclude) Inverted() Combiner {
func (exclude) Inverted() Combiner {
return include{}
}

var Exclude exclude

type allReferencesFilter struct{}

func (_ allReferencesFilter) Filter(_ string) bool {
func (allReferencesFilter) Filter(_ string) bool {
return true
}

var AllReferencesFilter allReferencesFilter

type noReferencesFilter struct{}

func (_ noReferencesFilter) Filter(_ string) bool {
func (noReferencesFilter) Filter(_ string) bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion git/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Reference struct {
// `Reference`. It is assumed that `line` is formatted like the output
// of
//
// git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'
// git for-each-ref --format='%(objectname) %(objecttype) %(objectsize) %(refname)'
func ParseReference(line string) (Reference, error) {
words := strings.Split(line, " ")
if len(words) != 4 {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/github/git-sizer

go 1.17
go 1.26

require (
github.com/cli/safeexec v1.0.0
Expand Down
27 changes: 0 additions & 27 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
github.com/cli/safeexec v1.0.0 h1:0VngyaIyqACHdcMNWfo6+KdUYnqEr2Sg+bSP1pdF+dI=
github.com/cli/safeexec v1.0.0/go.mod h1:Z/D4tTN8Vs5gXYHDCbaM1S/anmEDnJb1iW0+EJ5zx3Q=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -23,36 +22,10 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk=
go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
10 changes: 5 additions & 5 deletions internal/refopts/filter_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ func (v *filterValue) Set(s string) error {

// Interpret an option argument flexibly:
//
// * If it is bracketed with `/` characters, treat it as a regexp.
// - If it is bracketed with `/` characters, treat it as a regexp.
//
// * If it starts with `@`, then consider it a refgroup name. That
// refgroup must already be defined. Use its filter. This construct
// is only allowed at the top level.
// - If it starts with `@`, then consider it a refgroup name. That
// refgroup must already be defined. Use its filter. This construct
// is only allowed at the top level.
//
// * Otherwise treat it as a prefix.
// - Otherwise treat it as a prefix.
func (v *filterValue) interpretFlexibly(s string) (git.ReferenceFilter, error) {
if len(s) >= 2 && strings.HasPrefix(s, "/") && strings.HasSuffix(s, "/") {
pattern := s[1 : len(s)-1]
Expand Down
6 changes: 3 additions & 3 deletions internal/testutils/repoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -150,8 +151,7 @@ func CleanGitEnv() []string {
func (repo *TestRepo) GitCommand(t *testing.T, args ...string) *exec.Cmd {
t.Helper()

gitArgs := []string{"-C", repo.Path}
gitArgs = append(gitArgs, args...)
gitArgs := slices.Concat([]string{"-C", repo.Path}, args)

//nolint:gosec // The args all come from the test code.
cmd := exec.Command("git", gitArgs...)
Expand Down Expand Up @@ -229,7 +229,7 @@ func (repo *TestRepo) AddFile(t *testing.T, relativePath, contents string) {
}

filename := filepath.Join(repo.Path, relativePath)
f, err := os.Create(filename)
f, err := os.Create(filename) //nolint:gosec // The path comes from the test code.
require.NoErrorf(t, err, "creating file %q", filename)
_, err = f.WriteString(contents)
require.NoErrorf(t, err, "writing to file %q", filename)
Expand Down
8 changes: 4 additions & 4 deletions sizes/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ func (r *treeRecord) initialize(g *Graph, oid git.OID, tree *git.Tree) error {
}
name := entry.Name

switch {
case entry.Filemode&0o170000 == 0o40000:
switch entry.Filemode & 0o170000 {
case 0o40000:
// Tree
listener := func(size TreeSize) {
// This listener is called when the tree pointed to by
Expand All @@ -542,12 +542,12 @@ func (r *treeRecord) initialize(g *Graph, oid git.OID, tree *git.Tree) error {
}
r.entryCount.Increment(1)

case entry.Filemode&0o170000 == 0o160000:
case 0o160000:
// Commit (i.e., submodule)
r.size.addSubmodule(name)
r.entryCount.Increment(1)

case entry.Filemode&0o170000 == 0o120000:
case 0o120000:
// Symlink
g.pathResolver.RecordTreeEntry(oid, name, entry.OID)

Expand Down
9 changes: 4 additions & 5 deletions sizes/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ func (t *Threshold) Type() string {
// A `pflag.Value` that can be used as a boolean option that sets a
// `Threshold` variable to a fixed value. For example,
//
// pflag.Var(
// sizes.NewThresholdFlagValue(&threshold, 30),
// "critical", "only report critical statistics",
// )
// pflag.Var(
// sizes.NewThresholdFlagValue(&threshold, 30),
// "critical", "only report critical statistics",
// )
//
// adds a `--critical` flag that sets `threshold` to 30.
type thresholdFlagValue struct {
Expand Down Expand Up @@ -470,7 +470,6 @@ func (s *HistorySize) contents(refGroups []RefGroup) tableContents {
metric := counts.Metric
binary := counts.Binary

//nolint:prealloc // The length is not known in advance.
var rgis []tableContents
for _, rg := range refGroups {
if rg.Symbol == "" {
Expand Down
10 changes: 5 additions & 5 deletions sizes/path_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ func (n NullPathResolver) RequestPath(oid git.OID, objectType string) *Path {
}
}

func (_ NullPathResolver) ForgetPath(p *Path) {}
func (NullPathResolver) ForgetPath(p *Path) {}

func (_ NullPathResolver) RecordName(name string, oid git.OID) {}
func (NullPathResolver) RecordName(name string, oid git.OID) {}

func (_ NullPathResolver) RecordTreeEntry(oid git.OID, name string, childOID git.OID) {}
func (NullPathResolver) RecordTreeEntry(oid git.OID, name string, childOID git.OID) {}

func (_ NullPathResolver) RecordCommit(oid, tree git.OID) {}
func (NullPathResolver) RecordCommit(oid, tree git.OID) {}

func (_ NullPathResolver) RecordTag(oid git.OID, tag *git.Tag) {}
func (NullPathResolver) RecordTag(oid git.OID, tag *git.Tag) {}

type InOrderPathResolver struct {
lock sync.Mutex
Expand Down
Loading