class R10K::Git::ShellGit::ThinRepository
Manage a Git working repository backed with cached bare repositories. Instead of duplicating all objects for new clones and updates, this uses Git alternate object databases to reuse objects from an existing repository, making new clones very lightweight.
Public Class Methods
new(basedir, dirname, cache_repo)
click to toggle source
Calls superclass method
R10K::Git::ShellGit::WorkingRepository.new
# File lib/r10k/git/shellgit/thin_repository.rb, line 11 def initialize(basedir, dirname, cache_repo) @cache_repo = cache_repo super(basedir, dirname) end
Public Instance Methods
cache()
click to toggle source
@return [String] The origin remote URL
# File lib/r10k/git/shellgit/thin_repository.rb, line 38 def cache git(['config', '--get', 'remote.cache.url'], :path => @path.to_s, :raise_on_fail => false).stdout end
clone(remote, opts = {})
click to toggle source
Clone this git repository
@param remote [String] The Git remote to clone @param opts [Hash]
@options opts [String] :ref The git ref to check out on clone
@return [void]
Calls superclass method
R10K::Git::ShellGit::WorkingRepository#clone
# File lib/r10k/git/shellgit/thin_repository.rb, line 24 def clone(remote, opts = {}) # todo check if opts[:reference] is set @cache_repo.sync super(remote, opts.merge(:reference => @cache_repo.git_dir.to_s)) setup_cache_remote end
fetch(remote = 'cache')
click to toggle source
Fetch refs from the backing bare Git repository.
# File lib/r10k/git/shellgit/thin_repository.rb, line 33 def fetch(remote = 'cache') git ['fetch', remote], :path => @path.to_s end
Private Instance Methods
git(cmd, opts = {})
click to toggle source
Calls superclass method
R10K::Git::ShellGit::BaseRepository#git
# File lib/r10k/git/shellgit/thin_repository.rb, line 49 def git(cmd, opts = {}) if !@_synced_alternates sync_alternates @_synced_alternates = true end super end
setup_cache_remote()
click to toggle source
# File lib/r10k/git/shellgit/thin_repository.rb, line 44 def setup_cache_remote git ["remote", "add", "cache", @cache_repo.git_dir.to_s], :path => @path.to_s fetch end
sync_alternates()
click to toggle source
# File lib/r10k/git/shellgit/thin_repository.rb, line 57 def sync_alternates if git_dir.exist? entry_added = alternates.add?(@cache_repo.objects_dir.to_s) if entry_added logger.debug2 { "Updated repo #{@path} to include alternate object db path #{@cache_repo.objects_dir}" } end end end