Skip to content

Commit

Permalink
Optimise calls to get git status dict
Browse files Browse the repository at this point in the history
  • Loading branch information
randrei-adobe committed May 2, 2024
1 parent c423c37 commit 958f48a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gitops/prer/create_gitops_prs.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,12 @@ func getGitStatusDict(workdir *git.Repo, branchName string) map[string]interface
return ctx
}

func stampFile(fullPath string, workdir *git.Repo, branchName string) {
func stampFile(fullPath string, ctx map[string]interface{}) {
template, err := os.ReadFile(fullPath)
if err != nil {
log.Fatal(err)
}

ctx := getGitStatusDict(workdir, branchName)

outf, err := os.OpenFile(fullPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -228,13 +226,16 @@ func main() {
}
if *stamp {
changedFiles := workdir.GetChangedFiles()
for _, filePath := range changedFiles {
fullPath := gitopsdir + "/" + filePath
if digester.VerifyDigest(fullPath) {
workdir.RestoreFile(fullPath)
} else {
digester.SaveDigest(fullPath)
stampFile(fullPath, workdir, *branchName)
if len(changedFiles) > 0 {
ctx := getGitStatusDict(workdir, *branchName)
for _, filePath := range changedFiles {
fullPath := gitopsdir + "/" + filePath
if digester.VerifyDigest(fullPath) {
workdir.RestoreFile(fullPath)
} else {
digester.SaveDigest(fullPath)
stampFile(fullPath, ctx)
}
}
}
}
Expand Down

0 comments on commit 958f48a

Please sign in to comment.