This commit introduces the `FileStats` struct, that adds the insertions
and deletions for each file to `DiffContent`.
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
Previously we only syntax highlighted files that were blobs inside the
git repo. This doesn't work when diffing files in the working copy.
We solve that by looking for files in the working copy if they aren't
found in the ODB.
Define types to support Diff of Diffs leaning on the Radicle Surf types.
Use Radicle Surf's Hunk type, but custom Diff, FileDiff, and
Modification types, and avoid Serde serialization as it does not yet
seem necessary.
Parse Git's unified diff format into Radicle Surf's types. Support to
and from the format helps testing and debugging.
Split the UnifiedDiff trait into Decode and Encode traits so we
can offer Decode in cases where no data could be expected..
For example Option<Hunk<_>> and Hunk<_> allowing partial and repeated
decoding on a byte stream.
Avoid decoding `Diff`, `DiffContent::Binary`, `FileDiff`, and `FileHeader`
types. `Diff` keeps fields and methods private which are necessary for
decoding.
Simplify the trait by defining it on the concrete type, which appears to
be the standard rust approach. Remove some oddities in the process (refs
of refs).
Move code for writing radicle_surf diff's in git's unified diff format
into its own module. Lean on the type system by defining a
`UnifiedDiff` trait to provide a method `encode` to encode to the
format and another default method to convert to a git 'unified' diff
string.
Additionally a `Header` struct is added to support processing Unified
Diff files. The Header's line numbers must be tracked and modified to
produce legal diff files.
This is in preparation for DDiff support. Upcoming improvements will
include parse unified diff's into these types to support test data.