From 9743396d3d5324433e53c4d17c22fb72609323f2 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Tue, 17 Dec 2024 14:06:32 +0100 Subject: [PATCH] bin(patch): Log more review debug output --- bin/commands/patch/review.rs | 12 ++++++-- bin/commands/patch/review/builder.rs | 45 +++++++++++++++++++++------- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/bin/commands/patch/review.rs b/bin/commands/patch/review.rs index cedb6383..7981b952 100644 --- a/bin/commands/patch/review.rs +++ b/bin/commands/patch/review.rs @@ -280,6 +280,8 @@ impl<'a> App<'a> { None => file.insert(FileReviewBuilder::new(item.inner.hunk())), }; + log::info!("Accepting hunk ({:?})", item.inner.hunk()); + let diff = file.item_diff(item.inner.hunk())?; brain.accept(diff, repo.raw())?; } @@ -309,7 +311,11 @@ impl<'a> App<'a> { let rejected_hunks = Hunks::new(DiffUtil::new(&repo).rejected_diffs(&brain, &self.revision)?); - for item in items { + log::info!("Reloaded hunk states.."); + log::info!("Rejected hunks: {:?}", rejected_hunks); + log::info!("Requested to reload hunks: {:?}", items); + + for item in &mut *items { let state = if rejected_hunks.contains(item.inner.hunk()) { HunkState::Rejected } else { @@ -318,6 +324,8 @@ impl<'a> App<'a> { *item.inner.state_mut() = state; } + log::info!("Reloaded hunks: {:?}", items); + Ok(()) } @@ -572,7 +580,7 @@ impl<'a> store::Update> for App<'a> { } Message::Accept => { match self.accept_current_hunk() { - Ok(()) => log::info!("Accepted hunk."), + Ok(()) => log::info!("Hunk accepted."), Err(err) => log::info!("An error occured while accepting hunk: {}", err), } let _ = self.reload_states(); diff --git a/bin/commands/patch/review/builder.rs b/bin/commands/patch/review/builder.rs index c49bb7fe..664b9c28 100644 --- a/bin/commands/patch/review/builder.rs +++ b/bin/commands/patch/review/builder.rs @@ -30,7 +30,7 @@ use radicle_cli::terminal as term; use crate::git::HunkDiff; /// Queue of items (usually hunks) left to review. -#[derive(Clone, Default)] +#[derive(Clone, Default, Debug)] pub struct Hunks { hunks: Vec, } @@ -153,7 +153,39 @@ impl Hunks { self.hunks.push(item); } - // pub fn contains(&self, ) + // pub fn contains(&self, hunk: &HunkDiff) -> bool { + // match hunk { + // HunkDiff::Modified { + // path: _, + // header: _, + // old: _, + // new: _, + // hunk, + // _stats, + // } => { + // let mut contains = false; + // let other = hunk.clone(); + + // for rejected in &self.hunks { + // match rejected { + // HunkDiff::Modified { + // path, + // header, + // old, + // new, + // hunk, + // _stats, + // } => { + // contains = true; + // } + // _ => contains = other == rejected.hunk().cloned(), + // } + // } + // contains + // } + // _ => self.hunks.contains(hunk), + // } + // } } impl std::ops::Deref for Hunks { @@ -439,15 +471,6 @@ impl<'a> ReviewBuilder<'a> { let diff = DiffUtil::new(self.repo).all_diffs(revision)?; Ok(Hunks::new(diff)) } - - // pub fn rejected_hunks( - // &self, - // brain: &'a Brain<'a>, - // revision: &Revision, - // ) -> anyhow::Result { - // let diff = DiffUtil::new(self.repo).rejected_diffs(brain, revision)?; - // Ok(Hunks::new(diff)) - // } } #[derive(Debug, PartialEq, Eq)]