2021-11-14 00:16:53 +00:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
2022-05-24 20:13:38 +00:00
|
|
|
"io"
|
2022-05-24 19:25:51 +00:00
|
|
|
"net/url"
|
2021-11-14 00:16:53 +00:00
|
|
|
"os"
|
2022-05-24 19:25:51 +00:00
|
|
|
"regexp"
|
2023-05-06 00:27:46 +00:00
|
|
|
"sync"
|
2021-11-14 00:16:53 +00:00
|
|
|
)
|
|
|
|
|
2022-05-24 19:25:51 +00:00
|
|
|
var gitRemoteRe = regexp.MustCompile(`^(?:(?:git@|https://)([\w.@]+)(?:/|:))((?:[\w-_]+)/(?:[\w-_/]+))(?:.git){0,1}(?:(?:/){0,1})$`)
|
|
|
|
|
2023-05-06 00:27:46 +00:00
|
|
|
var oneGitPull sync.Mutex
|
|
|
|
|
2021-11-14 00:16:53 +00:00
|
|
|
func countFileInDir(dirname string) (int, error) {
|
|
|
|
files, err := os.ReadDir(dirname)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(files), nil
|
|
|
|
}
|
|
|
|
|
2023-05-03 08:54:02 +00:00
|
|
|
func (i GitImporter) Exists(filename string) bool {
|
|
|
|
return i.li.Exists(filename)
|
2021-11-14 00:16:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i GitImporter) toURL(filename string) string {
|
|
|
|
return i.li.toURL(filename)
|
|
|
|
}
|
|
|
|
|
2022-05-22 23:39:35 +00:00
|
|
|
func (i GitImporter) GetLocalPath(filename ...string) string {
|
|
|
|
return i.li.GetLocalPath(filename...)
|
|
|
|
}
|
|
|
|
|
2021-11-14 00:16:53 +00:00
|
|
|
func (i GitImporter) importFile(URI string, next func(string, string) (interface{}, error)) (interface{}, error) {
|
|
|
|
return i.li.importFile(URI, next)
|
|
|
|
}
|
|
|
|
|
2023-11-25 16:13:31 +00:00
|
|
|
func (i GitImporter) GetFile(filename string) (io.Reader, error) {
|
|
|
|
return i.li.GetFile(filename)
|
2021-11-14 00:16:53 +00:00
|
|
|
}
|
|
|
|
|
2022-05-24 20:13:38 +00:00
|
|
|
func (i GitImporter) writeFile(filename string, reader io.Reader) error {
|
|
|
|
return i.li.writeFile(filename, reader)
|
|
|
|
}
|
|
|
|
|
2023-11-25 16:13:31 +00:00
|
|
|
func (i GitImporter) ListDir(filename string) ([]string, error) {
|
|
|
|
return i.li.ListDir(filename)
|
2021-11-14 00:16:53 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 16:13:31 +00:00
|
|
|
func (i GitImporter) Stat(filename string) (os.FileInfo, error) {
|
|
|
|
return i.li.Stat(filename)
|
2021-11-14 00:16:53 +00:00
|
|
|
}
|
2022-01-20 14:29:49 +00:00
|
|
|
|
|
|
|
func (i GitImporter) Kind() string {
|
|
|
|
return "git originated from " + i.Remote + " on " + i.li.Kind()
|
|
|
|
}
|
2022-05-24 19:25:51 +00:00
|
|
|
|
|
|
|
func getForgeBaseLink(remote string) (u *url.URL, err error) {
|
|
|
|
res := gitRemoteRe.FindStringSubmatch(remote)
|
|
|
|
u, err = url.Parse(res[2])
|
|
|
|
u.Scheme = "https"
|
|
|
|
u.Host = res[1]
|
|
|
|
return
|
|
|
|
}
|
2023-10-23 10:03:40 +00:00
|
|
|
|
|
|
|
type GitSubmoduleStatus struct {
|
|
|
|
Hash string `json:"hash"`
|
|
|
|
Text string `json:"text,omitempty"`
|
|
|
|
Path string `json:"path"`
|
|
|
|
Branch string `json:"branch"`
|
|
|
|
}
|