MCPcopy Index your code
hub / github.com/go-git/go-git / findMatchInFiles

Function findMatchInFiles

worktree.go:941–976  ·  view source on GitHub ↗

findMatchInFiles takes a FileIter, worktree name and GrepOptions, and returns a slice of GrepResult containing the result of regex pattern matching in content of all the files.

(fileiter *object.FileIter, treeName string, opts *GrepOptions)

Source from the content-addressed store, hash-verified

939// returns a slice of GrepResult containing the result of regex pattern matching
940// in content of all the files.
941func findMatchInFiles(fileiter *object.FileIter, treeName string, opts *GrepOptions) ([]GrepResult, error) {
942 var results []GrepResult
943
944 err := fileiter.ForEach(func(file *object.File) error {
945 var fileInPathSpec bool
946
947 // When no pathspecs are provided, search all the files.
948 if len(opts.PathSpecs) == 0 {
949 fileInPathSpec = true
950 }
951
952 // Check if the file name matches with the pathspec. Break out of the
953 // loop once a match is found.
954 for _, pathSpec := range opts.PathSpecs {
955 if pathSpec != nil && pathSpec.MatchString(file.Name) {
956 fileInPathSpec = true
957 break
958 }
959 }
960
961 // If the file does not match with any of the pathspec, skip it.
962 if !fileInPathSpec {
963 return nil
964 }
965
966 grepResults, err := findMatchInFile(file, treeName, opts)
967 if err != nil {
968 return err
969 }
970 results = append(results, grepResults...)
971
972 return nil
973 })
974
975 return results, err
976}
977
978// findMatchInFile takes a single File, worktree name and GrepOptions,
979// and returns a slice of GrepResult containing the result of regex pattern

Callers 1

GrepMethod · 0.85

Calls 2

findMatchInFileFunction · 0.85
ForEachMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…