Radish alpha
r
rad:z39mP9rQAaGmERfUMPULfPUi473tY
Radicle terminal user interface
Radicle
Git
bin(patch): Log more review debug output
Erik Kundt committed 1 year ago
commit 9743396d3d5324433e53c4d17c22fb72609323f2
parent 537e8be
2 files changed +44 -13
modified 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<Message<'a>> 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();
modified 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<HunkDiff>,
}
@@ -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<Hunks> {
-
    //     let diff = DiffUtil::new(self.repo).rejected_diffs(brain, revision)?;
-
    //     Ok(Hunks::new(diff))
-
    // }
}

#[derive(Debug, PartialEq, Eq)]