generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
Description
Description
Check if it's possible to check the last commit for the function's remote without cloning the whole repository. The current code is costing a lot of memory. To improve that, we can use the current library to build a solution similar to the previous solution based on the libgit2 library.
Code example:
func GetLatestCommit(url, reference string, gitAuth *GitAuth) (string, error) {
gitRepo, _ := git.Init(memory.NewStorage(), nil)
newRemote, _ := gitRepo.CreateRemote(&config.RemoteConfig{
// implement
})
_ = newRemote.Fetch(&git.FetchOptions{
// implement
})
ref, _ := gitRepo.Reference(plumbing.ReferenceName(reference), true)
return ref.Hash().String(), nil
}Reasons
Speed up while process and decrease memory and CPU consumption to avoid problems like this.