Refactor string splitting in check.go and fsurls.go to use strings.SplitSeq for improved performance. Enhance debug output for .gitignore and .slinkignore file handling, providing clearer logging during file checks and reads.

This commit is contained in:
Luke Hagar
2025-09-13 01:49:22 +00:00
parent 2df17e8247
commit 211fafe931
2 changed files with 56 additions and 5 deletions

View File

@@ -40,7 +40,7 @@ func init() {
// Parse targets: allow comma-separated chunks
var raw []string
for _, a := range args {
for _, part := range strings.Split(a, ",") {
for part := range strings.SplitSeq(a, ",") {
p := strings.TrimSpace(part)
if p != "" {
raw = append(raw, toSlash(p))
@@ -115,6 +115,7 @@ func init() {
}
merge(res, "", true)
}
// 2) Collect for each concrete root
for _, r := range roots {
clean := toSlash(filepath.Clean(r.path))

View File

@@ -578,39 +578,89 @@ func extractCandidateMatches(content string) []matchCandidate {
func loadGitIgnore(root string) *ignore.GitIgnore {
var lines []string
gi := filepath.Join(root, ".gitignore")
if isDebugEnv() {
fmt.Printf("::debug:: Checking for .gitignore at: %s\n", gi)
}
if _, err := os.Stat(gi); err != nil {
if isDebugEnv() {
fmt.Printf("::debug:: .gitignore not found at: %s\n", gi)
}
return nil
}
if isDebugEnv() {
fmt.Printf("::debug:: Reading .gitignore from: %s\n", gi)
}
if b, err := os.ReadFile(gi); err == nil {
for _, ln := range strings.Split(string(b), "\n") {
for ln := range strings.SplitSeq(string(b), "\n") {
lines = append(lines, ln)
}
}
ge := filepath.Join(root, ".git", "info", "exclude")
if isDebugEnv() {
fmt.Printf("::debug:: Checking for .git/info/exclude at: %s\n", ge)
}
if _, err := os.Stat(ge); err != nil {
if isDebugEnv() {
fmt.Printf("::debug:: .git/info/exclude not found at: %s\n", ge)
}
return nil
}
if isDebugEnv() {
fmt.Printf("::debug:: Reading .git/info/exclude from: %s\n", ge)
}
if b, err := os.ReadFile(ge); err == nil {
for _, ln := range strings.Split(string(b), "\n") {
for ln := range strings.SplitSeq(string(b), "\n") {
lines = append(lines, ln)
}
}
if len(lines) == 0 {
if isDebugEnv() {
fmt.Printf("::debug:: .gitignore or .git/info/exclude is empty\n")
}
return nil
}
if isDebugEnv() {
fmt.Printf("::debug:: Compiling .gitignore and .git/info/exclude\n")
}
return ignore.CompileIgnoreLines(lines...)
}
// .slinkignore support
type slinkyIgnore struct {
IgnorePaths []string `json:"ignorePaths"`
IgnoreURLs []string `json:"ignoreURLs"`
IgnorePaths []string `json:"ignorePaths" optional:"true"`
IgnoreURLs []string `json:"ignoreURLs" optional:"true"`
}
func loadSlinkyIgnore(root string) (*ignore.GitIgnore, []string) {
cfgPath := filepath.Join(root, ".slinkignore")
if isDebugEnv() {
fmt.Printf("::debug:: Checking for .slinkignore at: %s\n", cfgPath)
}
if _, err := os.Stat(cfgPath); err != nil {
if isDebugEnv() {
fmt.Printf("::debug:: .slinkignore not found at: %s\n", cfgPath)
}
return nil, nil
}
if isDebugEnv() {
fmt.Printf("::debug:: Reading .slinkignore from: %s\n", cfgPath)
}
b, err := os.ReadFile(cfgPath)
if err != nil || len(b) == 0 {
if isDebugEnv() {
fmt.Printf("::debug:: .slinkignore is empty or not found at: %s\n", cfgPath)
}
return nil, nil
}
var cfg slinkyIgnore
if jerr := json.Unmarshal(b, &cfg); jerr != nil {
return nil, nil
}
if isDebugEnv() {
fmt.Printf("::debug:: Loaded .slinkignore from: %s\n", cfgPath)
fmt.Printf("::debug:: IgnorePaths: %v\n", cfg.IgnorePaths)
fmt.Printf("::debug:: IgnoreURLs: %v\n", cfg.IgnoreURLs)
}
var ign *ignore.GitIgnore
if len(cfg.IgnorePaths) > 0 {
ign = ignore.CompileIgnoreLines(cfg.IgnorePaths...)