Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
bin: Make hunk items debuggable
Erik Kundt committed 1 year ago
commit 537e8be681db594b39bcd09bf1a92bda9e351f34
parent 1768304
2 files changed +38 -2
modified 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);

modified 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<Vec<(EntryId, Comment<CodeLocation>)>> 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<Line<'a>> for HighlightedLine<'a> {