In situations where you don't want to diff an entire file (for example you want to ignore some header), you could diff only a subset of the lines. But then the line numbers in the generated patch will be wrong since they will be relative to the start of that subset.
Would you be open to an API that supports setting line offsets for the original and modified text? Similar to DiffOptions::set_original_filename() and DiffOptions::set_modified_filename(), I think this could be added with a DiffOptions::set_original_line_offset() and DiffOptions::set_modified_line_offset(). These would add some integer offset to the generated Hunks.
An alternative API could be to add a Patch::hunks_mut() and the ability to update the old range and new range of each Hunk. Maybe a Hunk::new_range_add_offset(i64) and Hunk::old_range_add_offset(i64). This would also be useful for converting back after reading/parsing a patch.
Some workarounds are:
- Add blank lines to the original and modified text to cause diffy to generate the correct line numbers. But this isn't great when you want to skip a lot of lines.
- Manually parse the generated patch text and replace the line numbers.
In situations where you don't want to diff an entire file (for example you want to ignore some header), you could diff only a subset of the lines. But then the line numbers in the generated patch will be wrong since they will be relative to the start of that subset.
Would you be open to an API that supports setting line offsets for the original and modified text? Similar to
DiffOptions::set_original_filename()andDiffOptions::set_modified_filename(), I think this could be added with aDiffOptions::set_original_line_offset()andDiffOptions::set_modified_line_offset(). These would add some integer offset to the generatedHunks.An alternative API could be to add a
Patch::hunks_mut()and the ability to update the old range and new range of eachHunk. Maybe aHunk::new_range_add_offset(i64)andHunk::old_range_add_offset(i64). This would also be useful for converting back after reading/parsing a patch.Some workarounds are: