Showing the changes to git-diff (6 of 7 files). Show all
Unified · Split
| @@ -3,4 +3,4 @@ · 2 unmodified lines | ||
| 3 | 3 | #[deny(missing_docs)] |
| 4 | 4 | |
| 5 | 5 | /// |
| 6 | −pub mod visit; | |
| 6 | +pub mod tree; | |
| @@ -1,9 +1,9 @@ | ||
| 1 | 1 | use crate::{ |
| 2 | − visit, | |
| 3 | − visit::{changes::Error::Cancelled, record::Change, TreeInfo, TreeInfoPair}, | |
| 2 | + tree, | |
| 3 | + tree::{changes::Error::Cancelled, visit::Change, TreeInfo, TreeInfoPair}, | |
| 4 | 4 | }; |
| 5 | 5 | use git_hash::{oid, ObjectId}; |
| 6 | −use git_object::{immutable, tree}; | |
| 6 | +use git_object::immutable; | |
| 7 | 7 | use quick_error::quick_error; |
| 8 | 8 | use std::{borrow::BorrowMut, collections::VecDeque}; |
| 9 | 9 | |
| @@ -24,8 +24,8 @@ quick_error! { · 14 unmodified lines | ||
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | −impl<'a> visit::Changes<'a> { | |
| 28 | − /// Returns the changes that need to be applied to `self` to get `other`. | |
| 27 | +impl<'a> tree::Changes<'a> { | |
| 28 | + /// that need to be applied to `self` to get `other`. | |
| 29 | 29 | /// TODO: Talk about choices in error handling and why Option<T> is enough, as opposed to the usual Result<Option<T>> |
| 30 | 30 | /// Talk about progress (done via delegate if needed) |
| 31 | 31 | /// |
| @@ -51,8 +51,8 @@ impl<'a> visit::Changes<'a> { · 19 unmodified lines | ||
| 51 | 51 | ) -> Result<(), Error> |
| 52 | 52 | where |
| 53 | 53 | LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>, |
| 54 | − R: visit::Record, | |
| 55 | − StateMut: BorrowMut<visit::State<R::PathId>>, | |
| 54 | + R: tree::Visit, | |
| 55 | + StateMut: BorrowMut<tree::State<R::PathId>>, | |
| 56 | 56 | { |
| 57 | 57 | let state = state.borrow_mut(); |
| 58 | 58 | state.clear(); |
| @@ -111,14 +111,14 @@ impl<'a> visit::Changes<'a> { · 52 unmodified lines | ||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | −fn delete_entry_schedule_recursion<R: visit::Record>( | |
| 114 | +fn delete_entry_schedule_recursion<R: tree::Visit>( | |
| 115 | 115 | entry: immutable::tree::Entry<'_>, |
| 116 | 116 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 117 | 117 | delegate: &mut R, |
| 118 | 118 | ) -> Result<(), Error> { |
| 119 | 119 | delegate.push_path_component(entry.filename); |
| 120 | 120 | if delegate |
| 121 | − .record(Change::Deletion { | |
| 121 | + .visit(Change::Deletion { | |
| 122 | 122 | entry_mode: entry.mode, |
| 123 | 123 | oid: entry.oid.to_owned(), |
| 124 | 124 | }) |
| @@ -140,14 +140,14 @@ fn delete_entry_schedule_recursion<R: visit::Record>( · 15 unmodified lines | ||
| 140 | 140 | Ok(()) |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | −fn add_entry_schedule_recursion<R: visit::Record>( | |
| 143 | +fn add_entry_schedule_recursion<R: tree::Visit>( | |
| 144 | 144 | entry: immutable::tree::Entry<'_>, |
| 145 | 145 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 146 | 146 | delegate: &mut R, |
| 147 | 147 | ) -> Result<(), Error> { |
| 148 | 148 | delegate.push_path_component(entry.filename); |
| 149 | 149 | if delegate |
| 150 | − .record(Change::Addition { | |
| 150 | + .visit(Change::Addition { | |
| 151 | 151 | entry_mode: entry.mode, |
| 152 | 152 | oid: entry.oid.to_owned(), |
| 153 | 153 | }) |
| @@ -168,7 +168,7 @@ fn add_entry_schedule_recursion<R: visit::Record>( · 14 unmodified lines | ||
| 168 | 168 | } |
| 169 | 169 | Ok(()) |
| 170 | 170 | } |
| 171 | −fn catchup_rhs_with_lhs<R: visit::Record>( | |
| 171 | +fn catchup_rhs_with_lhs<R: tree::Visit>( | |
| 172 | 172 | rhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, |
| 173 | 173 | lhs: immutable::tree::Entry<'_>, |
| 174 | 174 | rhs: immutable::tree::Entry<'_>, |
| @@ -208,7 +208,7 @@ fn catchup_rhs_with_lhs<R: visit::Record>( · 33 unmodified lines | ||
| 208 | 208 | Ok(()) |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | −fn catchup_lhs_with_rhs<R: visit::Record>( | |
| 211 | +fn catchup_lhs_with_rhs<R: tree::Visit>( | |
| 212 | 212 | lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, |
| 213 | 213 | lhs: immutable::tree::Entry<'_>, |
| 214 | 214 | rhs: immutable::tree::Entry<'_>, |
| @@ -248,19 +248,19 @@ fn catchup_lhs_with_rhs<R: visit::Record>( · 33 unmodified lines | ||
| 248 | 248 | Ok(()) |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | −fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( | |
| 251 | +fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( | |
| 252 | 252 | lhs: immutable::tree::Entry<'_>, |
| 253 | 253 | rhs: immutable::tree::Entry<'_>, |
| 254 | 254 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 255 | 255 | delegate: &mut R, |
| 256 | 256 | ) -> Result<(), Error> { |
| 257 | − use tree::EntryMode::*; | |
| 257 | + use git_object::tree::EntryMode::*; | |
| 258 | 258 | match (lhs.mode, rhs.mode) { |
| 259 | 259 | (Tree, Tree) => { |
| 260 | 260 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 261 | 261 | if lhs.oid != rhs.oid |
| 262 | 262 | && delegate |
| 263 | − .record(Change::Modification { | |
| 263 | + .visit(Change::Modification { | |
| 264 | 264 | previous_entry_mode: lhs.mode, |
| 265 | 265 | previous_oid: lhs.oid.to_owned(), |
| 266 | 266 | entry_mode: rhs.mode, |
| @@ -284,7 +284,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 17 unmodified lines | ||
| 284 | 284 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { |
| 285 | 285 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 286 | 286 | if delegate |
| 287 | − .record(Change::Deletion { | |
| 287 | + .visit(Change::Deletion { | |
| 288 | 288 | entry_mode: lhs.mode, |
| 289 | 289 | oid: lhs.oid.to_owned(), |
| 290 | 290 | }) |
| @@ -293,7 +293,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 2 unmodified lines | ||
| 293 | 293 | return Err(Cancelled); |
| 294 | 294 | }; |
| 295 | 295 | if delegate |
| 296 | − .record(Change::Addition { | |
| 296 | + .visit(Change::Addition { | |
| 297 | 297 | entry_mode: rhs.mode, |
| 298 | 298 | oid: rhs.oid.to_owned(), |
| 299 | 299 | }) |
| @@ -312,7 +312,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 12 unmodified lines | ||
| 312 | 312 | (Tree, rhs_mode) if rhs_mode.is_no_tree() => { |
| 313 | 313 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 314 | 314 | if delegate |
| 315 | − .record(Change::Deletion { | |
| 315 | + .visit(Change::Deletion { | |
| 316 | 316 | entry_mode: lhs.mode, |
| 317 | 317 | oid: lhs.oid.to_owned(), |
| 318 | 318 | }) |
| @@ -321,7 +321,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 2 unmodified lines | ||
| 321 | 321 | return Err(Error::Cancelled); |
| 322 | 322 | } |
| 323 | 323 | if delegate |
| 324 | − .record(Change::Addition { | |
| 324 | + .visit(Change::Addition { | |
| 325 | 325 | entry_mode: rhs.mode, |
| 326 | 326 | oid: rhs.oid.to_owned(), |
| 327 | 327 | }) |
| @@ -342,7 +342,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 14 unmodified lines | ||
| 342 | 342 | debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree()); |
| 343 | 343 | if lhs.oid != rhs.oid |
| 344 | 344 | && delegate |
| 345 | − .record(Change::Modification { | |
| 345 | + .visit(Change::Modification { | |
| 346 | 346 | previous_entry_mode: lhs.mode, |
| 347 | 347 | previous_oid: lhs.oid.to_owned(), |
| 348 | 348 | entry_mode: rhs.mode, |
| @@ -41,9 +41,9 @@ where · 40 unmodified lines | ||
| 41 | 41 | mod changes; |
| 42 | 42 | |
| 43 | 43 | /// |
| 44 | −pub mod record; | |
| 45 | −pub use record::Record; | |
| 44 | +pub mod visit; | |
| 45 | +pub use visit::Visit; | |
| 46 | 46 | |
| 47 | −/// Houses a [`record::Record`] to keep track of all seen changes. Useful for debugging primarily. | |
| 47 | +/// Houses a [`visit::Visit`] to keep track of all seen changes. Useful for debugging primarily. | |
| 48 | 48 | pub mod recorder; |
| 49 | 49 | pub use recorder::Recorder; |
| @@ -1,4 +1,4 @@ | ||
| 1 | −use crate::visit::record; | |
| 1 | +use crate::tree::visit; | |
| 2 | 2 | use git_hash::ObjectId; |
| 3 | 3 | use git_object::{ |
| 4 | 4 | bstr::{BStr, BString, ByteSlice, ByteVec}, |
| @@ -6,8 +6,8 @@ use git_object::{ · 1 unmodified line | ||
| 6 | 6 | }; |
| 7 | 7 | use std::{collections::BTreeMap, ops::Deref, path::PathBuf}; |
| 8 | 8 | |
| 9 | −/// A Change as observed by a call to [`record::Record::record`], enhanced with the path affected by the change. | |
| 10 | −/// Its similar to [record::Change] but adds a path. | |
| 9 | +/// A Change as observed by a call to [`visit::Visit::visit`], enhanced with the path affected by the change. | |
| 10 | +/// Its similar to [visit::Change] but adds a path. | |
| 11 | 11 | #[derive(Clone, Debug, PartialEq, Eq)] |
| 12 | 12 | #[allow(missing_docs)] |
| 13 | 13 | pub enum Change { |
| @@ -32,7 +32,7 @@ pub enum Change { · 18 unmodified lines | ||
| 32 | 32 | }, |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | −/// A [record::Record] implementation to record every observed change and keep track of the changed paths. | |
| 35 | +/// A [visit::Visit] implementation to record every observed change and keep track of the changed paths. | |
| 36 | 36 | #[derive(Clone, Debug, Default)] |
| 37 | 37 | pub struct Recorder { |
| 38 | 38 | path_count: usize, |
| @@ -67,7 +67,7 @@ impl Recorder { · 28 unmodified lines | ||
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | −impl record::Record for Recorder { | |
| 70 | +impl visit::Visit for Recorder { | |
| 71 | 71 | type PathId = usize; |
| 72 | 72 | |
| 73 | 73 | fn set_current_path(&mut self, path: Self::PathId) { |
| @@ -90,8 +90,8 @@ impl record::Record for Recorder { · 16 unmodified lines | ||
| 90 | 90 | self.pop_element(); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | − fn record(&mut self, change: record::Change) -> record::Action { | |
| 94 | − use record::Change::*; | |
| 93 | + fn visit(&mut self, change: visit::Change) -> visit::Action { | |
| 94 | + use visit::Change::*; | |
| 95 | 95 | self.records.push(match change { |
| 96 | 96 | Deletion { entry_mode, oid } => Change::Deletion { |
| 97 | 97 | entry_mode, |
| @@ -116,6 +116,6 @@ impl record::Record for Recorder { · 18 unmodified lines | ||
| 116 | 116 | path: self.path_buf(), |
| 117 | 117 | }, |
| 118 | 118 | }); |
| 119 | − record::Action::Continue | |
| 119 | + visit::Action::Continue | |
| 120 | 120 | } |
| 121 | 121 | } |
| @@ -32,12 +32,12 @@ pub enum Change { · 31 unmodified lines | ||
| 32 | 32 | }, |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | −/// What to do after a [Change] was [recorded][Record::record()]. | |
| 35 | +/// What to do after a [Change] was [recorded][Visit::visit()]. | |
| 36 | 36 | #[derive(Clone, Copy, PartialOrd, PartialEq, Ord, Eq, Hash)] |
| 37 | 37 | pub enum Action { |
| 38 | 38 | /// Continue the traversal of changes. |
| 39 | 39 | Continue, |
| 40 | − /// Stop the traversal of changes, making this te last call to [record(…)][Record::record()]. | |
| 40 | + /// Stop the traversal of changes, making this te last call to [record(…)][Visit::visit()]. | |
| 41 | 41 | Cancel, |
| 42 | 42 | } |
| 43 | 43 | |
| @@ -50,7 +50,7 @@ impl Action { · 6 unmodified lines | ||
| 50 | 50 | |
| 51 | 51 | /// A trait to allow responding to a traversal designed to figure out the [changes][Change] |
| 52 | 52 | /// to turn tree A into tree B. |
| 53 | −pub trait Record { | |
| 53 | +pub trait Visit { | |
| 54 | 54 | /// A type capable of uniquely identifying paths in a tree. |
| 55 | 55 | type PathId: Clone + Default; |
| 56 | 56 | |
| @@ -65,7 +65,7 @@ pub trait Record { · 8 unmodified lines | ||
| 65 | 65 | /// Record a `change` and return an instruction whether to continue or not. |
| 66 | 66 | /// |
| 67 | 67 | /// The implementation may use the current path to lean where in the tree the change is located. |
| 68 | − fn record(&mut self, change: Change) -> Action; | |
| 68 | + fn visit(&mut self, change: Change) -> Action; | |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | #[cfg(test)] |
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | mod changes { |
| 2 | 2 | mod to_obtain_tree { |
| 3 | 3 | use crate::hex_to_id; |
| 4 | − use git_diff::visit::{recorder, recorder::Change::*}; | |
| 4 | + use git_diff::tree::{recorder, recorder::Change::*}; | |
| 5 | 5 | use git_hash::{oid, ObjectId}; |
| 6 | 6 | use git_object::{bstr::ByteSlice, immutable, tree::EntryMode}; |
| 7 | 7 | use git_odb::{linked, pack, Find}; |
| @@ -43,10 +43,10 @@ mod changes { · 35 unmodified lines | ||
| 43 | 43 | .and_then(|lhs| locate_tree_by_commit(db, &lhs, &mut buf).ok()); |
| 44 | 44 | let mut buf2 = Vec::new(); |
| 45 | 45 | let rhs_tree = locate_tree_by_commit(db, rhs, &mut buf2)?; |
| 46 | − let mut recorder = git_diff::visit::Recorder::default(); | |
| 47 | − git_diff::visit::Changes::from(lhs_tree).needed_to_obtain( | |
| 46 | + let mut recorder = git_diff::tree::Recorder::default(); | |
| 47 | + git_diff::tree::Changes::from(lhs_tree).needed_to_obtain( | |
| 48 | 48 | rhs_tree, |
| 49 | − git_diff::visit::State::default(), | |
| 49 | + git_diff::tree::State::default(), | |
| 50 | 50 | |oid, buf| { |
| 51 | 51 | db.find(oid, buf, &mut pack::cache::Never) |
| 52 | 52 | .ok() |
| @@ -89,10 +89,10 @@ mod changes { · 36 unmodified lines | ||
| 89 | 89 | .and_then(|tree| tree.into_tree_iter()) |
| 90 | 90 | }; |
| 91 | 91 | |
| 92 | − let mut recorder = git_diff::visit::Recorder::default(); | |
| 93 | − git_diff::visit::Changes::from(previous_tree).needed_to_obtain( | |
| 92 | + let mut recorder = git_diff::tree::Recorder::default(); | |
| 93 | + git_diff::tree::Changes::from(previous_tree).needed_to_obtain( | |
| 94 | 94 | current_tree, |
| 95 | − &mut git_diff::visit::State::default(), | |
| 95 | + &mut git_diff::tree::State::default(), | |
| 96 | 96 | |oid, buf| { |
| 97 | 97 | db.find(oid, buf, &mut pack::cache::Never) |
| 98 | 98 | .ok() |