Showing the changes to git-diff/src (2 of 3 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | |||
| 1 | use crate::{ | 1 | use crate::{ |
| 2 | tree, | 2 | tree, |
| 3 | tree::{visit::Change, TreeInfo, TreeInfoPair}, | 3 | tree::{visit::Change, TreeInfoPair}, |
| 4 | }; | 4 | }; |
| 5 | use git_hash::{oid, ObjectId}; | 5 | use git_hash::{oid, ObjectId}; |
| 6 | use git_object::immutable; | 6 | use git_object::immutable; |
| @@ -77,24 +77,16 @@ impl<'a> tree::Changes<'a> { · 70 unmodified lines | |||
| 77 | match state.trees.pop_front() { | 77 | match state.trees.pop_front() { |
| 78 | Some((None, Some(rhs))) => { | 78 | Some((None, Some(rhs))) => { |
| 79 | delegate.pop_front_tracked_path_and_set_current(); | 79 | delegate.pop_front_tracked_path_and_set_current(); |
| 80 | rhs_entries = peekable( | 80 | rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?); |
| 81 | locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound { oid: rhs.tree_id })?, | ||
| 82 | ); | ||
| 83 | } | 81 | } |
| 84 | Some((Some(lhs), Some(rhs))) => { | 82 | Some((Some(lhs), Some(rhs))) => { |
| 85 | delegate.pop_front_tracked_path_and_set_current(); | 83 | delegate.pop_front_tracked_path_and_set_current(); |
| 86 | lhs_entries = peekable( | 84 | lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?); |
| 87 | locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound { oid: lhs.tree_id })?, | 85 | rhs_entries = peekable(locate(&rhs, &mut state.buf2).ok_or(Error::NotFound { oid: rhs })?); |
| 88 | ); | ||
| 89 | rhs_entries = peekable( | ||
| 90 | locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound { oid: rhs.tree_id })?, | ||
| 91 | ); | ||
| 92 | } | 86 | } |
| 93 | Some((Some(lhs), None)) => { | 87 | Some((Some(lhs), None)) => { |
| 94 | delegate.pop_front_tracked_path_and_set_current(); | 88 | delegate.pop_front_tracked_path_and_set_current(); |
| 95 | lhs_entries = peekable( | 89 | lhs_entries = peekable(locate(&lhs, &mut state.buf1).ok_or(Error::NotFound { oid: lhs })?); |
| 96 | locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound { oid: lhs.tree_id })?, | ||
| 97 | ); | ||
| 98 | } | 90 | } |
| 99 | Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"), | 91 | Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"), |
| 100 | None => return Ok(()), | 92 | None => return Ok(()), |
| @@ -140,14 +132,8 @@ fn delete_entry_schedule_recursion<R: tree::Visit>( · 39 unmodified lines | |||
| 140 | } | 132 | } |
| 141 | if entry.mode.is_tree() { | 133 | if entry.mode.is_tree() { |
| 142 | delegate.pop_path_component(); | 134 | delegate.pop_path_component(); |
| 143 | let path_id = delegate.push_back_tracked_path_component(entry.filename); | 135 | delegate.push_back_tracked_path_component(entry.filename); |
| 144 | queue.push_back(( | 136 | queue.push_back((Some(entry.oid.to_owned()), None)); |
| 145 | Some(TreeInfo { | ||
| 146 | tree_id: entry.oid.to_owned(), | ||
| 147 | parent_path_id: Some(path_id), | ||
| 148 | }), | ||
| 149 | None, | ||
| 150 | )); | ||
| 151 | } | 137 | } |
| 152 | Ok(()) | 138 | Ok(()) |
| 153 | } | 139 | } |
| @@ -169,14 +155,8 @@ fn add_entry_schedule_recursion<R: tree::Visit>( · 15 unmodified lines | |||
| 169 | } | 155 | } |
| 170 | if entry.mode.is_tree() { | 156 | if entry.mode.is_tree() { |
| 171 | delegate.pop_path_component(); | 157 | delegate.pop_path_component(); |
| 172 | let path_id = delegate.push_back_tracked_path_component(entry.filename); | 158 | delegate.push_back_tracked_path_component(entry.filename); |
| 173 | queue.push_back(( | 159 | queue.push_back((None, Some(entry.oid.to_owned()))) |
| 174 | None, | ||
| 175 | Some(TreeInfo { | ||
| 176 | tree_id: entry.oid.to_owned(), | ||
| 177 | parent_path_id: Some(path_id), | ||
| 178 | }), | ||
| 179 | )) | ||
| 180 | } | 160 | } |
| 181 | Ok(()) | 161 | Ok(()) |
| 182 | } | 162 | } |
| @@ -269,7 +249,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 86 unmodified lines | |||
| 269 | use git_object::tree::EntryMode::*; | 249 | use git_object::tree::EntryMode::*; |
| 270 | match (lhs.mode, rhs.mode) { | 250 | match (lhs.mode, rhs.mode) { |
| 271 | (Tree, Tree) => { | 251 | (Tree, Tree) => { |
| 272 | let path_id = delegate.push_back_tracked_path_component(lhs.filename); | 252 | delegate.push_back_tracked_path_component(lhs.filename); |
| 273 | if lhs.oid != rhs.oid | 253 | if lhs.oid != rhs.oid |
| 274 | && delegate | 254 | && delegate |
| 275 | .visit(Change::Modification { | 255 | .visit(Change::Modification { |
| @@ -282,19 +262,10 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 6 unmodified lines | |||
| 282 | { | 262 | { |
| 283 | return Err(Error::Cancelled); | 263 | return Err(Error::Cancelled); |
| 284 | } | 264 | } |
| 285 | queue.push_back(( | 265 | queue.push_back((Some(lhs.oid.to_owned()), Some(rhs.oid.to_owned()))); |
| 286 | Some(TreeInfo { | ||
| 287 | tree_id: lhs.oid.to_owned(), | ||
| 288 | parent_path_id: Some(path_id), | ||
| 289 | }), | ||
| 290 | Some(TreeInfo { | ||
| 291 | tree_id: rhs.oid.to_owned(), | ||
| 292 | parent_path_id: None, | ||
| 293 | }), | ||
| 294 | )); | ||
| 295 | } | 266 | } |
| 296 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { | 267 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { |
| 297 | let path_id = delegate.push_back_tracked_path_component(lhs.filename); | 268 | delegate.push_back_tracked_path_component(lhs.filename); |
| 298 | if delegate | 269 | if delegate |
| 299 | .visit(Change::Deletion { | 270 | .visit(Change::Deletion { |
| 300 | entry_mode: lhs.mode, | 271 | entry_mode: lhs.mode, |
| @@ -313,16 +284,10 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 12 unmodified lines | |||
| 313 | { | 284 | { |
| 314 | return Err(Error::Cancelled); | 285 | return Err(Error::Cancelled); |
| 315 | }; | 286 | }; |
| 316 | queue.push_back(( | 287 | queue.push_back((None, Some(rhs.oid.to_owned()))); |
| 317 | None, | ||
| 318 | Some(TreeInfo { | ||
| 319 | tree_id: rhs.oid.to_owned(), | ||
| 320 | parent_path_id: Some(path_id), | ||
| 321 | }), | ||
| 322 | )); | ||
| 323 | } | 288 | } |
| 324 | (Tree, rhs_mode) if rhs_mode.is_no_tree() => { | 289 | (Tree, rhs_mode) if rhs_mode.is_no_tree() => { |
| 325 | let path_id = delegate.push_back_tracked_path_component(lhs.filename); | 290 | delegate.push_back_tracked_path_component(lhs.filename); |
| 326 | if delegate | 291 | if delegate |
| 327 | .visit(Change::Deletion { | 292 | .visit(Change::Deletion { |
| 328 | entry_mode: lhs.mode, | 293 | entry_mode: lhs.mode, |
| @@ -341,13 +306,7 @@ fn handle_lhs_and_rhs_with_equal_filenames<R: tree::Visit>( · 12 unmodified lines | |||
| 341 | { | 306 | { |
| 342 | return Err(Error::Cancelled); | 307 | return Err(Error::Cancelled); |
| 343 | }; | 308 | }; |
| 344 | queue.push_back(( | 309 | queue.push_back((Some(lhs.oid.to_owned()), None)); |
| 345 | Some(TreeInfo { | ||
| 346 | tree_id: lhs.oid.to_owned(), | ||
| 347 | parent_path_id: Some(path_id), | ||
| 348 | }), | ||
| 349 | None, | ||
| 350 | )); | ||
| 351 | } | 310 | } |
| 352 | (lhs_non_tree, rhs_non_tree) => { | 311 | (lhs_non_tree, rhs_non_tree) => { |
| 353 | delegate.push_path_component(lhs.filename); | 312 | delegate.push_path_component(lhs.filename); |
| @@ -10,13 +10,7 @@ pub struct State { · 9 unmodified lines | |||
| 10 | trees: VecDeque<TreeInfoPair>, | 10 | trees: VecDeque<TreeInfoPair>, |
| 11 | } | 11 | } |
| 12 | 12 | ||
| 13 | type TreeInfoPair = (Option<TreeInfo>, Option<TreeInfo>); | 13 | type TreeInfoPair = (Option<ObjectId>, Option<ObjectId>); |
| 14 | |||
| 15 | #[derive(Clone)] | ||
| 16 | pub(crate) struct TreeInfo { | ||
| 17 | pub tree_id: ObjectId, | ||
| 18 | pub parent_path_id: Option<()>, | ||
| 19 | } | ||
| 20 | 14 | ||
| 21 | impl State { | 15 | impl State { |
| 22 | fn clear(&mut self) { | 16 | fn clear(&mut self) { |