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:
Matej Vasek 2022-08-25 15:20:19 +02:00 committed by GitHub
parent 81289dc757
commit dca11dad5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 0 deletions

View File

@ -184,6 +184,10 @@ func filesystemFromURI(uri string) (f Filesystem, err error) {
return EmbeddedTemplatesFS, nil return EmbeddedTemplatesFS, nil
} }
if isNonBareGitRepo(uri) {
return filesystemFromPath(uri)
}
// Attempt to get a filesystem from the uri as a remote repo. // Attempt to get a filesystem from the uri as a remote repo.
f, err = filesystemFromRepo(uri) f, err = filesystemFromRepo(uri)
if f != nil || err != nil { if f != nil || err != nil {
@ -194,6 +198,22 @@ func filesystemFromURI(uri string) (f Filesystem, err error) {
return filesystemFromPath(uri) 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 // 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. // indicated by the given URI. Returns nil if there is not a repo at the URI.
func filesystemFromRepo(uri string) (Filesystem, error) { func filesystemFromRepo(uri string) (Filesystem, error) {