Module: Dockly::History

Defined in:
lib/dockly/history.rb

Overview

This module contains logic to find matching content hash for a given commit.

Constant Summary collapse

ASCII_FILE_SEP =
28.chr
ASCII_RECORD_SEP =
30.chr
TAG_PREFIX =
'dockly-'

Class Method Summary collapse

Class Method Details

.content_hash_for(paths) ⇒ Object



47
48
49
50
51
52
53
54
55
# 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_tagObject



39
40
41
# File 'lib/dockly/history.rb', line 39

def 
  @content_tag ||= TAG_PREFIX + content_hash_for(ls_files)
end

.duplicate_build?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/dockly/history.rb', line 22

def duplicate_build?
  !duplicate_build_sha.nil?
end

.duplicate_build_shaObject



26
27
28
29
30
# File 'lib/dockly/history.rb', line 26

def duplicate_build_sha
  return @duplicate_build_sha if @duplicate_build_sha
  sha = tags[]
  @duplicate_build_sha = sha unless sha == repo.capturing.rev_parse('HEAD').chomp
end

.ls_filesObject



43
44
45
# 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!Object



10
11
12
13
14
15
16
# File 'lib/dockly/history.rb', line 10

def 
  refs = ["refs/tags/#{}"]
  remotes = repo.capturing.remote(:v => true).split(/\n/).map{ |r| r.split.first }.uniq
  remotes.each do |remote|
    repo.push(remote, refs)
  end
end

.repoObject



57
58
59
# File 'lib/dockly/history.rb', line 57

def repo
  @repo ||= MiniGit.new('.')
end

.tagsObject



32
33
34
35
36
37
# File 'lib/dockly/history.rb', line 32

def tags
  @tags ||= Hash.new do |hash, key|
    tag = repo.capturing.show_ref({ :tags => true }, key).chomp rescue nil
    hash[key] = repo.capturing.rev_parse(key).chomp if tag
  end
end

.write_content_tag!Object



18
19
20
# File 'lib/dockly/history.rb', line 18

def 
  repo.tag('-f', , repo.capturing.rev_parse('HEAD').chomp)
end