mirror of https://github.com/knative/func.git
fix: performance of template loading (#1189)
If repo is non-bare git repo treat is as plain FS template, i.e. do not load it from ".git" date. Signed-off-by: Matej Vasek <mvasek@redhat.com> Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
81289dc757
commit
dca11dad5b
|
|
@ -184,6 +184,10 @@ func filesystemFromURI(uri string) (f Filesystem, err error) {
|
|||
return EmbeddedTemplatesFS, nil
|
||||
}
|
||||
|
||||
if isNonBareGitRepo(uri) {
|
||||
return filesystemFromPath(uri)
|
||||
}
|
||||
|
||||
// Attempt to get a filesystem from the uri as a remote repo.
|
||||
f, err = filesystemFromRepo(uri)
|
||||
if f != nil || err != nil {
|
||||
|
|
@ -194,6 +198,22 @@ func filesystemFromURI(uri string) (f Filesystem, err error) {
|
|||
return filesystemFromPath(uri)
|
||||
}
|
||||
|
||||
func isNonBareGitRepo(uri string) bool {
|
||||
parsed, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if parsed.Scheme != "file" {
|
||||
return false
|
||||
}
|
||||
p := filepath.Join(filepath.FromSlash(uri[7:]), ".git")
|
||||
fi, err := os.Stat(p)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return fi.IsDir()
|
||||
}
|
||||
|
||||
// filesystemFromRepo attempts to fetch a filesystem from a git repository
|
||||
// indicated by the given URI. Returns nil if there is not a repo at the URI.
|
||||
func filesystemFromRepo(uri string) (Filesystem, error) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue