Class: Churn::GitAnalyzer
Instance Method Summary
collapse
#initialize
Instance Method Details
#get_logs ⇒ Object
4
5
6
|
# File 'lib/churn/git_analyzer.rb', line 4
def get_logs
`git log #{date_range} --name-only --pretty=format:`.split(/\n/).reject{|line| line == ""}
end
|
#get_revisions ⇒ Object
8
9
10
|
# File 'lib/churn/git_analyzer.rb', line 8
def get_revisions
`git log #{date_range} --pretty=format:"%H"`.split(/\n/).reject{|line| line == ""}
end
|
#get_updated_files_change_info(revision, revisions) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/churn/git_analyzer.rb', line 23
def get_updated_files_change_info(revision, revisions)
updated = {}
logs = get_updated_files_from_log(revision, revisions)
recent_file = nil
logs.each do |line|
if line.match(/^---/) || line.match(/^\+\+\+/)
recent_file = get_recent_file(line)
updated[recent_file] = [] unless updated.include?(recent_file)
elsif line.match(/^@@/)
removed_range = get_changed_range(line, '-')
added_range = get_changed_range(line, '\+')
updated[recent_file] << removed_range
updated[recent_file] << added_range
else
puts line.match(/^---/)
raise "git diff lines that don't match the two patterns aren't expected: '#{line}'"
end
end
updated
end
|
#get_updated_files_from_log(revision, revisions) ⇒ Object
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/churn/git_analyzer.rb', line 12
def get_updated_files_from_log(revision, revisions)
current_index = revisions.index(revision)
previous_index = current_index+1
previous_revision = revisions[previous_index] unless revisions.length < previous_index
if revision && previous_revision
`git diff #{revision} #{previous_revision} --unified=0`.split(/\n/).select{|line| line.match(/^@@/) || line.match(/^---/) || line.match(/^\+\+\+/) }
else
[]
end
end
|