| @@ -1,9 +1,9 @@ |
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | visit, | 2 | tree, |
| 3 | visit::{changes::Error::Cancelled, record::Change, TreeInfo, TreeInfoPair}, | 3 | tree::{changes::Error::Cancelled, visit::Change, TreeInfo, TreeInfoPair}, |
| 4 | }; | 4 | }; |
| 5 | use git_hash::{oid, ObjectId}; | 5 | use git_hash::{oid, ObjectId}; |
| 6 | use git_object::{immutable, tree}; | 6 | use git_object::immutable; |
| 7 | use quick_error::quick_error; | 7 | use quick_error::quick_error; |
| 8 | use std::{borrow::BorrowMut, collections::VecDeque}; | 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> { | 27 | impl<'a> tree::Changes<'a> { |
| 28 | /// Returns the changes that need to be applied to `self` to get `other`. | 28 | /// that need to be applied to `self` to get `other`. |
| 29 | /// TODO: Talk about choices in error handling and why Option<T> is enough, as opposed to the usual Result<Option<T>> | 29 | /// TODO: Talk about choices in error handling and why Option<T> is enough, as opposed to the usual Result<Option<T>> |
| 30 | /// Talk about progress (done via delegate if needed) | 30 | /// Talk about progress (done via delegate if needed) |
| 31 | /// | 31 | /// |
| @@ -51,8 +51,8 @@ impl<'a> visit::Changes<'a> { · 19 unmodified lines |
| 51 | ) -> Result<(), Error> | 51 | ) -> Result<(), Error> |
| 52 | where | 52 | where |
| 53 | LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>, | 53 | LocateFn: for<'b> FnMut(&oid, &'b mut Vec<u8>) -> Option<immutable::tree::TreeIter<'b>>, |
| 54 | R: visit::Record, | 54 | R: tree::Visit, |
| 55 | StateMut: BorrowMut<visit::State<R::PathId>>, | 55 | StateMut: BorrowMut<tree::State<R::PathId>>, |
| 56 | { | 56 | { |
| 57 | let state = state.borrow_mut(); | 57 | let state = state.borrow_mut(); |
| 58 | state.clear(); | 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 | entry: immutable::tree::Entry<'_>, | 115 | entry: immutable::tree::Entry<'_>, |
| 116 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, | 116 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 117 | delegate: &mut R, | 117 | delegate: &mut R, |
| 118 | ) -> Result<(), Error> { | 118 | ) -> Result<(), Error> { |
| 119 | delegate.push_path_component(entry.filename); | 119 | delegate.push_path_component(entry.filename); |
| 120 | if delegate | 120 | if delegate |
| 121 | .record(Change::Deletion { | 121 | .visit(Change::Deletion { |
| 122 | entry_mode: entry.mode, | 122 | entry_mode: entry.mode, |
| 123 | oid: entry.oid.to_owned(), | 123 | oid: entry.oid.to_owned(), |
| 124 | }) | 124 | }) |
| @@ -140,14 +140,14 @@ fn delete_entry_schedule_recursion<R: visit::Record>( · 15 unmodified lines |
| 140 | Ok(()) | 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 | entry: immutable::tree::Entry<'_>, | 144 | entry: immutable::tree::Entry<'_>, |
| 145 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, | 145 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 146 | delegate: &mut R, | 146 | delegate: &mut R, |
| 147 | ) -> Result<(), Error> { | 147 | ) -> Result<(), Error> { |
| 148 | delegate.push_path_component(entry.filename); | 148 | delegate.push_path_component(entry.filename); |
| 149 | if delegate | 149 | if delegate |
| 150 | .record(Change::Addition { | 150 | .visit(Change::Addition { |
| 151 | entry_mode: entry.mode, | 151 | entry_mode: entry.mode, |
| 152 | oid: entry.oid.to_owned(), | 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 | Ok(()) | 169 | Ok(()) |
| 170 | } | 170 | } |
| 171 | fn catchup_rhs_with_lhs<R: visit::Record>( | 171 | fn catchup_rhs_with_lhs<R: tree::Visit>( |
| 172 | rhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, | 172 | rhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, |
| 173 | lhs: immutable::tree::Entry<'_>, | 173 | lhs: immutable::tree::Entry<'_>, |
| 174 | rhs: immutable::tree::Entry<'_>, | 174 | rhs: immutable::tree::Entry<'_>, |
| @@ -208,7 +208,7 @@ fn catchup_rhs_with_lhs<R: visit::Record>( · 33 unmodified lines |
| 208 | Ok(()) | 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 | lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, | 212 | lhs_entries: &mut IteratorType<immutable::TreeIter<'_>>, |
| 213 | lhs: immutable::tree::Entry<'_>, | 213 | lhs: immutable::tree::Entry<'_>, |
| 214 | rhs: immutable::tree::Entry<'_>, | 214 | rhs: immutable::tree::Entry<'_>, |
| @@ -248,19 +248,19 @@ fn catchup_lhs_with_rhs<R: visit::Record>( · 33 unmodified lines |
| 248 | Ok(()) | 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 | lhs: immutable::tree::Entry<'_>, | 252 | lhs: immutable::tree::Entry<'_>, |
| 253 | rhs: immutable::tree::Entry<'_>, | 253 | rhs: immutable::tree::Entry<'_>, |
| 254 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, | 254 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, |
| 255 | delegate: &mut R, | 255 | delegate: &mut R, |
| 256 | ) -> Result<(), Error> { | 256 | ) -> Result<(), Error> { |
| 257 | use tree::EntryMode::*; | 257 | use git_object::tree::EntryMode::*; |
| 258 | match (lhs.mode, rhs.mode) { | 258 | match (lhs.mode, rhs.mode) { |
| 259 | (Tree, Tree) => { | 259 | (Tree, Tree) => { |
| 260 | let path_id = delegate.push_tracked_path_component(lhs.filename); | 260 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 261 | if lhs.oid != rhs.oid | 261 | if lhs.oid != rhs.oid |
| 262 | && delegate | 262 | && delegate |
| 263 | .record(Change::Modification { | 263 | .visit(Change::Modification { |
| 264 | previous_entry_mode: lhs.mode, | 264 | previous_entry_mode: lhs.mode, |
| 265 | previous_oid: lhs.oid.to_owned(), | 265 | previous_oid: lhs.oid.to_owned(), |
| 266 | entry_mode: rhs.mode, | 266 | entry_mode: rhs.mode, |
| @@ -284,7 +284,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: visit::Record>( · 17 unmodified lines |
| 284 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { | 284 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { |
| 285 | let path_id = delegate.push_tracked_path_component(lhs.filename); | 285 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 286 | if delegate | 286 | if delegate |
| 287 | .record(Change::Deletion { | 287 | .visit(Change::Deletion { |
| 288 | entry_mode: lhs.mode, | 288 | entry_mode: lhs.mode, |
| 289 | oid: lhs.oid.to_owned(), | 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 | return Err(Cancelled); | 293 | return Err(Cancelled); |
| 294 | }; | 294 | }; |
| 295 | if delegate | 295 | if delegate |
| 296 | .record(Change::Addition { | 296 | .visit(Change::Addition { |
| 297 | entry_mode: rhs.mode, | 297 | entry_mode: rhs.mode, |
| 298 | oid: rhs.oid.to_owned(), | 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 | (Tree, rhs_mode) if rhs_mode.is_no_tree() => { | 312 | (Tree, rhs_mode) if rhs_mode.is_no_tree() => { |
| 313 | let path_id = delegate.push_tracked_path_component(lhs.filename); | 313 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| 314 | if delegate | 314 | if delegate |
| 315 | .record(Change::Deletion { | 315 | .visit(Change::Deletion { |
| 316 | entry_mode: lhs.mode, | 316 | entry_mode: lhs.mode, |
| 317 | oid: lhs.oid.to_owned(), | 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 | return Err(Error::Cancelled); | 321 | return Err(Error::Cancelled); |
| 322 | } | 322 | } |
| 323 | if delegate | 323 | if delegate |
| 324 | .record(Change::Addition { | 324 | .visit(Change::Addition { |
| 325 | entry_mode: rhs.mode, | 325 | entry_mode: rhs.mode, |
| 326 | oid: rhs.oid.to_owned(), | 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 | debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree()); | 342 | debug_assert!(lhs_non_tree.is_no_tree() && rhs_non_tree.is_no_tree()); |
| 343 | if lhs.oid != rhs.oid | 343 | if lhs.oid != rhs.oid |
| 344 | && delegate | 344 | && delegate |
| 345 | .record(Change::Modification { | 345 | .visit(Change::Modification { |
| 346 | previous_entry_mode: lhs.mode, | 346 | previous_entry_mode: lhs.mode, |
| 347 | previous_oid: lhs.oid.to_owned(), | 347 | previous_oid: lhs.oid.to_owned(), |
| 348 | entry_mode: rhs.mode, | 348 | entry_mode: rhs.mode, |