git-delta 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in git-delta.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Marc-Andre Lafortune
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Git::Delta
2
+
3
+ Outputs the net number of lines added/removed by you for the current `git` directory.
4
+
5
+ It sums the net change for each commit and output the sum of positive and negative contributions:
6
+
7
+ $ git-delta
8
+ 123 - 100 = 23
9
+
10
+ Net lines added: 23
11
+
12
+ ## Installation
13
+
14
+ gem install 'git-delta'
15
+
16
+ ## Usage
17
+
18
+ $ git-delta -v
19
+ $ git-delta app lib
20
+ $ git-delta .js .coffee
21
+ $ git-delta --author=someone_else
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
data/bin/git-delta ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'git-delta/run'
data/git-delta.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/git-delta/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Marc-Andre Lafortune"]
6
+ gem.email = ["github@marc-andre.ca"]
7
+ gem.description = %q{Calculate the number of lines added/subtracted in a git directory}
8
+ gem.summary = %q{Calculate the number of lines added/subtracted in a git directory}
9
+ gem.homepage = "http://github.com/marcandre/git-delta"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "git-delta"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Git::Delta::VERSION
17
+ end
data/lib/git-delta.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "git-delta/version"
2
+ require "git-delta/reporter"
3
+
4
+ module Git
5
+ module Delta
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,73 @@
1
+ module Git
2
+ module Delta
3
+ class Reporter < Struct.new(:paths, :extensions, :extra_args)
4
+ attr_reader :verbose
5
+
6
+ def filter_out(exclude)
7
+ exclude = exclude.split("\n") unless exclude.respond_to? :map
8
+ w = exclude.map do |skip|
9
+ n = data.size
10
+ data.delete_if{|commit, _, _| commit.include?(skip)}
11
+ case n -= @data.size
12
+ when 1
13
+ when 0
14
+ "Didn't find commit '#{skip}'" if ARGV.size <= 1
15
+ else
16
+ "Commit '#{skip}' matched #{n} commits"
17
+ end
18
+ end.compact
19
+ (@warnings ||= []).concat(w)
20
+ end
21
+
22
+ def delta
23
+ plus_minus_delta.last
24
+ end
25
+
26
+ def plus_minus_delta
27
+ deltas = data.map{|_, plus, minus| plus + minus }
28
+ deletions = deltas.select{|d| d < 0}.inject(0, :+)
29
+ delta = deltas.inject(0, :+)
30
+ [delta - deletions, deletions, delta]
31
+ end
32
+
33
+ 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
37
+ plus, minus, delta = plus_minus_delta
38
+ puts "#{plus} #{minus} = #{delta}"
39
+ puts "** Warnings:", @warnings if @warnings && !@warnings.empty?
40
+ end
41
+
42
+ def data
43
+ @data ||= parse_log(git_log)
44
+ end
45
+
46
+ private
47
+ def git_log
48
+ extra = extra_args.join(' ')
49
+ extra << "--author=#{`git config user.email`.strip}" unless extra.include? '--author='
50
+ puts "git log --oneline --shortstat --no-merges #{extra} -- #{file_filter}"
51
+ `git log --oneline --shortstat --no-merges #{extra} -- #{file_filter}`
52
+ end
53
+
54
+ def file_filter
55
+ p = Array(paths)
56
+ p << '.' if p.empty?
57
+ e = Array(extensions)
58
+ e << nil if e.empty?
59
+ p.product(e).map do |path, ext|
60
+ next path if ext.nil?
61
+ [path, '/*', ext.start_with?('.') || '.', ext].join
62
+ end.join(' ')
63
+ end
64
+
65
+ def parse_log(log)
66
+ log.lines.each_slice(2).map do |commit, changes|
67
+ _, plus, minus = *changes.match(/.*changed, (\d+) insertions.* (\d+) deletions/)
68
+ [commit, plus.to_i, -minus.to_i]
69
+ end.reverse
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,14 @@
1
+ require "git-delta"
2
+
3
+ verbose = ARGV.delete('-v')
4
+
5
+ ext, paths, extra = [], [], []
6
+ split = Hash.new{|h, k| h['path']}.merge!('.' => [], '-' => [], 'path' => [])
7
+ ARGV.each{|a| split[a[0]] << a}
8
+
9
+ CommitStatsReporter.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)
14
+ end
@@ -0,0 +1,5 @@
1
+ module Git
2
+ module Delta
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-delta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marc-Andre Lafortune
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-18 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Calculate the number of lines added/subtracted in a git directory
15
+ email:
16
+ - github@marc-andre.ca
17
+ executables:
18
+ - git-delta
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/git-delta
28
+ - git-delta.gemspec
29
+ - lib/git-delta.rb
30
+ - lib/git-delta/reporter.rb
31
+ - lib/git-delta/run.rb
32
+ - lib/git-delta/version.rb
33
+ homepage: http://github.com/marcandre/git-delta
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.24
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Calculate the number of lines added/subtracted in a git directory
57
+ test_files: []
58
+ has_rdoc: