mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-03 18:30:41 +08:00
lib/bin: Fix clippy warnings
This commit is contained in:
+26
-27
@@ -23,6 +23,7 @@ pub mod issue;
|
||||
pub mod patch;
|
||||
|
||||
pub type IndexedHunkItem = (usize, crate::cob::HunkItem, HunkState);
|
||||
pub type FilePaths<'a> = (Option<(&'a Path, Oid)>, Option<(&'a Path, Oid)>);
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn parse_labels(input: String) -> Result<Vec<Label>> {
|
||||
@@ -102,21 +103,21 @@ pub enum HunkState {
|
||||
/// Files are usually split into multiple review items.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum HunkItem {
|
||||
FileAdded {
|
||||
Added {
|
||||
path: PathBuf,
|
||||
header: FileHeader,
|
||||
new: DiffFile,
|
||||
hunk: Option<Hunk<Modification>>,
|
||||
_stats: Option<FileStats>,
|
||||
},
|
||||
FileDeleted {
|
||||
Deleted {
|
||||
path: PathBuf,
|
||||
header: FileHeader,
|
||||
old: DiffFile,
|
||||
hunk: Option<Hunk<Modification>>,
|
||||
_stats: Option<FileStats>,
|
||||
},
|
||||
FileModified {
|
||||
Modified {
|
||||
path: PathBuf,
|
||||
header: FileHeader,
|
||||
old: DiffFile,
|
||||
@@ -124,20 +125,20 @@ pub enum HunkItem {
|
||||
hunk: Option<Hunk<Modification>>,
|
||||
_stats: Option<FileStats>,
|
||||
},
|
||||
FileMoved {
|
||||
Moved {
|
||||
moved: Moved,
|
||||
},
|
||||
FileCopied {
|
||||
Copied {
|
||||
copied: Copied,
|
||||
},
|
||||
FileEofChanged {
|
||||
EofChanged {
|
||||
path: PathBuf,
|
||||
header: FileHeader,
|
||||
old: DiffFile,
|
||||
new: DiffFile,
|
||||
_eof: EofNewLine,
|
||||
},
|
||||
FileModeChanged {
|
||||
ModeChanged {
|
||||
path: PathBuf,
|
||||
header: FileHeader,
|
||||
old: DiffFile,
|
||||
@@ -148,28 +149,28 @@ pub enum HunkItem {
|
||||
impl HunkItem {
|
||||
pub fn hunk(&self) -> Option<&Hunk<Modification>> {
|
||||
match self {
|
||||
Self::FileAdded { hunk, .. } => hunk.as_ref(),
|
||||
Self::FileDeleted { hunk, .. } => hunk.as_ref(),
|
||||
Self::FileModified { hunk, .. } => hunk.as_ref(),
|
||||
Self::Added { hunk, .. } => hunk.as_ref(),
|
||||
Self::Deleted { hunk, .. } => hunk.as_ref(),
|
||||
Self::Modified { hunk, .. } => hunk.as_ref(),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn file_header(&self) -> FileHeader {
|
||||
match self {
|
||||
Self::FileAdded { header, .. } => header.clone(),
|
||||
Self::FileDeleted { header, .. } => header.clone(),
|
||||
Self::FileMoved { moved } => FileHeader::Moved {
|
||||
Self::Added { header, .. } => header.clone(),
|
||||
Self::Deleted { header, .. } => header.clone(),
|
||||
Self::Moved { moved } => FileHeader::Moved {
|
||||
old_path: moved.old_path.clone(),
|
||||
new_path: moved.new_path.clone(),
|
||||
},
|
||||
Self::FileCopied { copied } => FileHeader::Copied {
|
||||
Self::Copied { copied } => FileHeader::Copied {
|
||||
old_path: copied.old_path.clone(),
|
||||
new_path: copied.new_path.clone(),
|
||||
},
|
||||
Self::FileModified { header, .. } => header.clone(),
|
||||
Self::FileEofChanged { header, .. } => header.clone(),
|
||||
Self::FileModeChanged { header, .. } => header.clone(),
|
||||
Self::Modified { header, .. } => header.clone(),
|
||||
Self::EofChanged { header, .. } => header.clone(),
|
||||
Self::ModeChanged { header, .. } => header.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,25 +178,23 @@ impl HunkItem {
|
||||
self.hunk().and_then(|h| HunkHeader::try_from(h).ok())
|
||||
}
|
||||
|
||||
pub fn paths(&self) -> (Option<(&Path, Oid)>, Option<(&Path, Oid)>) {
|
||||
pub fn paths(&self) -> FilePaths {
|
||||
match self {
|
||||
Self::FileAdded { path, new, .. } => (None, Some((path, new.oid))),
|
||||
Self::FileDeleted { path, old, .. } => (Some((path, old.oid)), None),
|
||||
Self::FileMoved { moved } => (
|
||||
Self::Added { path, new, .. } => (None, Some((path, new.oid))),
|
||||
Self::Deleted { path, old, .. } => (Some((path, old.oid)), None),
|
||||
Self::Moved { moved } => (
|
||||
Some((&moved.old_path, moved.old.oid)),
|
||||
Some((&moved.new_path, moved.new.oid)),
|
||||
),
|
||||
Self::FileCopied { copied } => (
|
||||
Self::Copied { copied } => (
|
||||
Some((&copied.old_path, copied.old.oid)),
|
||||
Some((&copied.new_path, copied.new.oid)),
|
||||
),
|
||||
Self::FileModified { path, old, new, .. } => {
|
||||
Self::Modified { path, old, new, .. } => (Some((path, old.oid)), Some((path, new.oid))),
|
||||
Self::EofChanged { path, old, new, .. } => {
|
||||
(Some((path, old.oid)), Some((path, new.oid)))
|
||||
}
|
||||
Self::FileEofChanged { path, old, new, .. } => {
|
||||
(Some((path, old.oid)), Some((path, new.oid)))
|
||||
}
|
||||
Self::FileModeChanged { path, old, new, .. } => {
|
||||
Self::ModeChanged { path, old, new, .. } => {
|
||||
(Some((path, old.oid)), Some((path, new.oid)))
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -94,7 +94,7 @@ pub fn find_review<'a, G: Signer>(
|
||||
patch
|
||||
.reviews_of(revision.id())
|
||||
.find(|(_, review)| review.author().public_key() == signer.public_key())
|
||||
.map(|(id, review)| (id.clone(), review))
|
||||
.map(|(id, review)| (*id, review))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -239,7 +239,7 @@ pub async fn run(options: Options, ctx: impl terminal::Context) -> anyhow::Resul
|
||||
};
|
||||
|
||||
// Run TUI with patch review interface
|
||||
interface::review(opts.clone(), profile, rid, patch_id.into()).await?;
|
||||
interface::review(opts.clone(), profile, rid, patch_id).await?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,18 +300,18 @@ mod interface {
|
||||
let repo = profile.storage.repository(rid).unwrap();
|
||||
let signer = terminal::signer(&profile)?;
|
||||
|
||||
let patch = patch::find(&profile, &repo, &patch_id.into())?
|
||||
let patch = patch::find(&profile, &repo, &patch_id)?
|
||||
.ok_or_else(|| anyhow!("Patch `{patch_id}` not found"))?;
|
||||
|
||||
let (_, revision) = opts.revision_or_latest(&patch, &repo)?;
|
||||
|
||||
let brain = Brain::load_or_new(patch_id, &revision, repo.raw(), &signer)?;
|
||||
let builder = ReviewBuilder::new(&repo).hunks(&brain, &revision)?;
|
||||
let brain = Brain::load_or_new(patch_id, revision, repo.raw(), &signer)?;
|
||||
let builder = ReviewBuilder::new(&repo).hunks(&brain, revision)?;
|
||||
let hunks = builder;
|
||||
|
||||
let drafts = DraftStore::new(&repo, *signer.public_key());
|
||||
let mut patches = cob::patch::Cache::no_cache(&drafts)?;
|
||||
let mut patch = patches.get_mut(&patch_id.into())?;
|
||||
let mut patch = patches.get_mut(&patch_id)?;
|
||||
|
||||
if let Some(review) = revision.review_by(signer.public_key()) {
|
||||
// Review already finalized. Do nothing and warn.
|
||||
@@ -360,7 +360,7 @@ mod interface {
|
||||
log::info!("Received selection from TUI: {:?}", selection);
|
||||
|
||||
if let Some(selection) = selection.as_ref() {
|
||||
match ReviewAction::try_from(selection.action)? {
|
||||
match selection.action {
|
||||
ReviewAction::Comment => {
|
||||
let hunk = selection
|
||||
.hunk
|
||||
|
||||
@@ -259,7 +259,7 @@ impl<'a> App<'a> {
|
||||
let states = base_files
|
||||
.iter()
|
||||
.map(|file| {
|
||||
if !queue_files.contains(&file) {
|
||||
if !queue_files.contains(file) {
|
||||
HunkState::Accepted
|
||||
} else {
|
||||
HunkState::Rejected
|
||||
@@ -358,7 +358,7 @@ impl<'a> App<'a> {
|
||||
Constraint::Length(8),
|
||||
),
|
||||
Column::new(
|
||||
span::default(&" ".to_string())
|
||||
span::default(" ")
|
||||
.into_left_aligned_line()
|
||||
.style(ui.theme().bar_on_black_style),
|
||||
Constraint::Fill(1),
|
||||
@@ -459,13 +459,13 @@ impl<'a> Show<Message> for App<'a> {
|
||||
frame,
|
||||
[
|
||||
Column::new(
|
||||
span::default(&" ".to_string())
|
||||
span::default(" ")
|
||||
.into_left_aligned_line()
|
||||
.style(ui.theme().bar_on_black_style),
|
||||
Constraint::Fill(1),
|
||||
),
|
||||
Column::new(
|
||||
span::default(&" ")
|
||||
span::default(" ")
|
||||
.into_right_aligned_line()
|
||||
.cyan()
|
||||
.dim()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
//! Review builder.
|
||||
//!
|
||||
//! This module enables a user to review a patch by interactively viewing and accepting diff hunks.
|
||||
//! The interaction and output is modeled around `git add -p`.
|
||||
//!
|
||||
//! To implement this behavior, we keep a hidden Git tree object that tracks the state of the
|
||||
//! repository including the accepted hunks. Thus, every time a diff hunk is accepted, it is applied
|
||||
@@ -62,14 +61,14 @@ impl ReviewQueue {
|
||||
|
||||
match file {
|
||||
FileDiff::Moved(moved) => {
|
||||
self.add_item(HunkItem::FileMoved { moved }, state);
|
||||
self.add_item(HunkItem::Moved { moved }, state);
|
||||
}
|
||||
FileDiff::Copied(copied) => {
|
||||
self.add_item(HunkItem::FileCopied { copied }, state);
|
||||
self.add_item(HunkItem::Copied { copied }, state);
|
||||
}
|
||||
FileDiff::Added(a) => {
|
||||
self.add_item(
|
||||
HunkItem::FileAdded {
|
||||
HunkItem::Added {
|
||||
path: a.path,
|
||||
header: header.clone(),
|
||||
new: a.new,
|
||||
@@ -89,7 +88,7 @@ impl ReviewQueue {
|
||||
}
|
||||
FileDiff::Deleted(d) => {
|
||||
self.add_item(
|
||||
HunkItem::FileDeleted {
|
||||
HunkItem::Deleted {
|
||||
path: d.path,
|
||||
header: header.clone(),
|
||||
old: d.old,
|
||||
@@ -110,7 +109,7 @@ impl ReviewQueue {
|
||||
FileDiff::Modified(m) => {
|
||||
if m.old.mode != m.new.mode {
|
||||
self.add_item(
|
||||
HunkItem::FileModeChanged {
|
||||
HunkItem::ModeChanged {
|
||||
path: m.path.clone(),
|
||||
header: header.clone(),
|
||||
old: m.old.clone(),
|
||||
@@ -125,7 +124,7 @@ impl ReviewQueue {
|
||||
}
|
||||
DiffContent::Binary => {
|
||||
self.add_item(
|
||||
HunkItem::FileModified {
|
||||
HunkItem::Modified {
|
||||
path: m.path.clone(),
|
||||
header: header.clone(),
|
||||
old: m.old.clone(),
|
||||
@@ -143,7 +142,7 @@ impl ReviewQueue {
|
||||
} => {
|
||||
for hunk in hunks {
|
||||
self.add_item(
|
||||
HunkItem::FileModified {
|
||||
HunkItem::Modified {
|
||||
path: m.path.clone(),
|
||||
header: header.clone(),
|
||||
old: m.old.clone(),
|
||||
@@ -156,7 +155,7 @@ impl ReviewQueue {
|
||||
}
|
||||
if let EofNewLine::OldMissing | EofNewLine::NewMissing = eof {
|
||||
self.add_item(
|
||||
HunkItem::FileEofChanged {
|
||||
HunkItem::EofChanged {
|
||||
path: m.path.clone(),
|
||||
header: header.clone(),
|
||||
old: m.old.clone(),
|
||||
@@ -319,17 +318,16 @@ impl<'a> Brain<'a> {
|
||||
) -> Result<Self, git::raw::Error> {
|
||||
let base = repo.find_commit((*revision.base()).into())?;
|
||||
|
||||
let brain =
|
||||
if let Ok(b) = Brain::load(patch.into(), signer.public_key(), base.clone(), repo) {
|
||||
log::info!(
|
||||
"Loaded existing brain {} for patch {}",
|
||||
b.head().id(),
|
||||
&patch
|
||||
);
|
||||
b
|
||||
} else {
|
||||
Brain::new(patch.into(), signer.public_key(), base, repo)?
|
||||
};
|
||||
let brain = if let Ok(b) = Brain::load(patch, signer.public_key(), base.clone(), repo) {
|
||||
log::info!(
|
||||
"Loaded existing brain {} for patch {}",
|
||||
b.head().id(),
|
||||
&patch
|
||||
);
|
||||
b
|
||||
} else {
|
||||
Brain::new(patch, signer.public_key(), base, repo)?
|
||||
};
|
||||
|
||||
Ok(brain)
|
||||
}
|
||||
@@ -417,7 +415,7 @@ impl<'a> DiffUtil<'a> {
|
||||
opts.patience(true).minimal(true).context_lines(3_u32);
|
||||
|
||||
let base_diff = self.diff(&base, &revision, repo, &mut opts)?;
|
||||
let queue_diff = self.diff(&brain.accepted(), &revision, repo, &mut opts)?;
|
||||
let queue_diff = self.diff(brain.accepted(), &revision, repo, &mut opts)?;
|
||||
|
||||
Ok((base_diff, queue_diff))
|
||||
}
|
||||
@@ -456,11 +454,7 @@ impl<'a> ReviewBuilder<'a> {
|
||||
}
|
||||
|
||||
/// Assemble the review for the given revision.
|
||||
pub fn hunks(
|
||||
&self,
|
||||
brain: &'a Brain<'a>,
|
||||
revision: &Revision,
|
||||
) -> anyhow::Result<ReviewQueue> {
|
||||
pub fn hunks(&self, brain: &'a Brain<'a>, revision: &Revision) -> anyhow::Result<ReviewQueue> {
|
||||
DiffUtil::new(self.repo)
|
||||
.base_queue(brain.clone(), revision)
|
||||
.map(|(base, queue)| Ok(ReviewQueue::new(base, queue)))?
|
||||
|
||||
+65
-90
@@ -1034,9 +1034,9 @@ impl ToTree<String> for CommentItem {
|
||||
|
||||
pub struct TermLine(terminal::Line);
|
||||
|
||||
impl<'a> Into<Line<'a>> for TermLine {
|
||||
fn into(self) -> Line<'a> {
|
||||
Line::raw(self.0.to_string())
|
||||
impl<'a> From<TermLine> for Line<'a> {
|
||||
fn from(val: TermLine) -> Self {
|
||||
Line::raw(val.0.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1057,13 +1057,10 @@ impl HunkComments {
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.comments
|
||||
.values()
|
||||
.into_iter()
|
||||
.fold(0_usize, |mut count, comments| {
|
||||
count += comments.len();
|
||||
count
|
||||
})
|
||||
self.comments.values().fold(0_usize, |mut count, comments| {
|
||||
count += comments.len();
|
||||
count
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1111,13 +1108,13 @@ impl<'a> From<(&Repository, &Review, &IndexedHunkItem)> for HunkItem<'a> {
|
||||
let hi = Highlighter::default();
|
||||
|
||||
let path = match &item.1 {
|
||||
crate::cob::HunkItem::FileAdded { path, .. } => path,
|
||||
crate::cob::HunkItem::FileModified { path, .. } => path,
|
||||
crate::cob::HunkItem::FileDeleted { path, .. } => path,
|
||||
crate::cob::HunkItem::FileCopied { copied } => &copied.new_path,
|
||||
crate::cob::HunkItem::FileMoved { moved } => &moved.new_path,
|
||||
crate::cob::HunkItem::FileModeChanged { path, .. } => path,
|
||||
crate::cob::HunkItem::FileEofChanged { path, .. } => path,
|
||||
crate::cob::HunkItem::Added { path, .. } => path,
|
||||
crate::cob::HunkItem::Modified { path, .. } => path,
|
||||
crate::cob::HunkItem::Deleted { path, .. } => path,
|
||||
crate::cob::HunkItem::Copied { copied } => &copied.new_path,
|
||||
crate::cob::HunkItem::Moved { moved } => &moved.new_path,
|
||||
crate::cob::HunkItem::ModeChanged { path, .. } => path,
|
||||
crate::cob::HunkItem::EofChanged { path, .. } => path,
|
||||
};
|
||||
|
||||
// TODO(erikli): Start with raw, non-highlighted lines and
|
||||
@@ -1129,7 +1126,7 @@ impl<'a> From<(&Repository, &Review, &IndexedHunkItem)> for HunkItem<'a> {
|
||||
.comments()
|
||||
.filter(|(_, comment)| comment.location().is_some())
|
||||
.filter(|(_, comment)| comment.location().unwrap().path == *path)
|
||||
.map(|(id, comment)| (id.clone(), comment.clone()))
|
||||
.map(|(id, comment)| (*id, comment.clone()))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
Self {
|
||||
@@ -1179,7 +1176,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
match &self.inner {
|
||||
(
|
||||
_,
|
||||
Item::FileAdded {
|
||||
Item::Added {
|
||||
path,
|
||||
header: _,
|
||||
new: _,
|
||||
@@ -1192,10 +1189,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
HunkState::Accepted => span::positive("✓"),
|
||||
HunkState::Rejected => span::secondary("?"),
|
||||
};
|
||||
let stats = hunk
|
||||
.as_ref()
|
||||
.map(|hunk| HunkStats::from(hunk))
|
||||
.unwrap_or_default();
|
||||
let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default();
|
||||
let stats_cell = [
|
||||
build_stats_spans(&DiffStats::Hunk(stats)),
|
||||
[span::default(" A ").bold().light_green().dim()].to_vec(),
|
||||
@@ -1210,7 +1204,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
Item::FileModified {
|
||||
Item::Modified {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1224,10 +1218,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
HunkState::Accepted => span::positive("✓"),
|
||||
HunkState::Rejected => span::secondary("?"),
|
||||
};
|
||||
let stats = hunk
|
||||
.as_ref()
|
||||
.map(|hunk| HunkStats::from(hunk))
|
||||
.unwrap_or_default();
|
||||
let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default();
|
||||
let stats_cell = [
|
||||
build_stats_spans(&DiffStats::Hunk(stats)),
|
||||
[span::default(" M ").bold().light_yellow().dim()].to_vec(),
|
||||
@@ -1242,7 +1233,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
Item::FileDeleted {
|
||||
Item::Deleted {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1255,10 +1246,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
HunkState::Accepted => span::positive("✓"),
|
||||
HunkState::Rejected => span::secondary("?"),
|
||||
};
|
||||
let stats = hunk
|
||||
.as_ref()
|
||||
.map(|hunk| HunkStats::from(hunk))
|
||||
.unwrap_or_default();
|
||||
let stats = hunk.as_ref().map(HunkStats::from).unwrap_or_default();
|
||||
let stats_cell = [
|
||||
build_stats_spans(&DiffStats::Hunk(stats)),
|
||||
[span::default(" D ").bold().light_red().dim()].to_vec(),
|
||||
@@ -1271,16 +1259,12 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
Line::from(stats_cell).right_aligned().into(),
|
||||
]
|
||||
}
|
||||
(_, Item::FileCopied { copied }, state) => {
|
||||
(_, Item::Copied { copied }, state) => {
|
||||
let state = match state {
|
||||
HunkState::Accepted => span::positive("✓"),
|
||||
HunkState::Rejected => span::secondary("?"),
|
||||
};
|
||||
let stats = copied
|
||||
.diff
|
||||
.stats()
|
||||
.map(|stats| stats.clone())
|
||||
.unwrap_or_default();
|
||||
let stats = copied.diff.stats().copied().unwrap_or_default();
|
||||
let stats_cell = [
|
||||
build_stats_spans(&DiffStats::File(stats)),
|
||||
[span::default(" CP ").bold().light_blue().dim()].to_vec(),
|
||||
@@ -1293,16 +1277,12 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
Line::from(stats_cell).right_aligned().into(),
|
||||
]
|
||||
}
|
||||
(_, Item::FileMoved { moved }, state) => {
|
||||
(_, Item::Moved { moved }, state) => {
|
||||
let state = match state {
|
||||
HunkState::Accepted => span::positive("✓"),
|
||||
HunkState::Rejected => span::secondary("?"),
|
||||
};
|
||||
let stats = moved
|
||||
.diff
|
||||
.stats()
|
||||
.map(|stats| stats.clone())
|
||||
.unwrap_or_default();
|
||||
let stats = moved.diff.stats().copied().unwrap_or_default();
|
||||
let stats_cell = [
|
||||
build_stats_spans(&DiffStats::File(stats)),
|
||||
[span::default(" MV ").bold().light_blue().dim()].to_vec(),
|
||||
@@ -1317,7 +1297,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
Item::FileEofChanged {
|
||||
Item::EofChanged {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1342,7 +1322,7 @@ impl<'a> ToRow<3> for HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
Item::FileModeChanged {
|
||||
Item::ModeChanged {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1372,8 +1352,8 @@ impl<'a> HunkItem<'a> {
|
||||
pub fn pretty_path(path: &Path, crossed_out: bool) -> Line<'a> {
|
||||
let file = path.file_name().unwrap_or_default();
|
||||
let path = if path.iter().count() > 1 {
|
||||
path.into_iter()
|
||||
.take(path.into_iter().count() - 1)
|
||||
path.iter()
|
||||
.take(path.iter().count() - 1)
|
||||
.map(|component| component.to_string_lossy().to_string())
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
@@ -1383,18 +1363,18 @@ impl<'a> HunkItem<'a> {
|
||||
let line = Line::from(
|
||||
[
|
||||
if crossed_out {
|
||||
span::default(&file.to_string_lossy().to_string()).crossed_out()
|
||||
span::default(file.to_string_lossy().as_ref()).crossed_out()
|
||||
} else {
|
||||
span::default(&file.to_string_lossy().to_string())
|
||||
span::default(file.to_string_lossy().as_ref())
|
||||
},
|
||||
span::default(" "),
|
||||
span::default(&format!("{}", path.join(&String::from("/"))))
|
||||
span::default(&path.join(&String::from("/")).to_string())
|
||||
.dark_gray()
|
||||
.dim(),
|
||||
]
|
||||
.to_vec(),
|
||||
);
|
||||
line.into()
|
||||
line
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1416,7 +1396,7 @@ impl<'a> HunkItem<'a> {
|
||||
match &self.inner {
|
||||
(
|
||||
_,
|
||||
crate::cob::HunkItem::FileAdded {
|
||||
crate::cob::HunkItem::Added {
|
||||
path,
|
||||
header: _,
|
||||
new: _,
|
||||
@@ -1447,7 +1427,7 @@ impl<'a> HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
crate::cob::HunkItem::FileModified {
|
||||
crate::cob::HunkItem::Modified {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1479,7 +1459,7 @@ impl<'a> HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
crate::cob::HunkItem::FileDeleted {
|
||||
crate::cob::HunkItem::Deleted {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1508,7 +1488,7 @@ impl<'a> HunkItem<'a> {
|
||||
|
||||
header.to_vec()
|
||||
}
|
||||
(_, crate::cob::HunkItem::FileCopied { copied }, _) => {
|
||||
(_, crate::cob::HunkItem::Copied { copied }, _) => {
|
||||
let path = Line::from(
|
||||
[
|
||||
HunkItem::pretty_path(&copied.old_path, false).spans,
|
||||
@@ -1533,7 +1513,7 @@ impl<'a> HunkItem<'a> {
|
||||
|
||||
header.to_vec()
|
||||
}
|
||||
(_, crate::cob::HunkItem::FileMoved { moved }, _) => {
|
||||
(_, crate::cob::HunkItem::Moved { moved }, _) => {
|
||||
let path = Line::from(
|
||||
[
|
||||
HunkItem::pretty_path(&moved.old_path, false).spans,
|
||||
@@ -1560,7 +1540,7 @@ impl<'a> HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
crate::cob::HunkItem::FileEofChanged {
|
||||
crate::cob::HunkItem::EofChanged {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1569,7 +1549,7 @@ impl<'a> HunkItem<'a> {
|
||||
},
|
||||
_,
|
||||
) => {
|
||||
let path = HunkItem::pretty_path(&path, false);
|
||||
let path = HunkItem::pretty_path(path, false);
|
||||
let header = [
|
||||
Column::new("", Constraint::Length(0)),
|
||||
Column::new(path.clone(), Constraint::Length(path.width() as u16)),
|
||||
@@ -1586,7 +1566,7 @@ impl<'a> HunkItem<'a> {
|
||||
}
|
||||
(
|
||||
_,
|
||||
crate::cob::HunkItem::FileModeChanged {
|
||||
crate::cob::HunkItem::ModeChanged {
|
||||
path,
|
||||
header: _,
|
||||
old: _,
|
||||
@@ -1594,7 +1574,7 @@ impl<'a> HunkItem<'a> {
|
||||
},
|
||||
_,
|
||||
) => {
|
||||
let path = HunkItem::pretty_path(&path, false);
|
||||
let path = HunkItem::pretty_path(path, false);
|
||||
let header = [
|
||||
Column::new("", Constraint::Length(0)),
|
||||
Column::new(path.clone(), Constraint::Length(path.width() as u16)),
|
||||
@@ -1616,9 +1596,9 @@ impl<'a> HunkItem<'a> {
|
||||
use crate::cob::HunkItem;
|
||||
|
||||
match &self.inner {
|
||||
(_, HunkItem::FileAdded { hunk, .. }, _)
|
||||
| (_, HunkItem::FileModified { hunk, .. }, _)
|
||||
| (_, HunkItem::FileDeleted { hunk, .. }, _) => {
|
||||
(_, HunkItem::Added { hunk, .. }, _)
|
||||
| (_, HunkItem::Modified { hunk, .. }, _)
|
||||
| (_, HunkItem::Deleted { hunk, .. }, _) => {
|
||||
let mut lines = hunk
|
||||
.as_ref()
|
||||
.map(|hunk| Text::from(hunk.to_text(&self.lines)));
|
||||
@@ -1627,7 +1607,7 @@ impl<'a> HunkItem<'a> {
|
||||
.map(|hunk| hunk.new.start as usize)
|
||||
.unwrap_or_default();
|
||||
|
||||
lines = lines.and_then(|lines| {
|
||||
lines = lines.map(|lines| {
|
||||
let mut mixins = HashMap::new();
|
||||
|
||||
let divider = span::default(&"─".to_string().repeat(500)).gray().dim();
|
||||
@@ -1658,7 +1638,6 @@ impl<'a> HunkItem<'a> {
|
||||
.1
|
||||
.body()
|
||||
.lines()
|
||||
.into_iter()
|
||||
.map(|line| {
|
||||
Line::from([span::default(line).gray()].to_vec())
|
||||
})
|
||||
@@ -1684,7 +1663,7 @@ impl<'a> HunkItem<'a> {
|
||||
}
|
||||
let merged = LineMerger::merge(lines.lines.clone(), mixins, start);
|
||||
|
||||
Some(Text::from(merged))
|
||||
Text::from(merged)
|
||||
});
|
||||
|
||||
lines
|
||||
@@ -1713,22 +1692,20 @@ impl<'a> Blobs<(PathBuf, Blob)> {
|
||||
if let Some((path, Blob::Plain(content))) = &self.old {
|
||||
blobs.old = hi
|
||||
.highlight(path, content)
|
||||
.and_then(|hi| {
|
||||
Ok(hi
|
||||
.into_iter()
|
||||
.map(|hi| {
|
||||
hi.into_iter()
|
||||
.map(|line| Line::raw(line.to_string()))
|
||||
.collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
if let Some((path, Blob::Plain(content))) = &self.new {
|
||||
blobs.new = hi
|
||||
.highlight(path, content)
|
||||
.and_then(|hi| {
|
||||
Ok(hi
|
||||
.into_iter()
|
||||
.map(|hi| {
|
||||
hi.into_iter()
|
||||
.map(|line| Line::raw(line.to_string()))
|
||||
.collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
@@ -1739,23 +1716,23 @@ impl<'a> Blobs<(PathBuf, Blob)> {
|
||||
let mut blobs = Blobs::default();
|
||||
if let Some((_, Blob::Plain(content))) = &self.old {
|
||||
blobs.old = std::str::from_utf8(content)
|
||||
.and_then(|lines| {
|
||||
Ok(lines
|
||||
.map(|lines| {
|
||||
lines
|
||||
.lines()
|
||||
.map(terminal::Line::new)
|
||||
.map(|line| Line::raw(line.to_string()))
|
||||
.collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
if let Some((_, Blob::Plain(content))) = &self.new {
|
||||
blobs.new = std::str::from_utf8(content)
|
||||
.and_then(|lines| {
|
||||
Ok(lines
|
||||
.map(|lines| {
|
||||
lines
|
||||
.lines()
|
||||
.map(terminal::Line::new)
|
||||
.map(|line| Line::raw(line.to_string()))
|
||||
.collect::<Vec<_>>())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.ok();
|
||||
}
|
||||
@@ -1799,15 +1776,13 @@ impl<'a> From<Line<'a>> for HighlightedLine<'a> {
|
||||
fn from(highlighted: Line<'a>) -> Self {
|
||||
let converted = highlighted.to_string().into_text().unwrap().lines;
|
||||
|
||||
Self {
|
||||
0: converted.first().cloned().unwrap_or_default(),
|
||||
}
|
||||
Self(converted.first().cloned().unwrap_or_default())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Into<Line<'a>> for HighlightedLine<'a> {
|
||||
fn into(self) -> Line<'a> {
|
||||
self.0
|
||||
impl<'a> From<HighlightedLine<'a>> for Line<'a> {
|
||||
fn from(val: HighlightedLine<'a>) -> Self {
|
||||
val.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1835,7 +1810,7 @@ impl<'a> ToText<'a> for HunkHeader {
|
||||
))
|
||||
.gray(),
|
||||
span::default(" "),
|
||||
span::default(&String::from_utf8_lossy(&self.text).to_string()),
|
||||
span::default(String::from_utf8_lossy(&self.text).as_ref()),
|
||||
]
|
||||
.to_vec(),
|
||||
)
|
||||
@@ -1903,7 +1878,7 @@ impl<'a> ToText<'a> for Hunk<Modification> {
|
||||
.gray()
|
||||
.dim(),
|
||||
span::default(" "),
|
||||
span::default(&String::from_utf8_lossy(&header.text).to_string())
|
||||
span::default(String::from_utf8_lossy(&header.text).as_ref())
|
||||
.gray()
|
||||
.dim(),
|
||||
]
|
||||
|
||||
@@ -68,10 +68,8 @@ impl Update<Message> for App {
|
||||
.selector
|
||||
.selected()
|
||||
.and_then(|selected| self.items.get(selected))
|
||||
.and_then(|item| {
|
||||
Some(Exit {
|
||||
value: Some(item.id),
|
||||
})
|
||||
.map(|item| Exit {
|
||||
value: Some(item.id),
|
||||
}),
|
||||
Message::Quit => Some(Exit { value: None }),
|
||||
}
|
||||
|
||||
+1
-1
@@ -798,7 +798,7 @@ impl<'a> Widget for TextView<'a> {
|
||||
|
||||
frame.render_stateful_widget(scroller, scroller_area, &mut scroller_state);
|
||||
frame.render_widget(
|
||||
Paragraph::new(self.text.clone()).scroll((self.cursor.x as u16, self.cursor.y as u16)),
|
||||
Paragraph::new(self.text.clone()).scroll((self.cursor.x, self.cursor.y)),
|
||||
text_area,
|
||||
);
|
||||
|
||||
|
||||
+5
-5
@@ -51,10 +51,10 @@ fn another_function() {
|
||||
Is this needed?
|
||||
──────────────────────────────────────"#
|
||||
.to_string();
|
||||
let comment = comment.lines().into_iter().collect::<Vec<_>>();
|
||||
let comment = comment.lines().collect::<Vec<_>>();
|
||||
|
||||
let merged = LineMerger::merge(
|
||||
diff.lines().into_iter().collect(),
|
||||
diff.lines().collect(),
|
||||
HashMap::from([(3_usize, vec![comment])]),
|
||||
1,
|
||||
);
|
||||
@@ -98,10 +98,10 @@ fn another_function() {
|
||||
Is this needed?
|
||||
──────────────────────────────────────"#
|
||||
.to_string();
|
||||
let comment = comment.lines().into_iter().collect::<Vec<_>>();
|
||||
let comment = comment.lines().collect::<Vec<_>>();
|
||||
|
||||
let merged = LineMerger::merge(
|
||||
diff.lines().into_iter().collect(),
|
||||
diff.lines().collect(),
|
||||
HashMap::from([(104_usize, vec![comment])]),
|
||||
100,
|
||||
);
|
||||
@@ -132,7 +132,7 @@ fn another_function() {
|
||||
let mut actual = String::new();
|
||||
for (idx, line) in lines.iter().enumerate() {
|
||||
if idx == lines.len() - 1 {
|
||||
actual.push_str(&format!("{}", line));
|
||||
actual.push_str(&line.to_string());
|
||||
} else {
|
||||
actual.push_str(&format!("{}\n", line));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user