Class: GitHealthCheck::History

Inherits:
Object
  • Object
show all
Defined in:
lib/git-health-check/history.rb

Constant Summary collapse

MEGABYTE =
1024 ** 2

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ History

Returns a new instance of History.



10
11
12
13
14
# File 'lib/git-health-check/history.rb', line 10

def initialize(options)
  @repository = options[:repository]
  @bytes_threshold = options[:threshold].to_f * MEGABYTE
  @git_lib = GitHealthCheck::GitLib.new
end

Instance Method Details

#searchObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/git-health-check/history.rb', line 16

def search
  revision_list = @git_lib.get_revision_list.split "\n"
  big_files = {}

  revision_list.each do |commit|
    @git_lib.get_treeish_contents(commit).split("\0").each do |object|
      bits, type, sha, size, path = object.split
      next if File.exist?("#@repository/#{path}")
      size = size.to_f
      big_files[path] = [sha, size, commit] if size >= @bytes_threshold
    end
  end

  big_files = big_files.map do |path, (sha, size, commit_sha)|
    where = @git_lib.get_commit_details commit_sha
    who = @git_lib.get_commit_author commit_sha
    [sha, (size / MEGABYTE).round(2), path, where, who]
  end

  big_files.sort_by! { |a| [a[1], a[2]] }.reverse!

end