git_loc_tracker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +4 -0
- data/README.md +0 -0
- data/Rakefile +1 -0
- data/bin/git-loc-tracker +37 -0
- data/git_loc_tracker.gemspec +25 -0
- data/lib/git_loc_tracker/command_constructor.rb +48 -0
- data/lib/git_loc_tracker/version.rb +3 -0
- data/lib/git_loc_tracker.rb +70 -0
- data/spec/spec_helper.rb +17 -0
- metadata +91 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/git-loc-tracker
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'git_loc_tracker'
|
5
|
+
|
6
|
+
options = {:search_scope => "app config extras db lib spec Gemfile", path: Dir.pwd}
|
7
|
+
|
8
|
+
option_parser = OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: [options]"
|
10
|
+
|
11
|
+
opts.on("-p", "--path PATH", "Specify path to rails project (MANDATORY)") do |path|
|
12
|
+
options[:path] = path
|
13
|
+
end
|
14
|
+
opts.on("-f", "--from TIME", "Specify from date ex. '2012-10-29' (OPTIONAL)") do |time|
|
15
|
+
options[:from] = time
|
16
|
+
end
|
17
|
+
opts.on("-t", "--till TIME", "Specify till date ex. '2012-10-29 12:44:01' (OPTIONAL)") do |time|
|
18
|
+
options[:till] = time
|
19
|
+
end
|
20
|
+
opts.on("-u", "--author AUTHOR", "Specify git author (OPTIONAL)") do |author|
|
21
|
+
options[:author] = author
|
22
|
+
end
|
23
|
+
opts.on("-s", "--searchscope DIRS", "Specify search scope for which to gather statistics, default: 'app config extras' (OPTIONAL)") do |search_scope|
|
24
|
+
options[:search_scope] = search_scope
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
28
|
+
puts opts
|
29
|
+
exit
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
34
|
+
option_parser.parse!
|
35
|
+
|
36
|
+
statistics = GitLocTracker::Statistics.new(options)
|
37
|
+
p statistics.print_statistics
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "git_loc_tracker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "git_loc_tracker"
|
7
|
+
s.version = GitLocTracker::VERSION
|
8
|
+
s.authors = ["ITHouse (Latvia) and Janis Kesteris"]
|
9
|
+
s.email = ["janisk@ithouse.lv"]
|
10
|
+
s.homepage = "https://github.com/Janziz/git_loc_tracker"
|
11
|
+
s.summary = %q{Counts new, deleted and modified lines in git repository with ability to pass various options}
|
12
|
+
s.description = %q{Counts new, deleted and modified lines in git repository with ability to pass various options}
|
13
|
+
|
14
|
+
s.rubyforge_project = "git_loc_tracker"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rspec"
|
23
|
+
s.add_development_dependency "debugger"
|
24
|
+
s.add_runtime_dependency "systemu", "~> 2.5.2"
|
25
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module GitLocTracker
|
2
|
+
class CommandConstructor
|
3
|
+
|
4
|
+
attr_accessor :options
|
5
|
+
|
6
|
+
NEW_CODE_REGEXP = /\{\+.*\+\}/
|
7
|
+
DELETED_CODE_REGEXP = /\[\-.*\-\]/
|
8
|
+
|
9
|
+
def initialize options
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def git_command
|
14
|
+
command_parts = []
|
15
|
+
options.each do |name, argument|
|
16
|
+
command_parts << get_command_part(name, argument)
|
17
|
+
end
|
18
|
+
"cd #{options[:path]} && git log -p --word-diff #{command_parts.join(" ")} #{existing_search_scope} | egrep '#{modified_line_parser_regexp}'"
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def get_command_part name, argument
|
24
|
+
case name
|
25
|
+
when :from
|
26
|
+
"--since='#{options[:from]}'"
|
27
|
+
when :till
|
28
|
+
"--until='#{options[:till]}'"
|
29
|
+
when :author
|
30
|
+
"--author='#{options[:author]}'"
|
31
|
+
else
|
32
|
+
""
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def existing_search_scope
|
37
|
+
scope_parts = options[:search_scope].split(" ")
|
38
|
+
existing_scope_dirs = scope_parts.select { |dir| File.exist?("#{options[:path]}/#{dir}") }
|
39
|
+
existing_scope_dirs.join(" ")
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def modified_line_parser_regexp
|
44
|
+
"#{GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP.source}|#{GitLocTracker::CommandConstructor::NEW_CODE_REGEXP.source}"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require "git_loc_tracker/version"
|
2
|
+
require "git_loc_tracker/command_constructor"
|
3
|
+
require 'systemu'
|
4
|
+
|
5
|
+
module GitLocTracker
|
6
|
+
|
7
|
+
class Statistics
|
8
|
+
class GitCommandError < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :git_lines, :git_command
|
12
|
+
|
13
|
+
def initialize options
|
14
|
+
@git_command = GitLocTracker::CommandConstructor.new(options).git_command
|
15
|
+
end
|
16
|
+
|
17
|
+
def print_statistics
|
18
|
+
set_raw_git_lines
|
19
|
+
puts "********************************"
|
20
|
+
puts "New lines: #{new_line_count}"
|
21
|
+
puts "Deleted lines: #{deleted_line_count}"
|
22
|
+
puts "Modified lines: #{modified_line_count}"
|
23
|
+
puts "********************************"
|
24
|
+
end
|
25
|
+
|
26
|
+
def new_line_count
|
27
|
+
git_lines.count do |line|
|
28
|
+
is_new? line
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def deleted_line_count
|
33
|
+
git_lines.count do |line|
|
34
|
+
is_deleted? line
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def modified_line_count
|
39
|
+
git_lines.count do |line|
|
40
|
+
is_modified? line
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_new?(line)
|
45
|
+
line.strip.gsub(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP, "").size == 0
|
46
|
+
end
|
47
|
+
|
48
|
+
def is_deleted?(line)
|
49
|
+
line.strip.gsub(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP, "").size == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def is_modified? line
|
53
|
+
line.strip.gsub(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP, "").size > 0 ||
|
54
|
+
line.strip.gsub(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP, "").size > 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def set_raw_git_lines
|
58
|
+
stdin, stdout, stderr = systemu git_command
|
59
|
+
raise_if_error(stderr)
|
60
|
+
self.git_lines = stdout.split("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
def raise_if_error(stderr)
|
64
|
+
unless stderr.empty?
|
65
|
+
raise GitCommandError, stderr
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_loc_tracker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- ITHouse (Latvia) and Janis Kesteris
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-11 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &72725250 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *72725250
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: debugger
|
27
|
+
requirement: &72725020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *72725020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: systemu
|
38
|
+
requirement: &72724760 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.5.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *72724760
|
47
|
+
description: Counts new, deleted and modified lines in git repository with ability
|
48
|
+
to pass various options
|
49
|
+
email:
|
50
|
+
- janisk@ithouse.lv
|
51
|
+
executables:
|
52
|
+
- git-loc-tracker
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- bin/git-loc-tracker
|
61
|
+
- git_loc_tracker.gemspec
|
62
|
+
- lib/git_loc_tracker.rb
|
63
|
+
- lib/git_loc_tracker/command_constructor.rb
|
64
|
+
- lib/git_loc_tracker/version.rb
|
65
|
+
- spec/spec_helper.rb
|
66
|
+
homepage: https://github.com/Janziz/git_loc_tracker
|
67
|
+
licenses: []
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project: git_loc_tracker
|
86
|
+
rubygems_version: 1.8.10
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: Counts new, deleted and modified lines in git repository with ability to
|
90
|
+
pass various options
|
91
|
+
test_files: []
|