1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:38:11 +00:00

LibDiff: Change underlying representation of Hunk to allow context

The existing hunk data structure does not contain any way to easily
store information about context surrounding the additions and removals
in a hunk. While this does work fine for normal diffs (where there is
never any surrounding context) this data structure is quite limiting for
other use cases.

Without support for surrounding context it is not possible to:
 * Add support for unified or context format to the diff utility to
   output surrounding context.
 * Be able to implement a patch utility that uses the surrounding
   context to reliably locate where to apply a patch when a hunk range
   does not apply perfectly.

This patch changes Diff::Hunk such that its data structure more closely
resembles a unified diff. Each line in a hunk is now either a change,
removal, addition or context.

Allowing hunks to have context inside of them exposes that HackStudio
heavily relies on there being no context in the hunks that it uses for
its' git gutter implementation. The fix here is simple - ask git to
produce us a diff that has no context in it!
This commit is contained in:
Shannon Booth 2023-06-24 17:33:04 +12:00 committed by Andrew Kaster
parent ef8f0f4f68
commit f690807c5a
8 changed files with 169 additions and 127 deletions

View file

@ -118,7 +118,7 @@ Optional<DeprecatedString> GitRepo::original_file_content(DeprecatedString const
Optional<DeprecatedString> GitRepo::unstaged_diff(DeprecatedString const& file) const
{
return command({ "diff", file.characters() });
return command({ "diff", "-U0", file.characters() });
}
bool GitRepo::is_tracked(DeprecatedString const& file) const