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

Function ParsePattern

plumbing/format/gitignore/pattern.go:41–66  ·  view source on GitHub ↗

ParsePattern parses a gitignore pattern string into the Pattern structure.

(p string, domain []string)

Source from the content-addressed store, hash-verified

39
40// ParsePattern parses a gitignore pattern string into the Pattern structure.
41func ParsePattern(p string, domain []string) Pattern {
42 // storing domain, copy it to ensure it isn't changed externally
43 domain = append([]string(nil), domain...)
44 res := pattern{domain: domain}
45
46 if strings.HasPrefix(p, inclusionPrefix) {
47 res.inclusion = true
48 p = p[1:]
49 }
50
51 if !strings.HasSuffix(p, "\\ ") {
52 p = strings.TrimRight(p, " ")
53 }
54
55 if strings.HasSuffix(p, patternDirSep) {
56 res.dirOnly = true
57 p = p[:len(p)-1]
58 }
59
60 if strings.Contains(p, patternDirSep) {
61 res.isGlob = true
62 }
63
64 res.pattern = strings.Split(p, patternDirSep)
65 return &res
66}
67
68func (p *pattern) Match(path []string, isDir bool) MatchResult {
69 if len(path) <= len(p.domain) {

Calls 1

ContainsMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…