Skip to content

Commit

Permalink
git cache: move cache arg from Sync() to NewSync()
Browse files Browse the repository at this point in the history
This allow to keep the Sync() signature as it was previously
  • Loading branch information
cdevienne committed Jun 20, 2024
1 parent 4e214a0 commit 1735ab0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pkg/vendir/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ func (d *Directory) Sync(syncOpts SyncOpts) (ctlconf.LockDirectory, error) {

switch {
case contents.Git != nil:
gitSync := ctlgit.NewSync(*contents.Git, NewInfoLog(d.ui), syncOpts.RefFetcher)
gitSync := ctlgit.NewSync(*contents.Git, NewInfoLog(d.ui), syncOpts.RefFetcher, syncOpts.Cache)

d.ui.PrintLinef("Fetching: %s + %s (git from %s)", d.opts.Path, contents.Path, gitSync.Desc())

lock, err := gitSync.Sync(stagingDstPath, stagingDir.TempArea(), syncOpts.Cache)
lock, err := gitSync.Sync(stagingDstPath, stagingDir.TempArea())
if err != nil {
return lockConfig, fmt.Errorf("Syncing directory '%s' with git contents: %s", contents.Path, err)
}
Expand Down
13 changes: 7 additions & 6 deletions pkg/vendir/fetch/git/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ type Sync struct {
opts ctlconf.DirectoryContentsGit
log io.Writer
refFetcher ctlfetch.RefFetcher
cache ctlcache.Cache
}

func NewSync(opts ctlconf.DirectoryContentsGit,
log io.Writer, refFetcher ctlfetch.RefFetcher) Sync {
log io.Writer, refFetcher ctlfetch.RefFetcher, cache ctlcache.Cache) Sync {

return Sync{opts, log, refFetcher}
return Sync{opts, log, refFetcher, cache}
}

func (d Sync) Desc() string {
Expand All @@ -41,7 +42,7 @@ func (d Sync) Desc() string {
return fmt.Sprintf("%s@%s", d.opts.URL, ref)
}

func (d Sync) Sync(dstPath string, tempArea ctlfetch.TempArea, cache ctlcache.Cache) (ctlconf.LockDirectoryContentsGit, error) {
func (d Sync) Sync(dstPath string, tempArea ctlfetch.TempArea) (ctlconf.LockDirectoryContentsGit, error) {
gitLockConf := ctlconf.LockDirectoryContentsGit{}

incomingTmpPath, err := tempArea.NewTempDir("git")
Expand All @@ -56,7 +57,7 @@ func (d Sync) Sync(dstPath string, tempArea ctlfetch.TempArea, cache ctlcache.Ca
git := NewGit(d.opts, d.log, d.refFetcher)

var bundle string
if cacheEntry, hasCache := cache.Has(gitCacheType, cacheID); hasCache {
if cacheEntry, hasCache := d.cache.Has(gitCacheType, cacheID); hasCache {
bundle = filepath.Join(cacheEntry, "bundle")
}

Expand All @@ -69,7 +70,7 @@ func (d Sync) Sync(dstPath string, tempArea ctlfetch.TempArea, cache ctlcache.Ca
gitLockConf.Tags = info.Tags
gitLockConf.CommitTitle = d.singleLineCommitTitle(info.CommitTitle)

if _, ok := cache.(*ctlcache.NoCache); !ok {
if _, ok := d.cache.(*ctlcache.NoCache); !ok {
// attempt to save a bundle to the cache
bundleDir, err := tempArea.NewTempDir("bundleCache")
if err != nil {
Expand All @@ -93,7 +94,7 @@ func (d Sync) Sync(dstPath string, tempArea ctlfetch.TempArea, cache ctlcache.Ca
if _, _, err := git.cmdRunner.Run(append([]string{"bundle", "create", bundle}, refs...), nil, incomingTmpPath); err != nil {
return gitLockConf, err
}
if err := cache.Save(gitCacheType, cacheID, bundleDir); err != nil {
if err := d.cache.Save(gitCacheType, cacheID, bundleDir); err != nil {
return gitLockConf, err
}
}
Expand Down

0 comments on commit 1735ab0

Please sign in to comment.