Skip to content

Commit

Permalink
fix: performance of template loading (#1189)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
matejvasek committed Aug 25, 2022
1 parent 81289dc commit dca11da
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down

0 comments on commit dca11da

Please sign in to comment.