mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-15 16:00:38 +08:00
bin: Make hunk items debuggable
This commit is contained in:
+26
-1
@@ -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);
|
||||
|
||||
|
||||
+12
-1
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user