git_diff_lcs 0.0.3

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5e272a492729c1b017559606e83a4791c7a0d388582efc226f193e44af97414c
4
+ data.tar.gz: ef406c7e347e1acbfdea5ca4c0c4ada7135044d3b730b5283b6dda0841934270
5
+ SHA512:
6
+ metadata.gz: d9743ca91179cbc87e26e85a8307c1efef197b6b951776a6d5afddb569e92272b4cdabe0f72b82abc30c94a1b255d0770d3e0e7521ad0b272c10feeba7f15f35
7
+ data.tar.gz: 3e6f78375468c2a003a51a202e246ca036f04b7b84b5d14a83b0851c8c630074670753ec5513b66be8866a57d7dd9e05342bac4caf6590a3906692c7ab90e296
@@ -0,0 +1,18 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ *.gem
2
+ memo.txt
3
+
4
+ /.bundle/
5
+ /.yardoc
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ Style/EndOfLine:
16
+ EnforcedStyle: lf
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in git_diff_lcs.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 0.80"
data/Gemfile.lock ADDED
@@ -0,0 +1,61 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_diff_lcs (0.0.3)
5
+ diff-lcs (= 1.4.4)
6
+ git (= 1.8.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ diff-lcs (1.4.4)
13
+ git (1.8.1)
14
+ rchardet (~> 1.8)
15
+ parallel (1.20.1)
16
+ parser (3.0.0.0)
17
+ ast (~> 2.4.1)
18
+ rainbow (3.0.0)
19
+ rake (13.0.3)
20
+ rchardet (1.8.0)
21
+ regexp_parser (2.1.1)
22
+ rexml (3.2.4)
23
+ rspec (3.10.0)
24
+ rspec-core (~> 3.10.0)
25
+ rspec-expectations (~> 3.10.0)
26
+ rspec-mocks (~> 3.10.0)
27
+ rspec-core (3.10.1)
28
+ rspec-support (~> 3.10.0)
29
+ rspec-expectations (3.10.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-mocks (3.10.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-support (3.10.2)
36
+ rubocop (0.93.1)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.7.1.5)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.8)
41
+ rexml
42
+ rubocop-ast (>= 0.6.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 2.0)
45
+ rubocop-ast (1.4.1)
46
+ parser (>= 2.7.1.5)
47
+ ruby-progressbar (1.11.0)
48
+ unicode-display_width (1.7.0)
49
+
50
+ PLATFORMS
51
+ x64-mingw32
52
+ x86_64-linux
53
+
54
+ DEPENDENCIES
55
+ git_diff_lcs!
56
+ rake (~> 13.0)
57
+ rspec (~> 3.0)
58
+ rubocop (~> 0.80)
59
+
60
+ BUNDLED WITH
61
+ 2.2.13
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 btpink
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,16 @@
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
+ ```ruby
12
+ require 'git_diff_lcs'
13
+
14
+ GitDiffLcs.diff('https://github.com/btpink-seo/git-diff-lcs.git', 'main', 'gem')
15
+ # => 169 files changed, 10407 insertions(+), 84 deletions(-), 134 modifications(!), total(10625)
16
+ ```
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,18 @@
1
+ # A file which has a shebang line as its first line is
2
+ # granted execute permission.
3
+
4
+ #!/usr/bin/env ruby
5
+ # frozen_string_literal: true
6
+
7
+ require "bundler/setup"
8
+ require "git_diff_lcs"
9
+
10
+ # You can add fixtures and/or initialization code here to make experimenting
11
+ # with your gem easier. You can also use a different console, if you like.
12
+
13
+ # (If you use this, don't forget to add pry to your Gemfile!)
14
+ # require "pry"
15
+ # Pry.start
16
+
17
+ require "irb"
18
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
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 = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
22
+
23
+ spec.license = "MIT"
24
+ spec.add_dependency "diff-lcs", "1.4.4"
25
+ spec.add_dependency "git", "1.8.1"
26
+ end
@@ -0,0 +1,105 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitDiffLcs
4
+ VERSION = "0.0.3"
5
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "git_diff_lcs/stat"
4
+ require "git_diff_lcs/version"
5
+
6
+ # git diff lcs
7
+ module GitDiffLcs
8
+ def self.diff(repo, src, dest)
9
+ diff = GitDiffLcs::Stat.new(repo, src, dest)
10
+ diff.summary
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_diff_lcs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - SEO SANG HYUN
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-03-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: diff-lcs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.4.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.4.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: git
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ description: Add modifications to 'git diff --shortstat' using the LCS algorithm.
42
+ email: btpink.seo@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".github/workflows/main.yml"
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - bin/console
57
+ - bin/setup
58
+ - git_diff_lcs.gemspec
59
+ - lib/git_diff_lcs.rb
60
+ - lib/git_diff_lcs/stat.rb
61
+ - lib/git_diff_lcs/version.rb
62
+ homepage: https://github.com/btpink-seo/git-diff-lcs
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 2.4.0
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.4
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: "'git diff --shortstat' with modifications"
85
+ test_files: []