Fix sort order of `DiffByteRecord::Modify`

The following has been sorted non-deterministically (because it resulted in a comparison of result Equal):

file_a.csv with first column as key:

5,foo,bar
6,baz,quux

file_b.csv with first column as key:

6,bazt,quux
5,foo_doo,bar

...so it could result in the following (wrong) sort order: file_diff_result.csv:

-,6,baz,quux
+,6,bazt,quux
-,5,foo,bar
+,5,foo_doo,bar

The result of the above will now always be: file_diff_result.csv:

-,5,foo,bar
+,5,foo_doo,bar
-,6,baz,quux
+,6,bazt,quux

The reason for the bug was a comparison result of Equal, when "interleaved" Modify rows had the following structure:

  • line number of Delete part of file_a is equal to line number of Add part of file_b
  • line number of Delete part of file_b is equal to line number of Add part of file_a

This now always resolves to either:

  • Less (Delete part of file_a < Delete part of file_b) or
  • Greater (Delete part of file_a > Delete part of file_b) Note: previous logic has already handled the case:
  • Delete part of file_a == Delete part of file_b so no change of logic is needed for that case

Thank you @datatraveller1 for reporting the bug: => https://github.com/dathere/qsv/issues/2443#issuecomment-2598987465

Merge request reports

Loading