MCPcopy
hub / github.com/git-lfs/git-lfs / getAll

Method getAll

config/url_config.go:59–166  ·  view source on GitHub ↗
(prefix, rawurl, key string)

Source from the content-addressed store, hash-verified

57}
58
59func (c *URLConfig) getAll(prefix, rawurl, key string) []string {
60 type urlMatch struct {
61 key string // The full configuration key
62 hostScore int // A score indicating the strength of the host match
63 pathScore int // A score indicating the strength of the path match
64 userMatch int // Whether we matched on a username. 1 for yes, else 0
65 }
66
67 searchURL, err := url.Parse(rawurl)
68 if err != nil {
69 return nil
70 }
71
72 config := c.git.All()
73
74 re := regexp.MustCompile(fmt.Sprintf(`\A%s\.(\S+)\.%s\z`, prefix, key))
75
76 bestMatch := urlMatch{
77 key: "",
78 hostScore: 0,
79 pathScore: 0,
80 userMatch: 0,
81 }
82
83 for k := range config {
84 // Ensure we're examining the correct type of key and parse out the URL
85 matches := re.FindStringSubmatch(k)
86 if matches == nil {
87 continue
88 }
89 configURL, err := url.Parse(matches[1])
90 if err != nil {
91 continue
92 }
93
94 match := urlMatch{
95 key: k,
96 }
97
98 // Rule #1: Scheme must match exactly
99 if searchURL.Scheme != configURL.Scheme {
100 continue
101 }
102
103 // Rule #2: Hosts must match exactly, or through wildcards. More exact
104 // matches should take priority over wildcard matches
105 match.hostScore = compareHosts(searchURL.Hostname(), configURL.Hostname())
106
107 if match.hostScore == 0 {
108 continue
109 }
110
111 if match.hostScore < bestMatch.hostScore {
112 continue
113 }
114
115 // Rule #3: Port Number must match exactly
116 if portForURL(searchURL) != portForURL(configURL) {

Callers 2

GetMethod · 0.95
GetAllMethod · 0.95

Calls 5

compareHostsFunction · 0.85
portForURLFunction · 0.85
comparePathsFunction · 0.85
AllMethod · 0.65
GetAllMethod · 0.65

Tested by

no test coverage detected