Class: R10K::Git::Cache Abstract

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Logging, Settings::Mixin
Defined in:
lib/r10k/git/cache.rb

Overview

This class is abstract.

Cache Git repository mirrors for object database reuse.

This implements most of the behavior needed for Git repo caching, but needs to have a specific Git bare repository provided. Subclasses should implement the Cache.bare_repository method.

See Also:

  • git-clone(1)

Direct Known Subclasses

Rugged::Cache, ShellGit::Cache

Constant Summary

Constants included from Logging

Logging::LOG_LEVELS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

debug_formatter, default_formatter, default_outputter, #logger, #logger_name, parse_level

Methods included from Settings::Mixin

included

Constructor Details

#initialize(remote) ⇒ Cache

Returns a new instance of Cache.

Parameters:

  • remote (String)

    The URL of the Git remote URL to cache.



64
65
66
67
# File 'lib/r10k/git/cache.rb', line 64

def initialize(remote)
  @remote = remote
  @repo = self.class.bare_repository.new(settings[:cache_root], sanitized_dirname)
end

Instance Attribute Details

#pathObject (readonly)



54
55
56
57
# File 'lib/r10k/git/cache.rb', line 54

def path
  logger.warn "#{self.class}#path is deprecated; use #git_dir"
  git_dir
end

#repoObject (readonly)

Returns the value of attribute repo.



61
62
63
# File 'lib/r10k/git/cache.rb', line 61

def repo
  @repo
end

Class Method Details

.bare_repositoryObject

This method is abstract.

Returns The concrete bare repository implementation to use for interacting with the cached Git repository.

Returns:

  • (Object)

    The concrete bare repository implementation to use for interacting with the cached Git repository.

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/r10k/git/cache.rb', line 41

def self.bare_repository
  raise NotImplementedError
end

.generate(remote) ⇒ R10K::Git::Cache

Generate a new instance with the given remote or return an existing object with the given remote. This should be used over R10K::Git::Cache.new.

Parameters:

  • remote (String)

    The git remote to cache

Returns:



34
35
36
# File 'lib/r10k/git/cache.rb', line 34

def self.generate(remote)
  instance_cache.generate(remote)
end

.instance_cacheObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
# File 'lib/r10k/git/cache.rb', line 24

def self.instance_cache
  @instance_cache
end

Instance Method Details

#reset!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



96
97
98
# File 'lib/r10k/git/cache.rb', line 96

def reset!
  @synced = false
end

#syncObject



69
70
71
72
73
74
# File 'lib/r10k/git/cache.rb', line 69

def sync
  if !@synced
    sync!
    @synced = true
  end
end

#sync!Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/r10k/git/cache.rb', line 80

def sync!
  if cached?
    @repo.fetch
  else
    logger.debug1 "Creating new git cache for #{@remote.inspect}"

    # TODO extract this to an initialization step
    if !File.exist?(settings[:cache_root])
      FileUtils.mkdir_p settings[:cache_root]
    end

    @repo.clone(@remote)
  end
end

#synced?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/r10k/git/cache.rb', line 76

def synced?
  @synced
end