module Dockly::History
This module contains logic to find matching content hash for a given commit.
Constants
- ASCII_FILE_SEP
- ASCII_RECORD_SEP
- TAG_PREFIX
Public Instance Methods
content_hash_for(paths)
click to toggle source
# File lib/dockly/history.rb, line 47 def content_hash_for(paths) paths.sort.each_with_object(Digest::SHA384.new) do |path, hash| next unless File.exist?(path) mode = File::Stat.new(path).mode data = File.read(path) str = [path, mode, data].join(ASCII_RECORD_SEP.chr) + ASCII_FILE_SEP.chr hash.update(str) end.hexdigest end
content_tag()
click to toggle source
# File lib/dockly/history.rb, line 39 def content_tag @content_tag ||= TAG_PREFIX + content_hash_for(ls_files) end
duplicate_build?()
click to toggle source
# File lib/dockly/history.rb, line 22 def duplicate_build? !duplicate_build_sha.nil? end
duplicate_build_sha()
click to toggle source
# File lib/dockly/history.rb, line 26 def duplicate_build_sha return @duplicate_build_sha if @duplicate_build_sha sha = tags[content_tag] @duplicate_build_sha = sha unless sha == repo.capturing.rev_parse('HEAD').chomp end
ls_files()
click to toggle source
# File lib/dockly/history.rb, line 43 def ls_files repo.capturing.ls_tree({ :name_only => true, :r => true }, 'HEAD').split end
push_content_tag!()
click to toggle source
# File lib/dockly/history.rb, line 10 def push_content_tag! refs = ["refs/tags/#{content_tag}"] remotes = repo.capturing.remote(:v => true).split(/\n/).map{ |r| r.split.first }.uniq remotes.each do |remote| repo.push(remote, refs) end end
repo()
click to toggle source
# File lib/dockly/history.rb, line 57 def repo @repo ||= MiniGit.new('.') end
write_content_tag!()
click to toggle source
# File lib/dockly/history.rb, line 18 def write_content_tag! repo.tag('-f', content_tag, repo.capturing.rev_parse('HEAD').chomp) end