git_diff_lcs 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2123947d389e4a5c12a5a274fb8e5598f20fcdfc275309b5e1a2edc1b9d5c461
4
- data.tar.gz: 73b19ddf4745c3c5760587eeab2f161e26969e173d6bf58af232fc9d689e74cb
3
+ metadata.gz: e1b6be903d8a4f4a01f76b6bb78e2760951c57bbf1ae01c1f08025be9a3fe466
4
+ data.tar.gz: 336de7d1164b9f315e83866901cc8beffe189bc5143e687f9f441881b0dffd0d
5
5
  SHA512:
6
- metadata.gz: 16d21b22cae93be9c4018b00c27445ad1690e08e1b59bf636e81eff1b3233864c2082c919d429525d0962275136dfeb537ba0527dcdc894f3d9d8050899f9339
7
- data.tar.gz: 20d284393155dc560423e06962f6759720e3785f50a30079bea557e9685da69e4971db9bbdd9048e6d652fa35ee6cc40401d5f6ac83c5c0527fd42c9e21d4c25
6
+ metadata.gz: ef89f50965b515f05fbe905aaf2f0b1c1b835d15e0cd0c30401c63f2ab63d78def8c710b26f0e886fe23a0a8b187c6f5a63abdcc83fbbd9e7a4fa3da28d05d38
7
+ data.tar.gz: 3d571ae3db7b6e9fc55d6df2d135996cbbfa68312b30803274230d8a30a03fc1bd0f39310c9e7bf81059e695ad61d1e3e7ce1f2f7da3d87c81d8dfda7e74060e
data/Gemfile.lock CHANGED
@@ -1,63 +1,63 @@
1
- PATH
2
- remote: .
3
- specs:
4
- git_diff_lcs (0.0.4)
5
- diff-lcs (= 1.4.4)
6
- git (= 1.8.1)
7
- thor (= 1.1.0)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ast (2.4.2)
13
- diff-lcs (1.4.4)
14
- git (1.8.1)
15
- rchardet (~> 1.8)
16
- parallel (1.20.1)
17
- parser (3.0.0.0)
18
- ast (~> 2.4.1)
19
- rainbow (3.0.0)
20
- rake (13.0.3)
21
- rchardet (1.8.0)
22
- regexp_parser (2.1.1)
23
- rexml (3.2.4)
24
- rspec (3.10.0)
25
- rspec-core (~> 3.10.0)
26
- rspec-expectations (~> 3.10.0)
27
- rspec-mocks (~> 3.10.0)
28
- rspec-core (3.10.1)
29
- rspec-support (~> 3.10.0)
30
- rspec-expectations (3.10.1)
31
- diff-lcs (>= 1.2.0, < 2.0)
32
- rspec-support (~> 3.10.0)
33
- rspec-mocks (3.10.2)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.10.0)
36
- rspec-support (3.10.2)
37
- rubocop (0.93.1)
38
- parallel (~> 1.10)
39
- parser (>= 2.7.1.5)
40
- rainbow (>= 2.2.2, < 4.0)
41
- regexp_parser (>= 1.8)
42
- rexml
43
- rubocop-ast (>= 0.6.0)
44
- ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 2.0)
46
- rubocop-ast (1.4.1)
47
- parser (>= 2.7.1.5)
48
- ruby-progressbar (1.11.0)
49
- thor (1.1.0)
50
- unicode-display_width (1.7.0)
51
-
52
- PLATFORMS
53
- x64-mingw32
54
- x86_64-linux
55
-
56
- DEPENDENCIES
57
- git_diff_lcs!
58
- rake (~> 13.0)
59
- rspec (~> 3.0)
60
- rubocop (~> 0.80)
61
-
62
- BUNDLED WITH
63
- 2.2.13
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_diff_lcs (0.0.6)
5
+ diff-lcs (= 1.4.4)
6
+ git (= 1.8.1)
7
+ thor (= 1.1.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ ast (2.4.2)
13
+ diff-lcs (1.4.4)
14
+ git (1.8.1)
15
+ rchardet (~> 1.8)
16
+ parallel (1.20.1)
17
+ parser (3.0.0.0)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
20
+ rake (13.0.3)
21
+ rchardet (1.8.0)
22
+ regexp_parser (2.1.1)
23
+ rexml (3.2.4)
24
+ rspec (3.10.0)
25
+ rspec-core (~> 3.10.0)
26
+ rspec-expectations (~> 3.10.0)
27
+ rspec-mocks (~> 3.10.0)
28
+ rspec-core (3.10.1)
29
+ rspec-support (~> 3.10.0)
30
+ rspec-expectations (3.10.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-mocks (3.10.2)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-support (3.10.2)
37
+ rubocop (0.93.1)
38
+ parallel (~> 1.10)
39
+ parser (>= 2.7.1.5)
40
+ rainbow (>= 2.2.2, < 4.0)
41
+ regexp_parser (>= 1.8)
42
+ rexml
43
+ rubocop-ast (>= 0.6.0)
44
+ ruby-progressbar (~> 1.7)
45
+ unicode-display_width (>= 1.4.0, < 2.0)
46
+ rubocop-ast (1.4.1)
47
+ parser (>= 2.7.1.5)
48
+ ruby-progressbar (1.11.0)
49
+ thor (1.1.0)
50
+ unicode-display_width (1.7.0)
51
+
52
+ PLATFORMS
53
+ x64-mingw32
54
+ x86_64-linux
55
+
56
+ DEPENDENCIES
57
+ git_diff_lcs!
58
+ rake (~> 13.0)
59
+ rspec (~> 3.0)
60
+ rubocop (~> 0.80)
61
+
62
+ BUNDLED WITH
63
+ 2.2.13
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # GitDiffLcs
1
+ # GitDiffLCS
2
2
 
3
3
  Generally, git diff --stat does not contain modifications, so we added it to display modifications using the LCS algorithm.
4
4
 
@@ -12,28 +12,29 @@ $ gem install git_diff-lcs
12
12
  ### CLI
13
13
 
14
14
  ```bash
15
+ $ git_diff_lcs diff [GIT_REPOSITORY] [SRC(BRANCH OR COMMIT)] [DEST(BRANCH OR COMMIT)]
15
16
  $ git_diff_lcs diff https://github.com/btpink-seo/git-diff-lcs.git test/src test/dest
16
17
  ```
17
18
 
18
19
  ### Ruby
19
20
 
20
- #### diff(repo, src, dest)
21
+ #### GitDiffLCS.diff(repo, src, dest)
21
22
 
22
23
  src, dest is branch name or commit
23
24
 
24
25
  ```ruby
25
26
  require 'git_diff_lcs'
26
27
 
27
- GitDiffLcs.diff('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
28
+ GitDiffLCS.diff('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
28
29
  # => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
29
30
  ```
30
31
 
31
- #### GitDiffLcs::Stat.new(repo, src, dest)
32
+ #### GitDiffLCS::Stat.new(repo, src, dest)
32
33
 
33
34
  ```ruby
34
35
  require 'git_diff_lcs'
35
36
 
36
- stat = GitDiffLcs::Stat.new('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
37
+ stat = GitDiffLCS::Stat.new('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
37
38
  stat.summary
38
39
  # => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
39
40
  stat.insertions
data/exe/git_diff_lcs CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  require "git_diff_lcs"
6
6
 
7
- GitDiffLcs::CLI.start(ARGV)
7
+ GitDiffLCS::CLI.start(ARGV)
data/git_diff_lcs.gemspec CHANGED
@@ -1,27 +1,27 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/git_diff_lcs/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "git_diff_lcs"
7
- spec.version = GitDiffLcs::VERSION
8
- spec.authors = ["SEO SANG HYUN"]
9
- spec.email = "btpink.seo@gmail.com"
10
-
11
- spec.summary = "'git diff --shortstat' with modifications"
12
- spec.description = "Add modifications to 'git diff --shortstat' using the LCS algorithm."
13
- spec.homepage = "https://github.com/btpink-seo/git-diff-lcs"
14
- spec.required_ruby_version = ">= 2.4.0"
15
-
16
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|script)/}) }
18
- end
19
- spec.require_paths = ["lib"]
20
- spec.bindir = "exe"
21
- spec.executables << "git_diff_lcs"
22
-
23
- spec.license = "MIT"
24
- spec.add_dependency "diff-lcs", "1.4.4"
25
- spec.add_dependency "git", "1.8.1"
26
- spec.add_runtime_dependency "thor", "1.1.0"
27
- end
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/git_diff_lcs/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "git_diff_lcs"
7
+ spec.version = GitDiffLCS::VERSION
8
+ spec.authors = ["SEO SANG HYUN"]
9
+ spec.email = "btpink.seo@gmail.com"
10
+
11
+ spec.summary = "'git diff --shortstat' with modifications"
12
+ spec.description = "Add modifications to 'git diff --shortstat' using the LCS algorithm."
13
+ spec.homepage = "https://github.com/btpink-seo/git-diff-lcs"
14
+ spec.required_ruby_version = ">= 2.4.0"
15
+
16
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|script)/}) }
18
+ end
19
+ spec.require_paths = ["lib"]
20
+ spec.bindir = "exe"
21
+ spec.executables << "git_diff_lcs"
22
+
23
+ spec.license = "MIT"
24
+ spec.add_dependency "diff-lcs", "1.4.4"
25
+ spec.add_dependency "git", "1.8.1"
26
+ spec.add_runtime_dependency "thor", "1.1.0"
27
+ end
data/lib/git_diff_lcs.rb CHANGED
@@ -1,13 +1,26 @@
1
- # frozen_string_literal: true
2
-
3
- require "git_diff_lcs/stat"
4
- require "git_diff_lcs/version"
5
- require "git_diff_lcs/cli"
6
-
7
- # Git Diff LCS
8
- module GitDiffLcs
9
- def self.diff(repo, src, dest)
10
- diff = GitDiffLcs::Stat.new(repo, src, dest)
11
- diff.summary
12
- end
13
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "git_diff_lcs/stat"
4
+ require "git_diff_lcs/version"
5
+ require "git_diff_lcs/cli"
6
+
7
+ # Git Diff LCS
8
+ module GitDiffLCS
9
+ # Get diff summary with LCS algorithm
10
+ #
11
+ # Arguments:
12
+ # [String] repo: repo git repository address
13
+ # [String] src: src src commit or branch
14
+ # [String] dest: dest commit or branch
15
+ #
16
+ # Return:
17
+ # [String] diff summary (changed files, insertions, deletions, modifications and total)
18
+ #
19
+ # Example:
20
+ # >> GitDiffLCS.diff("https://github.com/btpink-seo/git-diff-lcs.git", "test/src", "test/dest")
21
+ # => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
22
+ def self.diff(repo, src, dest)
23
+ diff = GitDiffLCS::Stat.new(repo, src, dest)
24
+ diff.errors.empty? ? diff.summary : diff.errors.first
25
+ end
26
+ end
@@ -1,18 +1,18 @@
1
- # frozen_string_literal: true
2
-
3
- require "thor"
4
-
5
- # Git Diff LCS
6
- module GitDiffLcs
7
- # Command Line Interface
8
- class CLI < Thor
9
- def self.exit_on_failure?
10
- true
11
- end
12
-
13
- desc "diff GIT_REPOSITORY, SRC(BRANCH OR COMMIT), DEST(BRANCH OR COMMIT)", "get diff with LCS"
14
- def diff(repo, src, dest)
15
- puts GitDiffLcs.diff(repo, src, dest)
16
- end
17
- end
18
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "thor"
4
+
5
+ # Git Diff LCS
6
+ module GitDiffLCS
7
+ # Command Line Interface
8
+ class CLI < Thor
9
+ def self.exit_on_failure?
10
+ true
11
+ end
12
+
13
+ desc "diff GIT_REPOSITORY SRC(BRANCH OR COMMIT) DEST(BRANCH OR COMMIT)", "get diff with LCS"
14
+ def diff(repo, src, dest)
15
+ puts GitDiffLCS.diff(repo, src, dest)
16
+ end
17
+ end
18
+ end
@@ -1,105 +1,118 @@
1
- # frozen_string_literal: true
2
-
3
- require "securerandom"
4
- require "diff/lcs"
5
- require "git"
6
-
7
- # Git Diff LCS
8
- module GitDiffLcs
9
- # Stat
10
- class Stat
11
- SRC_FOLDER = "src_#{SecureRandom.uuid}"
12
- DEST_FOLDER = "dest_#{SecureRandom.uuid}"
13
- INIT_COUNT = [0, 0, 0].freeze
14
-
15
- # repo(String) : git repository address
16
- # src(String) : src commit or branch
17
- # dest(String) : dest commit or branch
18
- def initialize(repo, src, dest)
19
- @go_next = false
20
- @dir = Dir.mktmpdir
21
- @add, @del, @mod = *INIT_COUNT
22
- @target_files = []
23
-
24
- @diff = git_clone(repo, src, dest).diff(src, dest)
25
- @target_files = @diff.name_status.keys
26
- calculate
27
- rescue Git::GitExecuteError
28
- puts "[ERROR] wrong git info(repo or src or dest)"
29
- end
30
-
31
- def summary
32
- total = @add + @del + @mod
33
- changed = @target_files.size
34
- "#{changed} files changed, #{@add} insertions(+), #{@del} deletions(-), #{@mod} modifications(!), total(#{total})"
35
- end
36
-
37
- def insertions
38
- @add
39
- end
40
-
41
- def deletions
42
- @del
43
- end
44
-
45
- def modifications
46
- @mod
47
- end
48
-
49
- private
50
-
51
- def close
52
- FileUtils.rm_rf(@dir)
53
- end
54
-
55
- def git_clone(repo, src, dest)
56
- git = Git.clone(repo, SRC_FOLDER, path: @dir)
57
- git.checkout(dest)
58
- FileUtils.copy_entry("#{@dir}/#{SRC_FOLDER}", "#{@dir}/#{DEST_FOLDER}")
59
- git.checkout(src)
60
- git
61
- end
62
-
63
- def open_src_file(src_filename, dest_filename)
64
- File.open(src_filename)
65
- rescue Errno::ENOENT
66
- # p "new file in dest #{file}"
67
- @add += open_dest_file(nil, dest_filename).readlines.size
68
- @go_next = true
69
- end
70
-
71
- def open_dest_file(src, dest_filename)
72
- File.open(dest_filename)
73
- rescue Errno::ENOENT
74
- # p "deleted file in dest #{file}"
75
- @del += src.readlines.size
76
- @go_next = true
77
- end
78
-
79
- def add_result(diff)
80
- # p diff if diff.adding? || diff.deleting? || diff.changed?
81
- @add += 1 if diff.adding?
82
- @del += 1 if diff.deleting?
83
- @mod += 1 if diff.changed?
84
- end
85
-
86
- # rubocop:disable Metrics/MethodLength
87
- def calculate
88
- @target_files.each do |file|
89
- src_filename = "#{@dir}/#{SRC_FOLDER}/#{file}"
90
- dest_filename = "#{@dir}/#{DEST_FOLDER}/#{file}"
91
-
92
- src = open_src_file(src_filename, dest_filename)
93
- dest = open_dest_file(src, dest_filename)
94
-
95
- next if @go_next && !(@go_next = !@go_next)
96
- next if FileUtils.cmp(src_filename, dest_filename)
97
-
98
- diffs = Diff::LCS.sdiff(src.readlines, dest.readlines)
99
- diffs.each { |d| add_result(d) }
100
- end
101
- close
102
- end
103
- # rubocop:enable Metrics/MethodLength
104
- end
105
- end
1
+ # frozen_string_literal: true
2
+
3
+ require "securerandom"
4
+ require "diff/lcs"
5
+ require "git"
6
+
7
+ # Git Diff LCS
8
+ module GitDiffLCS
9
+ # Stat
10
+ class Stat
11
+ # Source folder
12
+ SRC_FOLDER = "src_#{SecureRandom.uuid}"
13
+
14
+ # Destination folder
15
+ DEST_FOLDER = "dest_#{SecureRandom.uuid}"
16
+
17
+ # Initial diff count number
18
+ INIT_COUNT = [0, 0, 0].freeze
19
+
20
+ # Initial array for target_files and errors
21
+ INIT_ARRAY = Array.new(2, [])
22
+
23
+ attr_reader :add, :del, :mod, :errors
24
+ alias insertions add
25
+ alias deletions del
26
+ alias modifications mod
27
+
28
+ # initialize GitDiffLCS::Stat
29
+ #
30
+ # Arguments:
31
+ # [String] repo: repo git repository address
32
+ # [String] src: src src commit or branch
33
+ # [String] dest: dest commit or branch
34
+ def initialize(repo, src, dest)
35
+ @go_next = false
36
+ @dir = Dir.mktmpdir
37
+ @add, @del, @mod = *INIT_COUNT
38
+ @target_files, @errors = *Array.new(2, [])
39
+ @diff = git_clone(repo, src, dest).diff(src, dest)
40
+ calculate
41
+ rescue Git::GitExecuteError
42
+ @errors << "[ERROR] wrong git info(repository or src or dest)"
43
+ ensure
44
+ FileUtils.rm_rf(@dir)
45
+ end
46
+
47
+ # Get diff summary
48
+ # changed files, insertions, deletions, modifications and total
49
+ #
50
+ # Return:
51
+ # [String] diff summary
52
+ #
53
+ # Example:
54
+ # >> stat = GitDiffLCS::Stat.new("https://github.com/btpink-seo/git-diff-lcs.git", "test/src", "test/dest")
55
+ # >> stat.summary
56
+ # => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
57
+ def summary
58
+ total = @add + @del + @mod
59
+ changed = @target_files.size
60
+ "#{changed} files changed, #{@add} insertions(+), #{@del} deletions(-), #{@mod} modifications(!), total(#{total})"
61
+ end
62
+
63
+ private
64
+
65
+ # git clone and copy to destination folder for compare
66
+ def git_clone(repo, src, dest)
67
+ git = Git.clone(repo, SRC_FOLDER, path: @dir)
68
+ git.checkout(dest)
69
+ FileUtils.copy_entry("#{@dir}/#{SRC_FOLDER}", "#{@dir}/#{DEST_FOLDER}")
70
+ git.checkout(src)
71
+ git
72
+ end
73
+
74
+ # open_src_file
75
+ # if dosen't exist file, add insertions all dest line length
76
+ def open_src_file(src_filename, dest_filename)
77
+ File.open(src_filename)
78
+ rescue Errno::ENOENT
79
+ # new file in dest
80
+ @add += open_dest_file(nil, dest_filename).readlines.size
81
+ @go_next = true
82
+ end
83
+
84
+ # open_dest_file
85
+ # if dosen't exist file, add deletions all src line length
86
+ def open_dest_file(src, dest_filename)
87
+ File.open(dest_filename)
88
+ rescue Errno::ENOENT
89
+ # deleted file in dest
90
+ @del += src.readlines.size
91
+ @go_next = true
92
+ end
93
+
94
+ # add each count variable
95
+ def add_result(diff)
96
+ @add += 1 if diff.adding?
97
+ @del += 1 if diff.deleting?
98
+ @mod += 1 if diff.changed?
99
+ end
100
+
101
+ # count diff
102
+ def calculate
103
+ @target_files = @diff.name_status.keys
104
+ @target_files.each do |file|
105
+ src_filename = "#{@dir}/#{SRC_FOLDER}/#{file}"
106
+ dest_filename = "#{@dir}/#{DEST_FOLDER}/#{file}"
107
+
108
+ src = open_src_file(src_filename, dest_filename)
109
+ dest = open_dest_file(src, dest_filename)
110
+
111
+ next if @go_next && !(@go_next = !@go_next)
112
+ next if FileUtils.cmp(src_filename, dest_filename)
113
+
114
+ Diff::LCS.sdiff(src.readlines, dest.readlines).each { |d| add_result(d) }
115
+ end
116
+ end
117
+ end
118
+ end
@@ -1,5 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
- module GitDiffLcs
4
- VERSION = "0.0.5"
5
- end
1
+ # frozen_string_literal: true
2
+
3
+ module GitDiffLCS
4
+ VERSION = "0.0.6"
5
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_diff_lcs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - SEO SANG HYUN
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-03-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diff-lcs