120 lines
2.2 KiB
Go
120 lines
2.2 KiB
Go
// Copyright (C) 2024 Umorpha Systems
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package gitcache
|
|
|
|
import (
|
|
_url "net/url"
|
|
"path"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
// reIsURL mimics git's url.c:is_url()
|
|
var reIsURL = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9+.-]*://`)
|
|
|
|
// NormalizeURL parses a URL in accordance with the "GIT URLS"
|
|
// section of git-fetch(1), and normalizes it.
|
|
func NormalizeURL(url string) (string, bool) {
|
|
switch {
|
|
case reIsURL.MatchString(url):
|
|
u, err := _url.Parse(url)
|
|
if err != nil {
|
|
return "", false
|
|
}
|
|
|
|
// work this left-to-right
|
|
|
|
// 1. scheme
|
|
switch u.Scheme {
|
|
case "ssh",
|
|
"git",
|
|