| 912 | } |
| 913 | |
| 914 | func (s *GitTokenStore) maybeRunGC(repoDir string) { |
| 915 | now := time.Now() |
| 916 | if now.Sub(s.lastGC) < gcInterval { |
| 917 | return |
| 918 | } |
| 919 | s.lastGC = now |
| 920 | |
| 921 | repo, err := git.PlainOpen(repoDir) |
| 922 | if err != nil { |
| 923 | return |
| 924 | } |
| 925 | |
| 926 | pruneOpts := git.PruneOptions{ |
| 927 | OnlyObjectsOlderThan: now, |
| 928 | Handler: repo.DeleteObject, |
| 929 | } |
| 930 | if err := repo.Prune(pruneOpts); err != nil && !errors.Is(err, git.ErrLooseObjectsNotSupported) { |
| 931 | return |
| 932 | } |
| 933 | _ = repo.RepackObjects(&git.RepackConfig{}) |
| 934 | } |
| 935 | |
| 936 | // PersistConfig commits and pushes configuration changes to git. |
| 937 | func (s *GitTokenStore) PersistConfig(_ context.Context) error { |