git-delta 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -15,11 +15,13 @@ Net lines added: 23
15
15
 
16
16
  ## Usage
17
17
 
18
- $ git-delta -v
19
18
  $ git-delta app lib
20
19
  $ git-delta .js .coffee
21
20
  $ git-delta --author=someone_else
22
21
 
22
+ $ git-delta -v
23
+ $ git-delta -rails
24
+
23
25
  ## Contributing
24
26
 
25
27
  1. Fork it
data/lib/git-delta.rb CHANGED
@@ -1,2 +1,2 @@
1
- require "git-delta/version"
2
- require "git-delta/reporter"
1
+ require_relative "git-delta/version"
2
+ require_relative "git-delta/reporter"
@@ -17,6 +17,7 @@ module Git
17
17
  end
18
18
  end.compact
19
19
  (@warnings ||= []).concat(w)
20
+ self
20
21
  end
21
22
 
22
23
  def delta
@@ -31,12 +32,14 @@ module Git
31
32
  end
32
33
 
33
34
  def report(verbose = false)
34
- data.each do |commit, plus, minus|
35
- puts ("%4d %5d = %5d " % [plus, minus, plus + minus]) + commit
36
- end if verbose
35
+ if verbose
36
+ data.each do |commit, plus, minus|
37
+ puts ("%4d %5d = %5d " % [plus, minus, plus + minus]) + commit
38
+ end
39
+ puts "** Warnings:", @warnings if @warnings && !@warnings.empty?
40
+ end
37
41
  plus, minus, delta = plus_minus_delta
38
42
  puts "#{plus} #{minus} = #{delta}"
39
- puts "** Warnings:", @warnings if @warnings && !@warnings.empty?
40
43
  end
41
44
 
42
45
  def data
@@ -45,7 +48,7 @@ module Git
45
48
 
46
49
  private
47
50
  def git_log
48
- extra = extra_args.join(' ')
51
+ extra = Array(extra_args).join(' ')
49
52
  extra << "--author=#{`git config user.email`.strip}" unless extra.include? '--author='
50
53
  `git log --oneline --shortstat --no-merges #{extra} -- #{file_filter}`
51
54
  end
@@ -57,7 +60,7 @@ module Git
57
60
  e << nil if e.empty?
58
61
  p.product(e).map do |path, ext|
59
62
  next path if ext.nil?
60
- [path, '/*', ext.start_with?('.') || '.', ext].join
63
+ "'#{path}/*#{'.' unless ext.start_with?('.')}#{ext}'"
61
64
  end.join(' ')
62
65
  end
63
66
 
data/lib/git-delta/run.rb CHANGED
@@ -1,14 +1,56 @@
1
- require "git-delta"
1
+ require_relative "../git-delta"
2
2
 
3
- verbose = ARGV.delete('-v')
3
+ class Git::Delta::Runner
4
+ def run(argv = ARGV)
5
+ if ARGV.delete('-rails')
6
+ rails
7
+ else
8
+ Git::Delta::Reporter.new(*parse_arg(argv)).filter_out(exclude).report(@verbose)
9
+ end
10
+ end
4
11
 
5
- ext, paths, extra = [], [], []
6
- split = Hash.new{|h, k| h['path']}.merge!('.' => [], '-' => [], 'path' => [])
7
- ARGV.each{|a| split[a[0]] << a}
12
+ def parse_arg(argv)
13
+ @verbose ||= ARGV.delete('-v')
8
14
 
9
- Git::Delta::Reporter.new(*split.values_at('path', '.', '-'))
10
- .instance_eval do
11
- excl = (File.read('./.ignore_commits') rescue File.read('tmp/.ignore_commits') rescue '')
12
- filter_out(excl)
13
- report(verbose)
15
+ split = Hash.new{|h, k| h['path']}.merge!('.' => [], '-' => [], 'path' => [])
16
+ argv.each{|a| split[a[0]] << a}
17
+
18
+ split.values_at('path', '.', '-')
19
+ end
20
+
21
+ def exclude
22
+ @excl ||= (File.read('./.ignore_commits') rescue File.read('tmp/.ignore_commits') rescue '')
23
+ end
24
+
25
+ def rails
26
+ app = %w[app lib]
27
+ categs = {
28
+ js: [app, %w[js coffee hbs]],
29
+ ruby: [app, %w[rb]],
30
+ erb: [app, %w[erb haml]],
31
+ app: [app, %w[erb haml rb js coffee hbs]],
32
+ test: [%w[test spec], %w[rb]],
33
+ }
34
+
35
+ pmd = categs.map do |kind, args|
36
+ Git::Delta::Reporter.new(*args).filter_out(exclude).plus_minus_delta
37
+ end
38
+
39
+ kinds = categs.keys
40
+
41
+ # pmd << pmd.transpose.map{|s| s.inject(:+)}
42
+ # kinds << 'total'
43
+ categs.zip(pmd) do |(kind, (paths, extensions)), (p, m, d)|
44
+ tot = total_lines(paths, extensions)
45
+ puts "%10s: %4d %5d = %5d (%2.2f%% of %d)" % [kind, p, m, d, 100.0 * d / tot, tot]
46
+ end
47
+ end
48
+
49
+ def total_lines(paths, extensions)
50
+ paths.product(extensions).map do |path, ext|
51
+ `find #{path} -name '*.#{ext}' -print0 | xargs -0 wc -l | tail -1`.to_i
52
+ end.inject(:+)
53
+ end
14
54
  end
55
+
56
+ Git::Delta::Runner.new.run
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  module Delta
3
- VERSION = "0.0.2"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git-delta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: