refactor diff
[?]
May 1, 2025, 7:36 AM
QMAUTRB6R5R7ABWT2JIDEA7LMILZOS3PGPZIF3YUFKRVLW6HGKTQCDependencies
- [2]
6YZAVBWUInitial commit - [3]
WT3GA27Padd cursor with selection - [4]
4WO3ZJM2show untracked files' contents - [5]
PTFDJ567add untracked files encoding - [6]
AMPZ2BXKshow changed files diffs (only Edit atm) - [7]
V55EAIWQadd src file LRU cache - [8]
NRCUG4R2load changed files src when selected - [9]
Y5ATDI2Hconvert changed file diffs and load src only if any needs it - [10]
HOJZI52Yrename flowers_ui to inflorescence - [11]
MJDGPSHGWIP contents diff - [12]
ZVI4AWERwoot contents_diff - [13]
EC3TVL4Xadd untracked files - [14]
SWWE2R6Mdisplay basic repo stuff - [15]
IQDCHWCPload a pijul repo - [16]
YBJRDOTCmake all repo actions async - [17]
BJXUYQ2Yshow untracked file contents in read-only text editor - [18]
3GZPRZXCs/-/_ in crate paths - [19]
DVKSPF7Rtrack selected file path together with an index
Change contents
- edit in crates/inflorescence/src/main.rs at line 1
mod contents_diff; - edit in crates/inflorescence/src/main.rs at line 2
mod diff; - replacement in crates/inflorescence/src/main.rs at line 154
Loaded(contents_diff::File),Loaded(diff::File), - replacement in crates/inflorescence/src/main.rs at line 172
contents_diff::File::Decoded(contents_diff::DecodedFile {diff::File::Decoded(diff::DecodedFile { - replacement in crates/inflorescence/src/main.rs at line 174
contents_diff::Combined {diff::Combined { - replacement in crates/inflorescence/src/main.rs at line 184
contents_diff::File::Undecodable(contents_diff::UndecodableFile {diffs_with_contents,diffs_without_contents,},) => {diff::File::Undecodable(diff::UndecodableFile {diffs_with_contents,diffs_without_contents,}) => { - replacement in crates/inflorescence/src/main.rs at line 239
action: contents_diff::Msg,action: diff::Action, - replacement in crates/inflorescence/src/main.rs at line 261
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 284
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 523
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 546
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 737
contents_diff::FileContent::Decoded(decoded)diff::FileContent::Decoded(decoded) - replacement in crates/inflorescence/src/main.rs at line 739
None => contents_diff::FileContent::UnknownEncoding,None => diff::FileContent::UnknownEncoding, - replacement in crates/inflorescence/src/main.rs at line 743
let file_diff: contents_diff::File =contents_diff::init_file(file_content, None);let file_diff: diff::File =diff::init_file(file_content, None); - replacement in crates/inflorescence/src/main.rs at line 755
let file_diff: contents_diff::File =contents_diff::init_file(file_content,changed_file,);let file_diff: diff::File =diff::init_file(file_content, changed_file); - replacement in crates/inflorescence/src/main.rs at line 776
contents_diff::update(diffs, action);diff::update(diffs, action); - replacement in crates/inflorescence/src/main.rs at line 782
contents_diff::update(diffs, action);diff::update(diffs, action); - replacement in crates/inflorescence/src/main.rs at line 869
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 901
diffs: contents_diff::State::default(),diffs: diff::State::default(), - replacement in crates/inflorescence/src/main.rs at line 998
contents_diff::diffs_from_repo_diffs(changed_file);diff::from_repo_changed_file(changed_file); - replacement in crates/inflorescence/src/main.rs at line 1079
contents_diff::view(selection_state, file).map(move |msg| Message::FileDiffsContentsAction {diff::view(selection_state, file).map(move |msg| {Message::FileDiffsContentsAction { - replacement in crates/inflorescence/src/main.rs at line 1083
},)}}) - replacement in crates/inflorescence/src/main.rs at line 1104
contents_diff::view(selection_state, file).map(move |msg| Message::FileDiffsContentsAction {diff::view(selection_state, file).map(move |msg| {Message::FileDiffsContentsAction { - replacement in crates/inflorescence/src/main.rs at line 1108
},)}}) - file move: contents_diff.rs → diff.rs
- edit in crates/inflorescence/src/diff.rs at line 12
#[allow(dead_code)] // TODO rm once `view_decoded` is fully implemented#[derive(Debug, Default)]pub struct State {pub selected_sections: Vec<usize>,pub expanded_unchanged_sections: Vec<usize>,pub collapsed_changed_sections: Vec<usize>,}#[derive(Debug, Clone)]pub enum Action {}pub fn update(_state: &mut State, _action: Action) {}pub fn view<'a>(state: &'a State, file: &'a File) -> Element<'a, Action> {match file {File::Decoded(decoded_file) => view_decoded(state, decoded_file),File::Undecodable(undecodable_file) => {view_undecodable(state, undecodable_file)}}}/// [`File`] is not part of [`State`] so it can be stored separately (i.e. in a/// cache, where it's immutable once set, unlike [`State`] which can change with [`Action`]s) - edit in crates/inflorescence/src/diff.rs at line 64
UnknownEncoding,}#[derive(Debug)]pub enum DiffWithContents {Add,Edit {line: usize,deleted: bool,contents: String,},Replacement {line: usize,/// Deleted linechange_contents: String,/// Added linesreplacement_contents: String,},Del,Undel,}#[allow(dead_code)] // TODO rm once `view_undecodable` is implemented#[derive(Debug)]pub enum DiffWithoutContents {// _________________________________________________________________________// Cases that never have contents:Move,SolveNameConflict,UnsolveNameConflict,SolveOrderConflict,UnsolveOrderConflict,ResurrectZombines,AddRoot,DelRoot,// _________________________________________________________________________// Cases that normally have contents, but in these cases the contents are// not decodable:Edit {line: usize,deleted: bool,contents: UndecodableContents,},Replacement {line: usize,/// Deleted linechange_contents: UndecodableContents,/// Added linesreplacement_contents: UndecodableContents,},}#[allow(dead_code)] // TODO rm once `view_undecodable` is implemented#[derive(Debug)]pub enum UndecodableContents {/// Short byte sequence of unknown encoding encoded with base64 for/// display. Must be shorter than [`crate::repo::MAX_LEN_BASE64_DISPLAY`]ShortBase64(String), - edit in crates/inflorescence/src/diff.rs at line 123
}#[derive(Debug)]pub enum Section {Unchanged(Lines),/// `deleted` and `added` are together because for/// `ChangedFileDiffWithContents::Replacement` they begin on the same line/// numberChanged {deleted: Lines,added: Lines,}, - edit in crates/inflorescence/src/diff.rs at line 136
/// INVARIANT: There must be no new-lines in any of the strings, the source/// string must be split on those.pub type Lines = Vec<String>; - replacement in crates/inflorescence/src/diff.rs at line 146
.map(diffs_from_repo_diffs).map(from_repo_changed_file) - replacement in crates/inflorescence/src/diff.rs at line 165
pub fn combine_decoded_contents(pub fn from_repo_changed_file(changed_file: &repo::ChangedFile,) -> (Vec<DiffWithContents>, Vec<DiffWithoutContents>) {changed_file.iter().fold((vec![], vec![]), |(mut with, mut without), diff| {match diff {repo::ChangedFileDiff::Move => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::Del => {with.push(DiffWithContents::Del);},repo::ChangedFileDiff::Undel => {with.push(DiffWithContents::Undel);},repo::ChangedFileDiff::Add => {with.push(DiffWithContents::Add);},repo::ChangedFileDiff::SolveNameConflict => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::UnsolveNameConflict => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::Edit { line, deleted, contents } => match contents{repo::Contents::Decoded(lines) => {with.push(DiffWithContents::Edit {line: *line,deleted: *deleted,contents: lines.clone(),});},repo::Contents::ShortBase64(short) => {without.push(DiffWithoutContents::Edit {line: *line,deleted: *deleted,contents: UndecodableContents::ShortBase64(short.clone()),});},repo::Contents::UnknownEncoding(_bytes) => {without.push(DiffWithoutContents::Edit {line: *line,deleted: *deleted,contents: UndecodableContents::UnknownEncoding,});},},repo::ChangedFileDiff::Replacement { line, change_contents, replacement_contents } => match (change_contents, replacement_contents) {(repo::Contents::Decoded(change), repo::Contents::Decoded(replacement)) => {with.push(DiffWithContents::Replacement {line: *line,change_contents: change.clone(),replacement_contents: replacement.clone(),});},(repo::Contents::ShortBase64(change), repo::Contents::ShortBase64(replacement)) => {without.push(DiffWithoutContents::Replacement {line: *line,change_contents: UndecodableContents::ShortBase64(change.clone()),replacement_contents: UndecodableContents::ShortBase64(replacement.clone()),});},(repo::Contents::UnknownEncoding(_change), repo::Contents::UnknownEncoding(_replacement)) => {without.push(DiffWithoutContents::Replacement {line: *line,change_contents: UndecodableContents::UnknownEncoding,replacement_contents: UndecodableContents::UnknownEncoding,});},_ => {unimplemented!("The change and replacement have different encoding!");}},repo::ChangedFileDiff::SolveOrderConflict => {without.push(DiffWithoutContents::SolveOrderConflict);},repo::ChangedFileDiff::UnsolveOrderConflict => {without.push(DiffWithoutContents::UnsolveOrderConflict);},repo::ChangedFileDiff::ResurrectZombines => {without.push(DiffWithoutContents::ResurrectZombines);},repo::ChangedFileDiff::AddRoot => {without.push(DiffWithoutContents::AddRoot);},repo::ChangedFileDiff::DelRoot => {without.push(DiffWithoutContents::DelRoot);},};(with, without)})}fn combine_decoded_contents( - edit in crates/inflorescence/src/diff.rs at line 364
}pub fn diffs_from_repo_diffs(changed_file: &repo::ChangedFile,) -> (Vec<DiffWithContents>, Vec<DiffWithoutContents>) {changed_file.iter().fold((vec![], vec![]), |(mut with, mut without), diff| {match diff {repo::ChangedFileDiff::Move => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::Del => {with.push(DiffWithContents::Del);},repo::ChangedFileDiff::Undel => {with.push(DiffWithContents::Undel);},repo::ChangedFileDiff::Add => {with.push(DiffWithContents::Add);},repo::ChangedFileDiff::SolveNameConflict => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::UnsolveNameConflict => {without.push(DiffWithoutContents::Move);},repo::ChangedFileDiff::Edit { line, deleted, contents } => match contents{repo::Contents::Decoded(lines) => {with.push(DiffWithContents::Edit {line: *line,deleted: *deleted,contents: lines.clone(),});},repo::Contents::ShortBase64(short) => {without.push(DiffWithoutContents::Edit {line: *line,deleted: *deleted,contents: UndecodableContents::ShortBase64(short.clone()),});},repo::Contents::UnknownEncoding(_bytes) => {without.push(DiffWithoutContents::Edit {line: *line,deleted: *deleted,contents: UndecodableContents::UnknownEncoding,});},},repo::ChangedFileDiff::Replacement { line, change_contents, replacement_contents } => match (change_contents, replacement_contents) {(repo::Contents::Decoded(change), repo::Contents::Decoded(replacement)) => {with.push(DiffWithContents::Replacement {line: *line,change_contents: change.clone(),replacement_contents: replacement.clone(),});},(repo::Contents::ShortBase64(change), repo::Contents::ShortBase64(replacement)) => {without.push(DiffWithoutContents::Replacement {line: *line,change_contents: UndecodableContents::ShortBase64(change.clone()),replacement_contents: UndecodableContents::ShortBase64(replacement.clone()),});},(repo::Contents::UnknownEncoding(_change), repo::Contents::UnknownEncoding(_replacement)) => {without.push(DiffWithoutContents::Replacement {line: *line,change_contents: UndecodableContents::UnknownEncoding,replacement_contents: UndecodableContents::UnknownEncoding,});},_ => {unimplemented!("The change and replacement have different encoding!");}},repo::ChangedFileDiff::SolveOrderConflict => {without.push(DiffWithoutContents::SolveOrderConflict);},repo::ChangedFileDiff::UnsolveOrderConflict => {without.push(DiffWithoutContents::UnsolveOrderConflict);},repo::ChangedFileDiff::ResurrectZombines => {without.push(DiffWithoutContents::ResurrectZombines);},repo::ChangedFileDiff::AddRoot => {without.push(DiffWithoutContents::AddRoot);},repo::ChangedFileDiff::DelRoot => {without.push(DiffWithoutContents::DelRoot);},};(with, without)}) - edit in crates/inflorescence/src/diff.rs at line 366[12.25628]→[12.25628:27145](∅→∅),[12.27145]→[11.10247:10250](∅→∅),[11.10247]→[11.10247:10250](∅→∅),[11.10250]→[12.27146:27679](∅→∅)
#[derive(Debug)]pub enum DiffWithContents {Add,Edit {line: usize,deleted: bool,contents: String,},Replacement {line: usize,/// Deleted linechange_contents: String,/// Added linesreplacement_contents: String,},Del,Undel,}#[allow(dead_code)] // TODO rm once `view_undecodable` is implemented#[derive(Debug)]pub enum DiffWithoutContents {// _________________________________________________________________________// Cases that never have contents:Move,SolveNameConflict,UnsolveNameConflict,SolveOrderConflict,UnsolveOrderConflict,ResurrectZombines,AddRoot,DelRoot,// _________________________________________________________________________// Cases that normally have contents, but in these cases the contents are// not decodable:Edit {line: usize,deleted: bool,contents: UndecodableContents,},Replacement {line: usize,/// Deleted linechange_contents: UndecodableContents,/// Added linesreplacement_contents: UndecodableContents,},}#[allow(dead_code)] // TODO rm once `view_undecodable` is implemented#[derive(Debug)]pub enum UndecodableContents {/// Short byte sequence of unknown encoding encoded with base64 for/// display. Must be shorter than [`crate::repo::MAX_LEN_BASE64_DISPLAY`]ShortBase64(String),UnknownEncoding,}#[allow(dead_code)] // TODO rm once `view_decoded` is fully implemented#[derive(Debug, Default)]pub struct State {pub selected_sections: Vec<usize>,pub expanded_unchanged_sections: Vec<usize>,pub collapsed_changed_sections: Vec<usize>,}#[derive(Debug)]pub enum Section {Unchanged(Lines),/// `deleted` and `added` are together because for/// `ChangedFileDiffWithContents::Replacement` they begin on the same line/// numberChanged {deleted: Lines,added: Lines,},} - edit in crates/inflorescence/src/diff.rs at line 381[11.10601]→[11.10601:10752](∅→∅),[11.10752]→[12.27786:27810](∅→∅),[12.27810]→[11.10769:10786](∅→∅),[11.10769]→[11.10769:10786](∅→∅),[11.10786]→[12.27811:28136](∅→∅)
}}/// INVARIANT: There must be no new-lines in any of the strings, the source/// string must be split on those.pub type Lines = Vec<String>;#[derive(Debug, Clone)]pub enum Msg {}pub fn update(_state: &mut State, _msg: Msg) {}pub fn view<'a>(state: &'a State, file: &'a File) -> Element<'a, Msg> {match file {File::Decoded(decoded_file) => view_decoded(state, decoded_file),File::Undecodable(undecodable_file) => {view_undecodable(state, undecodable_file)} - replacement in crates/inflorescence/src/diff.rs at line 384
pub fn view_decoded<'a>(fn view_decoded<'a>( - replacement in crates/inflorescence/src/diff.rs at line 387
) -> Element<'a, Msg> {) -> Element<'a, Action> { - replacement in crates/inflorescence/src/diff.rs at line 452
pub fn view_undecodable<'a>(fn view_undecodable<'a>( - replacement in crates/inflorescence/src/diff.rs at line 455
) -> Element<'a, Msg> {) -> Element<'a, Action> { - replacement in crates/inflorescence/src/cursor.rs at line 1
use crate::contents_diff;use crate::diff; - replacement in crates/inflorescence/src/cursor.rs at line 13
diffs: contents_diff::State,diffs: diff::State, - replacement in crates/inflorescence/src/cursor.rs at line 18
diffs: contents_diff::State,diffs: diff::State,