Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rename walk package to walker
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <brian@bmcgee.ie>
brianmcgee committed Jul 10, 2024
1 parent 327d45e commit a0f479c
Showing 9 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions cache/cache.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import (
"git.numtide.com/numtide/treefmt/stats"

"git.numtide.com/numtide/treefmt/format"
"git.numtide.com/numtide/treefmt/walk"
"git.numtide.com/numtide/treefmt/walker"

"github.com/charmbracelet/log"

@@ -187,7 +187,7 @@ func putEntry(bucket *bolt.Bucket, path string, entry *Entry) error {

// ChangeSet is used to walk a filesystem, starting at root, and outputting any new or changed paths using pathsCh.
// It determines if a path is new or has changed by comparing against cache entries.
func ChangeSet(ctx context.Context, walker walk.Walker, filesCh chan<- *walk.File) error {
func ChangeSet(ctx context.Context, wk walker.Walker, filesCh chan<- *walker.File) error {
start := time.Now()

defer func() {
@@ -205,7 +205,7 @@ func ChangeSet(ctx context.Context, walker walk.Walker, filesCh chan<- *walk.Fil
}
}()

return walker.Walk(ctx, func(file *walk.File, err error) error {
return wk.Walk(ctx, func(file *walker.File, err error) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -264,7 +264,7 @@ func ChangeSet(ctx context.Context, walker walk.Walker, filesCh chan<- *walk.Fil
}

// Update is used to record updated cache information for the specified list of paths.
func Update(files []*walk.File) error {
func Update(files []*walker.File) error {
start := time.Now()
defer func() {
logger.Debugf("finished processing %v paths in %v", len(files), time.Since(start))
10 changes: 5 additions & 5 deletions cli/cli.go
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ import (
"github.com/gobwas/glob"

"git.numtide.com/numtide/treefmt/format"
"git.numtide.com/numtide/treefmt/walk"
"git.numtide.com/numtide/treefmt/walker"
"github.com/alecthomas/kong"
"github.com/charmbracelet/log"
)
@@ -25,7 +25,7 @@ type Format struct {
Formatters []string `short:"f" help:"Specify formatters to apply. Defaults to all formatters."`
TreeRoot string `type:"existingdir" xor:"tree-root" help:"The root directory from which treefmt will start walking the filesystem (defaults to the directory containing the config file)."`
TreeRootFile string `type:"string" xor:"tree-root" help:"File to search for to find the project root (if --tree-root is not passed)."`
Walk walk.Type `enum:"auto,git,filesystem" default:"auto" help:"The method used to traverse the files within --tree-root. Currently supports 'auto', 'git' or 'filesystem'."`
Walk walker.Type `enum:"auto,git,filesystem" default:"auto" help:"The method used to traverse the files within --tree-root. Currently supports 'auto', 'git' or 'filesystem'."`
GitAllFiles bool `default:"false" help:"Forces the git walker to ignore change tracking and emit all files for processing instead of only those that have changed."`

Verbosity int `name:"verbose" short:"v" type:"counter" default:"0" env:"LOG_LEVEL" help:"Set the verbosity of logs e.g. -vv."`
@@ -42,9 +42,9 @@ type Format struct {
formatters map[string]*format.Formatter
globalExcludes []glob.Glob

filesCh chan *walk.File
formattedCh chan *walk.File
processedCh chan *walk.File
filesCh chan *walker.File
formattedCh chan *walker.File
processedCh chan *walker.File
}

func (f *Format) configureLogging() {
18 changes: 9 additions & 9 deletions cli/format.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ import (

"git.numtide.com/numtide/treefmt/cache"
"git.numtide.com/numtide/treefmt/config"
"git.numtide.com/numtide/treefmt/walk"
"git.numtide.com/numtide/treefmt/walker"

"github.com/charmbracelet/log"
"golang.org/x/sync/errgroup"
@@ -147,13 +147,13 @@ func (f *Format) Run() (err error) {

// create a channel for files needing to be processed
// we use a multiple of batch size here as a rudimentary concurrency optimization based on the host machine
f.filesCh = make(chan *walk.File, BatchSize*runtime.NumCPU())
f.filesCh = make(chan *walker.File, BatchSize*runtime.NumCPU())

// create a channel for files that have been formatted
f.formattedCh = make(chan *walk.File, cap(f.filesCh))
f.formattedCh = make(chan *walker.File, cap(f.filesCh))

// create a channel for files that have been processed
f.processedCh = make(chan *walk.File, cap(f.filesCh))
f.processedCh = make(chan *walker.File, cap(f.filesCh))

// start concurrent processing tasks in reverse order
eg.Go(f.updateCache(ctx))
@@ -175,7 +175,7 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {
walkerType := f.Walk

if f.Stdin {
walkerType = walk.Filesystem
walkerType = walker.Filesystem

// check we have only received one path arg which we use for the file extension / matching to formatters
if len(f.Paths) != 1 {
@@ -222,7 +222,7 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {
}

// create a filesystem walker
walker, err := walk.New(walkerType, f.TreeRoot, f.GitAllFiles, pathsCh)
wk, err := walker.New(walkerType, f.TreeRoot, f.GitAllFiles, pathsCh)
if err != nil {
return fmt.Errorf("failed to create walker: %w", err)
}
@@ -232,7 +232,7 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {

// if no cache has been configured, or we are processing from stdin, we invoke the walker directly
if f.NoCache || f.Stdin {
return walker.Walk(ctx, func(file *walk.File, err error) error {
return wk.Walk(ctx, func(file *walker.File, err error) error {
select {
case <-ctx.Done():
return ctx.Err()
@@ -247,7 +247,7 @@ func (f *Format) walkFilesystem(ctx context.Context) func() error {

// otherwise we pass the walker to the cache and have it generate files for processing based on whether or not
// they have been added/changed since the last invocation
if err = cache.ChangeSet(ctx, walker, f.filesCh); err != nil {
if err = cache.ChangeSet(ctx, wk, f.filesCh); err != nil {
return fmt.Errorf("failed to generate change set: %w", err)
}
return nil
@@ -419,7 +419,7 @@ func (f *Format) detectFormatted(ctx context.Context) func() error {
func (f *Format) updateCache(ctx context.Context) func() error {
return func() error {
// used to batch updates for more efficient txs
batch := make([]*walk.File, 0, BatchSize)
batch := make([]*walker.File, 0, BatchSize)

// apply a batch
processBatch := func() error {
4 changes: 2 additions & 2 deletions format/formatter.go
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"os/exec"
"time"

"git.numtide.com/numtide/treefmt/walk"
"git.numtide.com/numtide/treefmt/walker"

"git.numtide.com/numtide/treefmt/config"

@@ -89,7 +89,7 @@ func (f *Formatter) Apply(ctx context.Context, tasks []*Task) error {

// Wants is used to test if a Formatter wants a path based on it's configured Includes and Excludes patterns.
// Returns true if the Formatter should be applied to path, false otherwise.
func (f *Formatter) Wants(file *walk.File) bool {
func (f *Formatter) Wants(file *walker.File) bool {
match := !PathMatches(file.RelPath, f.excludes) && PathMatches(file.RelPath, f.includes)
if match {
f.log.Debugf("match: %v", file)
6 changes: 3 additions & 3 deletions format/task.go
Original file line number Diff line number Diff line change
@@ -4,16 +4,16 @@ import (
"cmp"
"slices"

"git.numtide.com/numtide/treefmt/walk"
"git.numtide.com/numtide/treefmt/walker"
)

type Task struct {
File *walk.File
File *walker.File
Formatters []*Formatter
BatchKey string
}

func NewTask(file *walk.File, formatters []*Formatter) Task {
func NewTask(file *walker.File, formatters []*Formatter) Task {
// sort by priority in ascending order
slices.SortFunc(formatters, func(a, b *Formatter) int {
priorityA := a.Priority()
2 changes: 1 addition & 1 deletion walk/filesystem.go → walker/filesystem.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package walk
package walker

import (
"context"
2 changes: 1 addition & 1 deletion walk/filesystem_test.go → walker/filesystem_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package walk
package walker

import (
"context"
2 changes: 1 addition & 1 deletion walk/git.go → walker/git.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package walk
package walker

import (
"context"
2 changes: 1 addition & 1 deletion walk/walker.go → walker/walker.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package walk
package walker

import (
"context"

0 comments on commit a0f479c

Please sign in to comment.