@@ -10,6 +10,7 @@ class ReportDiff
1010 attr_accessor :base_violations_size
1111 attr_accessor :patch_violations_size
1212 attr_accessor :new_violations_size
13+ attr_accessor :changed_violations_size
1314 attr_accessor :removed_violations_size
1415 attr_accessor :violation_diffs_size
1516
@@ -88,28 +89,28 @@ def diffs_exist?
8889 def calculate_violations ( base_violations , patch_violations )
8990 @base_violations_size = base_violations . violations_size
9091 @patch_violations_size = patch_violations . violations_size
91- violation_diffs = build_diffs ( base_violations . violations , patch_violations . violations )
92- @violation_diffs = violation_diffs
93- @new_violations_size , @removed_violations_size = get_diffs_size ( violation_diffs )
94- @violation_diffs_size = @new_violations_size + @removed_violations_size
92+
93+ @violation_diffs = build_diffs ( base_violations . violations , patch_violations . violations )
94+ @violation_diffs = merge_changed_violations ( @violation_diffs )
95+
96+ @new_violations_size , @changed_violations_size , @removed_violations_size = get_diffs_size ( @violation_diffs )
97+ @violation_diffs_size = @violation_diffs . size
9598 end
9699
97100 def calculate_errors ( base_errors , patch_errors )
98101 @base_errors_size = base_errors . errors_size
99102 @patch_errors_size = patch_errors . errors_size
100- error_diffs = build_diffs ( base_errors . errors , patch_errors . errors )
101- @error_diffs = error_diffs
102- @new_errors_size , @removed_errors_size = get_diffs_size ( error_diffs )
103- @error_diffs_size = @new_errors_size + @removed_errors_size
103+ @error_diffs = build_diffs ( base_errors . errors , patch_errors . errors )
104+ @new_errors_size , _ , @removed_errors_size = get_diffs_size ( @error_diffs )
105+ @error_diffs_size = @error_diffs . size
104106 end
105107
106108 def calculate_configerrors ( base_configerrors , patch_configerrors )
107109 @base_configerrors_size = base_configerrors . size
108110 @patch_configerrors_size = patch_configerrors . size
109- configerrors_diffs = build_diffs ( base_configerrors . errors , patch_configerrors . errors )
110- @configerrors_diffs = configerrors_diffs
111- @new_configerrors_size , @removed_configerrors_size = get_diffs_size ( configerrors_diffs )
112- @configerrors_diffs_size = @new_configerrors_size + @removed_configerrors_size
111+ @configerrors_diffs = build_diffs ( base_configerrors . errors , patch_configerrors . errors )
112+ @new_configerrors_size , _ , @removed_configerrors_size = get_diffs_size ( @configerrors_diffs )
113+ @configerrors_diffs_size = @configerrors_diffs . size
113114 end
114115
115116 def calculate_details ( base_info , patch_info )
@@ -130,7 +131,10 @@ def calculate_details(base_info, patch_info)
130131 end
131132
132133 def build_diffs ( base_hash , patch_hash )
134+ # Keys are filenames
135+ # Values are lists of violations/errors
133136 diffs = base_hash . merge ( patch_hash ) do |_key , base_value , patch_value |
137+ # make the difference of values
134138 ( base_value | patch_value ) - ( base_value & patch_value )
135139 end
136140
@@ -139,15 +143,33 @@ def build_diffs(base_hash, patch_hash)
139143 end
140144 end
141145
146+ # @param diff_violations a hash { filename => list[violation]}, containing those that changed
147+ def merge_changed_violations ( diff_violations )
148+ diff_violations . each do |fname , different |
149+ diff_violations [ fname ] = different . dup . delete_if { |v |
150+ v . branch == BASE &&
151+ # try_merge will set v2.changed = true if it succeeds
152+ different . any? { |v2 | v2 . try_merge? ( v ) }
153+ }
154+ end
155+ end
156+
142157 def get_diffs_size ( diffs_hash )
143158 new_size = 0
159+ changed_size = 0
144160 removed_size = 0
145161 diffs_hash . each_value do |value |
146162 value . each do |item |
147- item . branch . eql? ( BASE ) ? removed_size += 1 : new_size += 1
163+ if item . changed
164+ changed_size += 1
165+ elsif item . branch . eql? ( BASE )
166+ removed_size += 1
167+ else
168+ new_size += 1
169+ end
148170 end
149171 end
150- [ new_size , removed_size ]
172+ [ new_size , changed_size , removed_size ]
151173 end
152174
153175 def introduce_new_errors?
0 commit comments