Class: GitHealthCheck::History

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

Constant Summary collapse

MEGABYTE =
1000 ** 2

Instance Method Summary collapse

Constructor Details

#initialize(repository, head = 'HEAD', threshold = 0.1) ⇒ History

Returns a new instance of History.



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

def initialize(repository, head = 'HEAD', threshold = 0.1)
  @head = head
  @bytes_threshold = threshold.to_f * MEGABYTE
  Dir.chdir repository
  @git_lib = GitHealthCheck::GitLib.new repository
end

Instance Method Details

#searchObject



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

def search

  big_files = {}

  # list commit objects in chronological order
  IO.popen("git rev-list #@head", 'r') do |rev_list|
    rev_list.each_line do |commit|
      # list contents of the tree object
      `git ls-tree -zrl #{commit.chomp!}`.split("\0").each do |object|
        bits, type, sha, size, path = object.split(/\s+/, 5)
        size = size.to_i
        big_files[sha] = [path, size, commit] if size >= @bytes_threshold
      end
    end
  end

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