Skip to content

Commit

Permalink
feat: remove relative path optimization in filesystem walker
Browse files Browse the repository at this point in the history
Just rely on `filepath.Rel` as the optimization wasn't adding much and just complicated things.

Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Sep 24, 2024
1 parent 147dcdb commit 202acb9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
5 changes: 0 additions & 5 deletions walk/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ func (f filesystemWalker) Root() string {
}

func (f filesystemWalker) relPath(path string) (string, error) {
// quick optimization for the majority of use cases
if len(path) >= f.relPathOffset && path[:len(f.root)] == f.root {
return path[f.relPathOffset:], nil
}
// fallback to proper relative path resolution
return filepath.Rel(f.root, path)
}

Expand Down
8 changes: 4 additions & 4 deletions walk/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package walk
import (
"context"
"fmt"
"github.com/charmbracelet/log"
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/format/index"
"io/fs"
"os"
"path/filepath"
"strings"

"github.com/charmbracelet/log"
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/format/index"

"github.com/go-git/go-git/v5"
)

Expand Down Expand Up @@ -95,7 +96,6 @@ func (g gitWalker) Walk(ctx context.Context, fn WalkFunc) error {
var cache *fileTree

for path := range g.paths {

switch path {

case g.root:
Expand Down
4 changes: 2 additions & 2 deletions walk/git_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package walk

import (
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/require"
)

func TestFileTree(t *testing.T) {

as := require.New(t)

node := &fileTree{name: ""}
Expand Down

0 comments on commit 202acb9

Please sign in to comment.