diff --git a/bin/git.rs b/bin/git.rs index 858f4884..7aad314b 100644 --- a/bin/git.rs +++ b/bin/git.rs @@ -1,3 +1,5 @@ +use std::fmt; +use std::fmt::Debug; use std::path::Path; use std::{fs, path::PathBuf}; @@ -222,7 +224,7 @@ pub enum HunkState { /// A single review item. Can be a hunk or eg. a file move. /// Files are usually split into multiple review items. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, PartialEq)] pub enum HunkDiff { Added { path: PathBuf, @@ -327,6 +329,29 @@ impl HunkDiff { } } +impl Debug for HunkDiff { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (name, path, hunk) = match self { + Self::Added { path, hunk, .. } => ("Added", path, hunk), + Self::Deleted { path, hunk, .. } => ("Deleted", path, hunk), + Self::Moved { moved } => ("Moved", &moved.new_path, &None), + Self::Copied { copied } => ("Copied", &copied.new_path, &None), + Self::Modified { path, hunk, .. } => ("Modified", path, hunk), + Self::EofChanged { path, .. } => ("EofChanged", path, &None), + Self::ModeChanged { path, .. } => ("ModeChanged", path, &None), + }; + + match hunk { + Some(hunk) => f + .debug_struct(name) + .field("path", path) + .field("hunk", &(hunk.old.clone(), hunk.new.clone())) + .finish(), + _ => f.debug_struct(name).field("path", path).finish(), + } + } +} + #[derive(Clone, Debug)] pub struct StatefulHunkDiff(HunkDiff, HunkState); diff --git a/bin/ui/items.rs b/bin/ui/items.rs index 4f489c3f..128260c6 100644 --- a/bin/ui/items.rs +++ b/bin/ui/items.rs @@ -1,4 +1,6 @@ use std::collections::HashMap; +use std::fmt; +use std::fmt::Debug; use std::str::FromStr; use nom::bytes::complete::{tag, take}; @@ -1090,7 +1092,7 @@ impl From)>> for HunkComments { /// A [`HunkItem`] that can be rendered. Hunk items are indexed sequentially and /// provide access to the underlying hunk type. -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct HunkItem<'a> { /// The underlying hunk type and its current state (accepted / rejected). pub inner: StatefulHunkDiff, @@ -1580,6 +1582,15 @@ impl<'a> HunkItem<'a> { } } +impl<'a> Debug for HunkItem<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("HunkItem") + .field("inner", &self.inner) + .field("comments", &self.comments) + .finish() + } +} + pub struct HighlightedLine<'a>(Line<'a>); impl<'a> From> for HighlightedLine<'a> {