MCPcopy Index your code
hub / github.com/github/git-sizer / configKeyMatchesPrefix

Function configKeyMatchesPrefix

git/gitconfig.go:96–114  ·  view source on GitHub ↗

configKeyMatchesPrefix checks whether `key` starts with `prefix` at a component boundary (i.e., at a '.'). If yes, it returns `true` and the part of the key after the prefix; e.g.: configKeyMatchesPrefix("foo.bar", "foo") → true, "bar" configKeyMatchesPrefix("foo.bar", "foo.") → true, "bar" configK

(key, prefix string)

Source from the content-addressed store, hash-verified

94// configKeyMatchesPrefix("foo.bar", "foo.bar") → true, ""
95// configKeyMatchesPrefix("foo.bar", "foo.bar.") → false, ""
96func configKeyMatchesPrefix(key, prefix string) (bool, string) {
97 if prefix == "" {
98 return true, key
99 }
100 if !strings.HasPrefix(key, prefix) {
101 return false, ""
102 }
103
104 if prefix[len(prefix)-1] == '.' {
105 return true, key[len(prefix):]
106 }
107 if len(key) == len(prefix) {
108 return true, ""
109 }
110 if key[len(prefix)] == '.' {
111 return true, key[len(prefix)+1:]
112 }
113 return false, ""
114}
115
116func (repo *Repository) ConfigStringDefault(key string, defaultValue string) (string, error) {
117 cmd := repo.GitCommand(

Callers 2

GetConfigMethod · 0.85

Calls

no outgoing calls

Tested by 1