Skip to content

Commit 202acb9

Browse files
committed
feat: remove relative path optimization in filesystem walker
Just rely on `filepath.Rel` as the optimization wasn't adding much and just complicated things. Signed-off-by: Brian McGee <[email protected]>
1 parent 147dcdb commit 202acb9

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

walk/filesystem.go

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ func (f filesystemWalker) Root() string {
1919
}
2020

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

walk/git.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package walk
33
import (
44
"context"
55
"fmt"
6-
"github.com/charmbracelet/log"
7-
"github.com/go-git/go-git/v5/plumbing/filemode"
8-
"github.com/go-git/go-git/v5/plumbing/format/index"
96
"io/fs"
107
"os"
118
"path/filepath"
129
"strings"
1310

11+
"github.com/charmbracelet/log"
12+
"github.com/go-git/go-git/v5/plumbing/filemode"
13+
"github.com/go-git/go-git/v5/plumbing/format/index"
14+
1415
"github.com/go-git/go-git/v5"
1516
)
1617

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

9798
for path := range g.paths {
98-
9999
switch path {
100100

101101
case g.root:

walk/git_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package walk
22

33
import (
4-
"github.com/stretchr/testify/require"
54
"testing"
5+
6+
"github.com/stretchr/testify/require"
67
)
78

89
func TestFileTree(t *testing.T) {
9-
1010
as := require.New(t)
1111

1212
node := &fileTree{name: ""}

0 commit comments

Comments
 (0)