comparePaths compares a path with a configuration path to determine a match. It returns an integer indicating the strength of the match, or 0 if the two paths did not match.
(rawSearchPath, rawConfigPath string)
| 213 | // It returns an integer indicating the strength of the match, or 0 if the two |
| 214 | // paths did not match. |
| 215 | func comparePaths(rawSearchPath, rawConfigPath string) int { |
| 216 | f := func(c rune) bool { |
| 217 | return c == '/' |
| 218 | } |
| 219 | searchPath := strings.FieldsFunc(rawSearchPath, f) |
| 220 | configPath := strings.FieldsFunc(rawConfigPath, f) |
| 221 | |
| 222 | if len(searchPath) < len(configPath) { |
| 223 | return 0 |
| 224 | } |
| 225 | |
| 226 | // Start with a base score of 1, so we return something above 0 for a |
| 227 | // zero-length path |
| 228 | score := 1 |
| 229 | |
| 230 | for i, element := range configPath { |
| 231 | searchElement := searchPath[i] |
| 232 | |
| 233 | if element == searchElement { |
| 234 | score += 2 |
| 235 | continue |
| 236 | } |
| 237 | |
| 238 | if isDefaultLFSUrl(searchElement, searchPath, i+1) { |
| 239 | if searchElement[0:len(searchElement)-4] == element { |
| 240 | // Since we matched without the `.git` prefix, only add one |
| 241 | // point to the score instead of 2 |
| 242 | score++ |
| 243 | continue |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return 0 |
| 248 | } |
| 249 | |
| 250 | return score |
| 251 | } |
| 252 | |
| 253 | func (c *URLConfig) hostsAndPaths(rawurl string) (hosts, paths []string) { |
| 254 | u, err := url.Parse(rawurl) |
no test coverage detected