diff_influence 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.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/diff_influence.gemspec +25 -0
- data/exe/diff-influence +6 -0
- data/lib/diff_influence/config.rb +94 -0
- data/lib/diff_influence/core.rb +112 -0
- data/lib/diff_influence/version.rb +3 -0
- data/lib/diff_influence.rb +3 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b4d55ee171f05f93366111120e33f56a834b3e28
|
4
|
+
data.tar.gz: 9a804afacfabf149ddca92860e8f6a12f036f7de
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ee1fb841a6de0f192a6859070f098c991be007cff67bf59d58a476b7708654523941fcf094dbef3804e44b9ec5beefd8042f80eb9196827119486d41934a5364
|
7
|
+
data.tar.gz: 2bea09cf03472c98533206dec2c7f96ba8821e1d5caf31cd9d05e250994ab88e191fb7745a79d824b6934672137249b887baf9ca6f707ca3bb300dc0bf56554d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
T License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 metalels
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Diff Influence
|
2
|
+
|
3
|
+
Search influence of git diff.
|
4
|
+
|
5
|
+
## Requirement ##
|
6
|
+
|
7
|
+
* git ( use git diff command )
|
8
|
+
|
9
|
+
## Installation ##
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'diff_influence', group: :development
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install diff_influence
|
24
|
+
|
25
|
+
## Usage ##
|
26
|
+
|
27
|
+
``
|
28
|
+
==============================================================================
|
29
|
+
[]: optional
|
30
|
+
|
31
|
+
Usage: diff-influence [Options]
|
32
|
+
|
33
|
+
Options:
|
34
|
+
|
35
|
+
-p --commit commit_id,commit_id git commit id(s) uses diff (default: none)
|
36
|
+
-p --path path,path,... path(s) to search file (default: app,lib)
|
37
|
+
-e --ext extension,extension,... extension(s) to search file (default: rb)
|
38
|
+
-g --grep use grep command with OS
|
39
|
+
-d --debug print debugging information to console
|
40
|
+
|
41
|
+
Feature Options:
|
42
|
+
|
43
|
+
-o --output path to output file (default: STDOUT)
|
44
|
+
==============================================================================
|
45
|
+
``
|
46
|
+
|
47
|
+
## Authors ##
|
48
|
+
|
49
|
+
[metalels](https://github.com/metalels)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "diff_influence"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
require "pry"
|
11
|
+
Pry.start
|
12
|
+
|
13
|
+
#require "irb"
|
14
|
+
#IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'diff_influence/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "diff_influence"
|
8
|
+
spec.version = DiffInfluence::VERSION
|
9
|
+
spec.authors = ["metalels"]
|
10
|
+
spec.email = ["metalels86@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{search diff influence.}
|
13
|
+
spec.description = %q{search diff influence.}
|
14
|
+
spec.homepage = "https://github.com/metalels/diff_influence"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
end
|
data/exe/diff-influence
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
module DiffInfluence
|
2
|
+
module Config
|
3
|
+
require 'pathname'
|
4
|
+
USAGE=<<-EOS
|
5
|
+
==============================================================================
|
6
|
+
[]: optional
|
7
|
+
|
8
|
+
Usage: diff_influence [Options]
|
9
|
+
|
10
|
+
Options:
|
11
|
+
|
12
|
+
-p --commit commit_id,commit_id git commit id(s) uses diff (default: none)
|
13
|
+
-p --path path,path,... path(s) to search file (default: app,lib)
|
14
|
+
-e --ext extension,extension,... extension(s) to search file (default: rb)
|
15
|
+
-g --grep use grep command with OS
|
16
|
+
-d --debug print debugging information to console
|
17
|
+
|
18
|
+
Feature Options:
|
19
|
+
|
20
|
+
-o --output path to output file (default: STDOUT)
|
21
|
+
==============================================================================
|
22
|
+
EOS
|
23
|
+
|
24
|
+
def self.exit_with_message(code, usage=false, msg=nil)
|
25
|
+
puts msg unless msg.nil?
|
26
|
+
puts USAGE if usage
|
27
|
+
exit code
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.root
|
31
|
+
@@root ||= Pathname.pwd
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.commits
|
35
|
+
@@commits ||= []
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.commits=(value)
|
39
|
+
@@commits = value.split(",").map{|v| v.chomp.strip}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.search_paths
|
43
|
+
@@search_paths ||= ["app", "lib"]
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.search_paths=(value)
|
47
|
+
@@search_paths = value.split(",").map{|v| v.chomp.strip}
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.search_extensions
|
51
|
+
@@search_extensions ||= ["rb"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.search_extensions=(value)
|
55
|
+
@@search_extensionss = value.split(",").map{|v| v.chomp.strip}
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.output
|
59
|
+
@@output ||= nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.os_grep
|
63
|
+
@@os_grep ||= false
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.debug
|
67
|
+
@@debug ||= false
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.parse_options(argv)
|
71
|
+
while arg = argv.shift
|
72
|
+
case arg
|
73
|
+
when /\A--commit\z/, /\A-c\z/
|
74
|
+
self.commits = argv.shift
|
75
|
+
when /\A--path\z/, /\A-p\z/
|
76
|
+
self.search_paths = argv.shift
|
77
|
+
when /\A--ext\z/, /\A-e\z/
|
78
|
+
self.search_extensions = argv.shift
|
79
|
+
when /\A--output\z/, /\A-o\z/
|
80
|
+
@@output = argv.shift
|
81
|
+
when /\A--grep\z/, /\A-g\z/
|
82
|
+
@@debug = true
|
83
|
+
when /\A--debug\z/, /\A-d\z/
|
84
|
+
@@debug = true
|
85
|
+
when /\A--help\z/, /\A-h\z/
|
86
|
+
self.exit_with_message 0, true
|
87
|
+
else
|
88
|
+
puts "unknown option #{arg}"
|
89
|
+
self.exit_with_message 2, true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module DiffInfluence
|
2
|
+
module Core
|
3
|
+
PREF_DIRS=["lib", "app"]
|
4
|
+
EMeth=Struct.new(:name, :type, :raw, :index)
|
5
|
+
EMeth.class_eval do
|
6
|
+
def initialize(attr={})
|
7
|
+
self.name = attr[:name]
|
8
|
+
self.type = attr[:type]
|
9
|
+
self.raw = attr[:raw]
|
10
|
+
self.index = attr[:index]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.git_status
|
15
|
+
`git status | grep modified`
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.file_paths
|
19
|
+
@@files ||= self.git_status.lines.map{|line| line.split.last}
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.git_diff(file_path)
|
23
|
+
`git --no-pager diff --no-ext-diff -U1000000 #{file_path}`
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.file(file_path)
|
27
|
+
File.read(file_path).lines
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.search_methods(file_path)
|
31
|
+
methods = []
|
32
|
+
last_method = nil
|
33
|
+
cnt = 0
|
34
|
+
lines = self.git_diff(file_path).lines
|
35
|
+
lines.each_with_index do |line, idx|
|
36
|
+
last_method = lines[idx].split("def ").last.chomp.gsub("self\.","") if line =~ /(\s|\t)*def/
|
37
|
+
case line
|
38
|
+
when /\A\+\+\+/, /\A---/, /\Adiff/, /\Aindex/, /\A@@/
|
39
|
+
puts "Ignore line: #{line}" if DiffInfluence::Config.debug
|
40
|
+
next
|
41
|
+
when /\A\+/, /\A\-/
|
42
|
+
cnt += 1 if line =~ /\A\+/
|
43
|
+
puts "idx:#{idx}, cnt:#{cnt}, #{line}" if DiffInfluence::Config.debug
|
44
|
+
|
45
|
+
t = case line
|
46
|
+
when /\A-(\s|\t)*def/
|
47
|
+
"remove"
|
48
|
+
when /\A\+(\s|\t)*def/
|
49
|
+
"add"
|
50
|
+
else
|
51
|
+
"effect"
|
52
|
+
end
|
53
|
+
methods.push EMeth.new(
|
54
|
+
name: last_method,
|
55
|
+
type: t,
|
56
|
+
raw: line,
|
57
|
+
index: cnt
|
58
|
+
)
|
59
|
+
else
|
60
|
+
cnt += 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
puts methods if DiffInfluence::Config.debug
|
64
|
+
methods
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.os_grep(keyword="")
|
68
|
+
DiffInfluence::Config.search_paths.each do |pd|
|
69
|
+
puts `grep -r -E '(\\.|@)#{keyword}(\\s|\\()' #{pd}`
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.native_grep(keyword="")
|
74
|
+
self.files.each do |file|
|
75
|
+
File.readlines(file).each_with_index do |line, idx|
|
76
|
+
if line =~ /(\.|@)#{keyword}(\s|\()/
|
77
|
+
puts "#{file}:#{idx+1} #{line}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.files
|
84
|
+
@@files ||= Dir.glob(DiffInfluence::Config.search_paths.map{|d| "#{d}/**/**.{#{DiffInfluence::Config.search_extensions.join(",")}}"})
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.influence_search(file_path)
|
88
|
+
searched_methods = []
|
89
|
+
self.search_methods(file_path).each do |method|
|
90
|
+
if method.name.nil? || method.name.empty? || searched_methods.include?(method.name)
|
91
|
+
next
|
92
|
+
else
|
93
|
+
searched_methods.push method.name
|
94
|
+
end
|
95
|
+
puts "### Searching method[#{method.name}] (from #{file_path}:#{method.index})"
|
96
|
+
if DiffInfluence::Config.os_grep
|
97
|
+
self.os_grep method.name
|
98
|
+
else
|
99
|
+
self.native_grep method.name
|
100
|
+
end
|
101
|
+
puts
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.exec
|
106
|
+
self.file_paths.each do |fp|
|
107
|
+
self.influence_search fp
|
108
|
+
end
|
109
|
+
exit 0
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: diff_influence
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- metalels
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-02-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: search diff influence.
|
70
|
+
email:
|
71
|
+
- metalels86@gmail.com
|
72
|
+
executables:
|
73
|
+
- diff-influence
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- diff_influence.gemspec
|
87
|
+
- exe/diff-influence
|
88
|
+
- lib/diff_influence.rb
|
89
|
+
- lib/diff_influence/config.rb
|
90
|
+
- lib/diff_influence/core.rb
|
91
|
+
- lib/diff_influence/version.rb
|
92
|
+
homepage: https://github.com/metalels/diff_influence
|
93
|
+
licenses: []
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.6.8
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: search diff influence.
|
115
|
+
test_files: []
|