git_diff_lcs 0.0.4 → 0.0.5
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 +4 -4
- data/Gemfile.lock +63 -63
- data/README.md +45 -38
- data/exe/git_diff_lcs +7 -7
- data/git_diff_lcs.gemspec +27 -27
- data/lib/git_diff_lcs.rb +13 -13
- data/lib/git_diff_lcs/cli.rb +18 -18
- data/lib/git_diff_lcs/stat.rb +105 -105
- data/lib/git_diff_lcs/version.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2123947d389e4a5c12a5a274fb8e5598f20fcdfc275309b5e1a2edc1b9d5c461
|
4
|
+
data.tar.gz: 73b19ddf4745c3c5760587eeab2f161e26969e173d6bf58af232fc9d689e74cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16d21b22cae93be9c4018b00c27445ad1690e08e1b59bf636e81eff1b3233864c2082c919d429525d0962275136dfeb537ba0527dcdc894f3d9d8050899f9339
|
7
|
+
data.tar.gz: 20d284393155dc560423e06962f6759720e3785f50a30079bea557e9685da69e4971db9bbdd9048e6d652fa35ee6cc40401d5f6ac83c5c0527fd42c9e21d4c25
|
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.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
|
data/README.md
CHANGED
@@ -1,38 +1,45 @@
|
|
1
|
-
# GitDiffLcs
|
2
|
-
|
3
|
-
Generally, git diff --stat does not contain modifications, so we added it to display modifications using the LCS algorithm.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
```bash
|
7
|
-
$ gem install git_diff-lcs
|
8
|
-
```
|
9
|
-
|
10
|
-
## How to use
|
11
|
-
|
12
|
-
###
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
stat.
|
37
|
-
|
38
|
-
|
1
|
+
# GitDiffLcs
|
2
|
+
|
3
|
+
Generally, git diff --stat does not contain modifications, so we added it to display modifications using the LCS algorithm.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
```bash
|
7
|
+
$ gem install git_diff-lcs
|
8
|
+
```
|
9
|
+
|
10
|
+
## How to use
|
11
|
+
|
12
|
+
### CLI
|
13
|
+
|
14
|
+
```bash
|
15
|
+
$ git_diff_lcs diff https://github.com/btpink-seo/git-diff-lcs.git test/src test/dest
|
16
|
+
```
|
17
|
+
|
18
|
+
### Ruby
|
19
|
+
|
20
|
+
#### diff(repo, src, dest)
|
21
|
+
|
22
|
+
src, dest is branch name or commit
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'git_diff_lcs'
|
26
|
+
|
27
|
+
GitDiffLcs.diff('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
|
28
|
+
# => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
|
29
|
+
```
|
30
|
+
|
31
|
+
#### GitDiffLcs::Stat.new(repo, src, dest)
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'git_diff_lcs'
|
35
|
+
|
36
|
+
stat = GitDiffLcs::Stat.new('https://github.com/btpink-seo/git-diff-lcs.git', 'test/src', 'test/dest')
|
37
|
+
stat.summary
|
38
|
+
# => 5 files changed, 13 insertions(+), 6 deletions(-), 2 modifications(!), total(21)
|
39
|
+
stat.insertions
|
40
|
+
# => 13
|
41
|
+
stat.deletions
|
42
|
+
# => 6
|
43
|
+
stat.modifications
|
44
|
+
# => 2
|
45
|
+
```
|
data/exe/git_diff_lcs
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
#!/usr/bin/env ruby
|
4
|
-
|
5
|
-
require "git_diff_lcs"
|
6
|
-
|
7
|
-
GitDiffLcs::CLI.start(ARGV)
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
|
5
|
+
require "git_diff_lcs"
|
6
|
+
|
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
|
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,13 @@
|
|
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
|
-
#
|
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
|
+
def self.diff(repo, src, dest)
|
10
|
+
diff = GitDiffLcs::Stat.new(repo, src, dest)
|
11
|
+
diff.summary
|
12
|
+
end
|
13
|
+
end
|
data/lib/git_diff_lcs/cli.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "thor"
|
4
|
-
|
5
|
-
#
|
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
|
data/lib/git_diff_lcs/stat.rb
CHANGED
@@ -1,105 +1,105 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "securerandom"
|
4
|
-
require "diff/lcs"
|
5
|
-
require "git"
|
6
|
-
|
7
|
-
#
|
8
|
-
module GitDiffLcs
|
9
|
-
#
|
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
|
+
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
|
data/lib/git_diff_lcs/version.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module GitDiffLcs
|
4
|
-
VERSION = "0.0.
|
5
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GitDiffLcs
|
4
|
+
VERSION = "0.0.5"
|
5
|
+
end
|