git_loc_tracker 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 ITHouse Latvia and Arturs Meisters
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -0,0 +1,26 @@
1
+ Git LOC tracker
2
+ ===============
3
+ Git LOC tracker is a tool that counts **new**, **deleted** and **modified** Lines Of Code(LOC). The problem with git log and git diff is that it counts only added and removed lines in all git generated summaries and there is no way of knowing which line is really new, deleted, or modified so that is what Git LOC tracker does.
4
+
5
+ Usage
6
+ ---------------
7
+ `gem install git_loc_tracker`
8
+ and type `git-loc-tracker` in any git repo
9
+ For help type `git-loc-tracker -h`
10
+
11
+ Options
12
+ ---------------
13
+ **-p, --path PATH** - Specify path to git repo root or sub directory. By default it is working directory from which you call the command.
14
+ **-f, --from TIME** - Specify from date ex. '2012-10-29'
15
+ **-t, --till TIME** - Specify till date ex. '2012-10-29 12:44:01'
16
+ **-u, --author AUTHOR** - Specify git author
17
+ **-s, --searchscope DIRS** - Specify search scope for which to gather statistics, default: 'app config extras db lib spec Gemfile'
18
+ **-h, --help** - Show help
19
+
20
+ Complex example
21
+ ---------------
22
+ *git-loc-tracker --path=path/to/git/repo --from="1 week ago" --till="1 hour ago" --author="Janis" --searchscope="app/controllers app/models"*
23
+
24
+ Boring details
25
+ ---------------
26
+ Gem uses standard `git log -p --word-diff` command with additional parameters described earlier and greps out only interesting lines. Then iterates through all found lines and checks the code in specific line to detect whether it's completely new, deleted or contains deleted or new parts and accordingly counts them as new, deleted, modified.
data/bin/git-loc-tracker CHANGED
@@ -8,19 +8,19 @@ options = {:search_scope => "app config extras db lib spec Gemfile", path: Dir.p
8
8
  option_parser = OptionParser.new do |opts|
9
9
  opts.banner = "Usage: [options]"
10
10
 
11
- opts.on("-p", "--path PATH", "Specify path to rails project (MANDATORY)") do |path|
11
+ opts.on("-p", "--path PATH", "Specify path to git repo root or sub directory. By default it is working directory from which you call the command.") do |path|
12
12
  options[:path] = path
13
13
  end
14
- opts.on("-f", "--from TIME", "Specify from date ex. '2012-10-29' (OPTIONAL)") do |time|
14
+ opts.on("-f", "--from TIME", "Specify from date ex. '2012-10-29'") do |time|
15
15
  options[:from] = time
16
16
  end
17
- opts.on("-t", "--till TIME", "Specify till date ex. '2012-10-29 12:44:01' (OPTIONAL)") do |time|
17
+ opts.on("-t", "--till TIME", "Specify till date ex. '2012-10-29 12:44:01'") do |time|
18
18
  options[:till] = time
19
19
  end
20
20
  opts.on("-u", "--author AUTHOR", "Specify git author (OPTIONAL)") do |author|
21
21
  options[:author] = author
22
22
  end
23
- opts.on("-s", "--searchscope DIRS", "Specify search scope for which to gather statistics, default: 'app config extras' (OPTIONAL)") do |search_scope|
23
+ opts.on("-s", "--searchscope DIRS", "Specify search scope for which to gather statistics, default: 'app config extras'") do |search_scope|
24
24
  options[:search_scope] = search_scope
25
25
  end
26
26
 
@@ -34,4 +34,4 @@ end
34
34
  option_parser.parse!
35
35
 
36
36
  statistics = GitLocTracker::Statistics.new(options)
37
- p statistics.print_statistics
37
+ statistics.print_statistics
@@ -36,7 +36,7 @@ module GitLocTracker
36
36
  def existing_search_scope
37
37
  scope_parts = options[:search_scope].split(" ")
38
38
  existing_scope_dirs = scope_parts.select { |dir| File.exist?("#{options[:path]}/#{dir}") }
39
- existing_scope_dirs.join(" ")
39
+ existing_scope_dirs.empty? ? options[:path] : existing_scope_dirs.join(" ")
40
40
  end
41
41
 
42
42
 
@@ -0,0 +1,25 @@
1
+ require 'systemu'
2
+
3
+ module GitLocTracker
4
+ class CommandExecutor
5
+ class GitCommandError < StandardError
6
+ end
7
+ attr_accessor :command
8
+
9
+ def initialize command
10
+ @command = command
11
+ end
12
+
13
+ def git_lines
14
+ stdin, stdout, stderr = systemu command
15
+ raise_if_error(stderr)
16
+ stdout.split("\n")
17
+ end
18
+
19
+ def raise_if_error(stderr)
20
+ unless stderr.empty?
21
+ raise GitCommandError, stderr
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ module GitLocTracker
2
+ class LineParser
3
+ attr_accessor :line
4
+
5
+ def initialize line
6
+ @line = line
7
+ end
8
+
9
+ def line_size_without_deleted_code
10
+ line.strip.gsub(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP, "").size
11
+ end
12
+
13
+ def line_size_without_new_code
14
+ line.strip.gsub(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP, "").size
15
+ end
16
+
17
+ def is_new?
18
+ line_size_without_new_code == 0
19
+ end
20
+
21
+ def is_deleted?
22
+ line_size_without_deleted_code == 0
23
+ end
24
+
25
+ def is_modified?
26
+ !is_new? && !is_deleted?
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module GitLocTracker
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,70 +1,52 @@
1
1
  require "git_loc_tracker/version"
2
2
  require "git_loc_tracker/command_constructor"
3
- require 'systemu'
3
+ require "git_loc_tracker/command_executor"
4
+ require "git_loc_tracker/line_parser"
4
5
 
5
6
  module GitLocTracker
6
7
 
7
8
  class Statistics
8
- class GitCommandError < StandardError
9
- end
10
9
 
11
- attr_accessor :git_lines, :git_command
10
+ attr_accessor :git_lines, :git_command, :line_parser
12
11
 
13
12
  def initialize options
14
13
  @git_command = GitLocTracker::CommandConstructor.new(options).git_command
15
14
  end
16
15
 
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 "********************************"
16
+ def git_lines
17
+ @git_lines ||= GitLocTracker::CommandExecutor.new(@git_command).git_lines
18
+ end
19
+
20
+ def line_parser line
21
+ GitLocTracker::LineParser.new(line)
24
22
  end
25
23
 
26
24
  def new_line_count
27
25
  git_lines.count do |line|
28
- is_new? line
26
+ line_parser(line).is_new?
29
27
  end
30
28
  end
31
29
 
32
30
  def deleted_line_count
33
31
  git_lines.count do |line|
34
- is_deleted? line
32
+ line_parser(line).is_deleted?
35
33
  end
36
34
  end
37
35
 
38
36
  def modified_line_count
39
37
  git_lines.count do |line|
40
- is_modified? line
38
+ line_parser(line).is_modified?
41
39
  end
42
40
  end
43
41
 
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")
42
+ def print_statistics
43
+ puts "********************************"
44
+ puts "New lines: #{new_line_count}"
45
+ puts "Deleted lines: #{deleted_line_count}"
46
+ puts "Modified lines: #{modified_line_count}"
47
+ puts "********************************"
61
48
  end
62
49
 
63
- def raise_if_error(stderr)
64
- unless stderr.empty?
65
- raise GitCommandError, stderr
66
- end
67
- end
68
50
  end
69
51
 
70
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_loc_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,31 +11,9 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2012-10-11 00:00:00.000000000Z
13
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
14
  - !ruby/object:Gem::Dependency
37
15
  name: systemu
38
- requirement: &72724760 !ruby/object:Gem::Requirement
16
+ requirement: &73615600 !ruby/object:Gem::Requirement
39
17
  none: false
40
18
  requirements:
41
19
  - - ~>
@@ -43,27 +21,27 @@ dependencies:
43
21
  version: 2.5.2
44
22
  type: :runtime
45
23
  prerelease: false
46
- version_requirements: *72724760
24
+ version_requirements: *73615600
47
25
  description: Counts new, deleted and modified lines in git repository with ability
48
26
  to pass various options
49
27
  email:
50
- - janisk@ithouse.lv
28
+ - support@ithouse.lv
51
29
  executables:
52
30
  - git-loc-tracker
53
31
  extensions: []
54
32
  extra_rdoc_files: []
55
33
  files:
56
- - .gitignore
57
- - Gemfile
58
- - README.md
59
- - Rakefile
60
34
  - bin/git-loc-tracker
61
- - git_loc_tracker.gemspec
62
- - lib/git_loc_tracker.rb
63
- - lib/git_loc_tracker/command_constructor.rb
35
+ - lib/git_loc_tracker/line_parser.rb
64
36
  - lib/git_loc_tracker/version.rb
37
+ - lib/git_loc_tracker/command_constructor.rb
38
+ - lib/git_loc_tracker/command_executor.rb
39
+ - lib/git_loc_tracker.rb
40
+ - MIT-LICENSE
41
+ - Rakefile
42
+ - README.md
65
43
  - spec/spec_helper.rb
66
- homepage: https://github.com/Janziz/git_loc_tracker
44
+ homepage: https://github.com/ithouse/git_loc_tracker
67
45
  licenses: []
68
46
  post_install_message:
69
47
  rdoc_options: []
@@ -88,4 +66,5 @@ signing_key:
88
66
  specification_version: 3
89
67
  summary: Counts new, deleted and modified lines in git repository with ability to
90
68
  pass various options
91
- test_files: []
69
+ test_files:
70
+ - spec/spec_helper.rb
data/.gitignore DELETED
@@ -1,7 +0,0 @@
1
- *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
- .idea
6
- .rvmrc
7
- .rspec
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in git_loc_tracker.gemspec
4
- gemspec
@@ -1,25 +0,0 @@
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