Hello community,
here is the log from the commit of package rubygem-hashdiff for
openSUSE:Factory checked in at 2019-06-19 21:00:03
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/rubygem-hashdiff (Old)
and /work/SRC/openSUSE:Factory/.rubygem-hashdiff.new.4811 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-hashdiff"
Wed Jun 19 21:00:03 2019 rev:8 rq:705995 version:0.3.9
Changes:
--------
--- /work/SRC/openSUSE:Factory/rubygem-hashdiff/rubygem-hashdiff.changes
2019-01-21 10:54:11.763740094 +0100
+++
/work/SRC/openSUSE:Factory/.rubygem-hashdiff.new.4811/rubygem-hashdiff.changes
2019-06-19 21:00:05.630072103 +0200
@@ -1,0 +2,10 @@
+Sun May 5 09:30:22 UTC 2019 - Stephan Kulow <[email protected]>
+
+- updated to version 0.3.9
+ see installed changelog.md
+
+ ## v0.3.9 2019-04-22
+
+ * Performance tweak (thanks @krzysiek1507: #51 #52 #53)
+
+-------------------------------------------------------------------
Old:
----
hashdiff-0.3.8.gem
New:
----
hashdiff-0.3.9.gem
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ rubygem-hashdiff.spec ++++++
--- /var/tmp/diff_new_pack.JKyilO/_old 2019-06-19 21:00:06.330072730 +0200
+++ /var/tmp/diff_new_pack.JKyilO/_new 2019-06-19 21:00:06.338072737 +0200
@@ -24,12 +24,12 @@
#
Name: rubygem-hashdiff
-Version: 0.3.8
+Version: 0.3.9
Release: 0
%define mod_name hashdiff
%define mod_full_name %{mod_name}-%{version}
BuildRoot: %{_tmppath}/%{name}-%{version}-build
-BuildRequires: %{ruby >= 1.9.3}
+BuildRequires: %{ruby >= 2.0.0}
BuildRequires: %{rubygem gem2rpm}
BuildRequires: ruby-macros >= 5
Url: https://github.com/liufengyun/hashdiff
++++++ hashdiff-0.3.8.gem -> hashdiff-0.3.9.gem ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/.rubocop.yml new/.rubocop.yml
--- old/.rubocop.yml 2018-12-30 19:46:35.000000000 +0100
+++ new/.rubocop.yml 2019-04-22 21:45:39.000000000 +0200
@@ -17,5 +17,8 @@
Enabled: false
Style/Documentation:
Enabled: false
+Style/FrozenStringLiteralComment:
+ Enabled: true
+ EnforcedStyle: always
RSpec/ExampleLength:
Enabled: false
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Gemfile new/Gemfile
--- old/Gemfile 2018-12-30 19:46:35.000000000 +0100
+++ new/Gemfile 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
source 'http://rubygems.org'
gemspec
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/README.md new/README.md
--- old/README.md 2018-12-30 19:46:35.000000000 +0100
+++ new/README.md 2019-04-22 21:45:39.000000000 +0200
@@ -8,6 +8,9 @@
**Docs**: [Documentation](http://rubydoc.info/gems/hashdiff)
+
+__WARNING__: Don't use the library for comparing large arrays, say ~10K (see
#49).
+
## Why HashDiff?
Given two Hashes A and B, sometimes you face the question: what's the smallest
modification that can be made to change A into B?
@@ -262,4 +265,3 @@
## License
HashDiff is distributed under the MIT-LICENSE.
-
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/Rakefile new/Rakefile
--- old/Rakefile 2018-12-30 19:46:35.000000000 +0100
+++ new/Rakefile 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
require 'rubocop/rake_task'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/changelog.md new/changelog.md
--- old/changelog.md 2018-12-30 19:46:35.000000000 +0100
+++ new/changelog.md 2019-04-22 21:45:39.000000000 +0200
@@ -1,5 +1,9 @@
# Change Log
+## v0.3.9 2019-04-22
+
+* Performance tweak (thanks @krzysiek1507: #51 #52 #53)
+
## v0.3.8 2018-12-30
* Add Rubocop and drops Ruby 1.9 support #47
@@ -73,4 +77,3 @@
instead of following:
[['-', 'c[0]', 4], ['-', 'c[1]', 5], ['-', 'c', []]]
-
Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/hashdiff.gemspec new/hashdiff.gemspec
--- old/hashdiff.gemspec 2018-12-30 19:46:35.000000000 +0100
+++ new/hashdiff.gemspec 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
$LOAD_PATH << File.expand_path('lib', __dir__)
require 'hashdiff/version'
@@ -12,7 +14,7 @@
s.test_files = `git ls-files -- Appraisals {spec}/*`.split("\n")
s.require_paths = ['lib']
- s.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
+ s.required_ruby_version = Gem::Requirement.new('>= 2.0.0')
s.authors = ['Liu Fengyun']
s.email = ['[email protected]']
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/diff.rb new/lib/hashdiff/diff.rb
--- old/lib/hashdiff/diff.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff/diff.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module HashDiff
# Best diff two objects, which tries to generate the smallest change set
using different similarity values.
#
@@ -120,13 +122,15 @@
elsif obj1.is_a?(Array) && !opts[:use_lcs]
result.concat(LinearCompareArray.call(obj1, obj2, opts))
elsif obj1.is_a?(Hash)
+ obj1_keys = obj1.keys
+ obj2_keys = obj2.keys
- deleted_keys = obj1.keys - obj2.keys
- common_keys = obj1.keys & obj2.keys
- added_keys = obj2.keys - obj1.keys
+ deleted_keys = (obj1_keys - obj2_keys).sort_by(&:to_s)
+ common_keys = (obj1_keys & obj2_keys).sort_by(&:to_s)
+ added_keys = (obj2_keys - obj1_keys).sort_by(&:to_s)
# add deleted properties
- deleted_keys.sort_by { |k, _v| k.to_s }.each do |k|
+ deleted_keys.each do |k|
change_key = prefix_append_key(opts[:prefix], k, opts)
custom_result = custom_compare(opts[:comparison], change_key, obj1[k],
nil)
@@ -138,13 +142,13 @@
end
# recursive comparison for common keys
- common_keys.sort_by { |k, _v| k.to_s }.each do |k|
+ common_keys.each do |k|
prefix = prefix_append_key(opts[:prefix], k, opts)
result.concat(diff(obj1[k], obj2[k], opts.merge(prefix: prefix)))
end
# added properties
- added_keys.sort_by { |k, _v| k.to_s }.each do |k|
+ added_keys.each do |k|
change_key = prefix_append_key(opts[:prefix], k, opts)
next if obj1.key?(k)
@@ -169,28 +173,33 @@
#
# diff array using LCS algorithm
def self.diff_array_lcs(arraya, arrayb, options = {})
- opts = {
- prefix: '',
- similarity: 0.8,
- delimiter: '.'
- }.merge!(options)
+ return [] if arraya.empty? && arrayb.empty?
change_set = []
- return [] if arraya.empty? && arrayb.empty?
if arraya.empty?
arrayb.each_index do |index|
change_set << ['+', index, arrayb[index]]
end
+
return change_set
- elsif arrayb.empty?
+ end
+
+ if arrayb.empty?
arraya.each_index do |index|
i = arraya.size - index - 1
change_set << ['-', i, arraya[i]]
end
+
return change_set
end
+ opts = {
+ prefix: '',
+ similarity: 0.8,
+ delimiter: '.'
+ }.merge!(options)
+
links = lcs(arraya, arrayb, opts)
# yield common
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/lcs.rb new/lib/hashdiff/lcs.rb
--- old/lib/hashdiff/lcs.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff/lcs.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,15 +1,17 @@
+# frozen_string_literal: true
+
module HashDiff
# @private
#
# caculate array difference using LCS algorithm
# http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
def self.lcs(arraya, arrayb, options = {})
+ return [] if arraya.empty? || arrayb.empty?
+
opts = { similarity: 0.8 }.merge!(options)
opts[:prefix] = prefix_append_array_index(opts[:prefix], '*', opts)
- return [] if arraya.empty? || arrayb.empty?
-
a_start = b_start = 0
a_finish = arraya.size - 1
b_finish = arrayb.size - 1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/linear_compare_array.rb
new/lib/hashdiff/linear_compare_array.rb
--- old/lib/hashdiff/linear_compare_array.rb 2018-12-30 19:46:35.000000000
+0100
+++ new/lib/hashdiff/linear_compare_array.rb 2019-04-22 21:45:39.000000000
+0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module HashDiff
# @private
#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/patch.rb new/lib/hashdiff/patch.rb
--- old/lib/hashdiff/patch.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff/patch.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#
# This module provides methods to diff two hash, patch and unpatch hash
#
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/util.rb new/lib/hashdiff/util.rb
--- old/lib/hashdiff/util.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff/util.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module HashDiff
# @private
#
@@ -5,14 +7,15 @@
def self.similar?(obja, objb, options = {})
return compare_values(obja, objb, options) unless obja.is_a?(Array) ||
obja.is_a?(Hash) || objb.is_a?(Array) || objb.is_a?(Hash)
- opts = { similarity: 0.8 }.merge(options)
-
count_a = count_nodes(obja)
count_b = count_nodes(objb)
- diffs = count_diff diff(obja, objb, opts)
return true if (count_a + count_b).zero?
+ opts = { similarity: 0.8 }.merge!(options)
+
+ diffs = count_diff diff(obja, objb, opts)
+
(1 - diffs.to_f / (count_a + count_b).to_f) >= opts[:similarity]
end
@@ -81,8 +84,8 @@
#
# check for equality or "closeness" within given tolerance
def self.compare_values(obj1, obj2, options = {})
- if (options[:numeric_tolerance].is_a? Numeric) &&
- [obj1, obj2].all? { |v| v.is_a? Numeric }
+ if options[:numeric_tolerance].is_a?(Numeric) &&
+ obj1.is_a?(Numeric) && obj2.is_a?(Numeric)
return (obj1 - obj2).abs <= options[:numeric_tolerance]
end
@@ -103,9 +106,7 @@
#
# check if objects are comparable
def self.comparable?(obj1, obj2, strict = true)
- [Array, Hash].each do |type|
- return true if obj1.is_a?(type) && obj2.is_a?(type)
- end
+ return true if (obj1.is_a?(Array) || obj1.is_a?(Hash)) &&
obj2.is_a?(obj1.class)
return true if !strict && obj1.is_a?(Numeric) && obj2.is_a?(Numeric)
obj1.is_a?(obj2.class) && obj2.is_a?(obj1.class)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff/version.rb new/lib/hashdiff/version.rb
--- old/lib/hashdiff/version.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff/version.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
module HashDiff
- VERSION = '0.3.8'.freeze
+ VERSION = '0.3.9'.freeze
end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/lib/hashdiff.rb new/lib/hashdiff.rb
--- old/lib/hashdiff.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/lib/hashdiff.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,6 +1,8 @@
-require 'hashdiff/util'
-require 'hashdiff/lcs'
-require 'hashdiff/linear_compare_array'
-require 'hashdiff/diff'
-require 'hashdiff/patch'
-require 'hashdiff/version'
+# frozen_string_literal: true
+
+require_relative 'hashdiff/util'
+require_relative 'hashdiff/lcs'
+require_relative 'hashdiff/linear_compare_array'
+require_relative 'hashdiff/diff'
+require_relative 'hashdiff/patch'
+require_relative 'hashdiff/version'
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/metadata new/metadata
--- old/metadata 2018-12-30 19:46:35.000000000 +0100
+++ new/metadata 2019-04-22 21:45:39.000000000 +0200
@@ -1,14 +1,14 @@
--- !ruby/object:Gem::Specification
name: hashdiff
version: !ruby/object:Gem::Version
- version: 0.3.8
+ version: 0.3.9
platform: ruby
authors:
- Liu Fengyun
autorequire:
bindir: bin
cert_chain: []
-date: 2018-12-30 00:00:00.000000000 Z
+date: 2019-04-22 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: bluecloth
@@ -126,7 +126,7 @@
requirements:
- - ">="
- !ruby/object:Gem::Version
- version: 1.9.3
+ version: 2.0.0
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/best_diff_spec.rb
new/spec/hash_diff/best_diff_spec.rb
--- old/spec/hash_diff/best_diff_spec.rb 2018-12-30 19:46:35.000000000
+0100
+++ new/spec/hash_diff/best_diff_spec.rb 2019-04-22 21:45:39.000000000
+0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/diff_array_spec.rb
new/spec/hash_diff/diff_array_spec.rb
--- old/spec/hash_diff/diff_array_spec.rb 2018-12-30 19:46:35.000000000
+0100
+++ new/spec/hash_diff/diff_array_spec.rb 2019-04-22 21:45:39.000000000
+0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/diff_spec.rb
new/spec/hash_diff/diff_spec.rb
--- old/spec/hash_diff/diff_spec.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/spec/hash_diff/diff_spec.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/lcs_spec.rb
new/spec/hash_diff/lcs_spec.rb
--- old/spec/hash_diff/lcs_spec.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/spec/hash_diff/lcs_spec.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/linear_compare_array_spec.rb
new/spec/hash_diff/linear_compare_array_spec.rb
--- old/spec/hash_diff/linear_compare_array_spec.rb 2018-12-30
19:46:35.000000000 +0100
+++ new/spec/hash_diff/linear_compare_array_spec.rb 2019-04-22
21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff::LinearCompareArray do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/patch_spec.rb
new/spec/hash_diff/patch_spec.rb
--- old/spec/hash_diff/patch_spec.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/spec/hash_diff/patch_spec.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/hash_diff/util_spec.rb
new/spec/hash_diff/util_spec.rb
--- old/spec/hash_diff/util_spec.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/spec/hash_diff/util_spec.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe HashDiff do
@@ -18,6 +20,14 @@
described_class.similar?(a, b, similarity: 1).should be false
end
+ it 'is able to tell similiar empty hash' do
+ described_class.similar?({}, {}, 1).should be true
+ end
+
+ it 'is able to tell similiar empty array' do
+ described_class.similar?([], [], 1).should be true
+ end
+
it 'is able to tell similiar hash with values within tolerance' do
a = { 'a' => 1.5, 'b' => 2.25, 'c' => 3, 'd' => 4, 'e' => 5 }
b = { 'a' => 1.503, 'b' => 2.22, 'c' => 3, 'e' => 5 }
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn'
'--exclude=.svnignore' old/spec/spec_helper.rb new/spec/spec_helper.rb
--- old/spec/spec_helper.rb 2018-12-30 19:46:35.000000000 +0100
+++ new/spec/spec_helper.rb 2019-04-22 21:45:39.000000000 +0200
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
$LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib')
require 'rubygems'