Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 6 files changed
  • 0 comments
  • 1 contributor
10 lib/git_stats.rb
... ... @@ -1,9 +1,9 @@
1   -require "GitStats/version"
2 1
3 2 module GitStats
4   - def init
5   - DataMapper.setup(:default, 'sqlite::memory:')
  3 + autoload "Analyzer"
  4 +
  5 + def self.init
  6 + #DataMapper.setup(:default, 'sqlite::memory:')
  7 + #p Analyzer.parse
6 8 end
7 9 end
8   -
9   -GitStats.init
54 lib/git_stats/analyzer.rb
... ... @@ -1,26 +1,38 @@
1   -@stat ={}
2   -IO.popen('git log --all --pretty=format:"%ae %ad" --shortstat --date=short') do |out|
3   - out.each_line do |string|
4   - string = string.strip
5   - next if string.empty?
6   - if match = string.match(/^([^@\s]+@[^\s]+)\s(.+)$/)
7   - @email = match[1]
8   - if @stat[@email].nil?
9   - @stat[@email]={:commits => 1}
10   - else
11   - commits = @stat[@email][:commits]
12   - commits +=1
13   - @stat[@email][:commits] = commits
  1 +module GitStats
  2 +
  3 + class Analyzer
  4 +
  5 + def initialize
  6 + end
  7 +
  8 + def parse
  9 + stat = {}
  10 +
  11 + IO.popen('git log --all --pretty=format:"%ae %ad" --shortstat --date=short') do |out|
  12 + out.each_line do |string|
  13 + string = string.strip
  14 + next if string.empty?
  15 + if match = string.match(/^([^@\s]+@[^\s]+)\s(.+)$/)
  16 + email = match[1]
  17 + if stat[email].nil?
  18 + stat[email]={:commits => 1}
  19 + else
  20 + commits = stat[email][:commits]
  21 + commits +=1
  22 + stat[email][:commits] = commits
  23 + end
  24 + elsif match = string.match(/(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(\-\)/)
  25 + if stat[email][:line].nil?
  26 + stat[email][:line] = {:add => match[1].to_i, :rm => match[2].to_i}
  27 + else
  28 + stat[email][:line][:add] += match[1].to_i
  29 + stat[email][:line][:rm] += match[2].to_i
  30 + end
  31 + end
  32 + end
14 33 end
15   - elsif match = string.match(/(\d+) files changed, (\d+) insertions\(\+\), (\d+) deletions\(\-\)/)
16   - if @stat[@email][:line].nil?
17   - @stat[@email][:line] = {:add => match[1].to_i, :rm => match[2].to_i}
18   - else
19   - @stat[@email][:line][:add] += match[1].to_i
20   - @stat[@email][:line][:rm] += match[2].to_i
21   - end
  34 + stat
22 35 end
23 36 end
24 37 end
25   -p @stat
26 38
BIN  test/.analyzer_test.rb.swp
Binary file not shown
BIN  test/.test_helper.rb.swp
Binary file not shown
7 test/analyzer_test.rb
... ... @@ -0,0 +1,7 @@
  1 +require 'test_helper'
  2 +
  3 +class AnalyzerTest < MiniTest::Unit::TestCase
  4 + def test_parse
  5 + GitStats.init
  6 + end
  7 +end
3  test/test_helper.rb
... ... @@ -0,0 +1,3 @@
  1 +require 'minitest/unit'
  2 +p 'loading'
  3 +require 'lib/git_stats.rb'

No commit comments for this range

Something went wrong with that request. Please try again.