Showing the changes to git-diff/src (1 of 3 files). Show all
Unified · Split
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::visit::TreeInfo; | 1 | use crate::visit::{TreeInfo, TreeInfoPair}; |
| 2 | use crate::{ | 2 | use crate::{ |
| 3 | visit, | 3 | visit, |
| 4 | visit::{changes::Error::Cancelled, record::Change}, | 4 | visit::{changes::Error::Cancelled, record::Change}, |
| @@ -6,6 +6,7 @@ use crate::{ · 1 unmodified line | |||
| 6 | use git_hash::{oid, ObjectId}; | 6 | use git_hash::{oid, ObjectId}; |
| 7 | use git_object::{immutable, tree}; | 7 | use git_object::{immutable, tree}; |
| 8 | use quick_error::quick_error; | 8 | use quick_error::quick_error; |
| 9 | use std::collections::VecDeque; | ||
| 9 | 10 | ||
| 10 | quick_error! { | 11 | quick_error! { |
| 11 | #[derive(Debug)] | 12 | #[derive(Debug)] |
| @@ -54,6 +55,7 @@ impl<'a> visit::Changes<'a> { · 42 unmodified lines | |||
| 54 | let mut rhs_entries = other; | 55 | let mut rhs_entries = other; |
| 55 | let mut avoid_popping_path: Option<()> = None; | 56 | let mut avoid_popping_path: Option<()> = None; |
| 56 | 57 | ||
| 58 | dbg!("================= START ==================="); | ||
| 57 | loop { | 59 | loop { |
| 58 | if avoid_popping_path.take().is_none() { | 60 | if avoid_popping_path.take().is_none() { |
| 59 | delegate.pop_path_component(); | 61 | delegate.pop_path_component(); |
| @@ -82,6 +84,7 @@ impl<'a> visit::Changes<'a> { · 22 unmodified lines | |||
| 82 | (Some(lhs), Some(rhs)) => { | 84 | (Some(lhs), Some(rhs)) => { |
| 83 | use std::cmp::Ordering::*; | 85 | use std::cmp::Ordering::*; |
| 84 | let (lhs, rhs) = (lhs?, rhs?); | 86 | let (lhs, rhs) = (lhs?, rhs?); |
| 87 | dbg!(&lhs, &rhs); | ||
| 85 | match lhs.filename.cmp(rhs.filename) { | 88 | match lhs.filename.cmp(rhs.filename) { |
| 86 | Equal => { | 89 | Equal => { |
| 87 | use tree::EntryMode::*; | 90 | use tree::EntryMode::*; |
| @@ -185,27 +188,27 @@ impl<'a> visit::Changes<'a> { · 97 unmodified lines | |||
| 185 | } | 188 | } |
| 186 | }; | 189 | }; |
| 187 | } | 190 | } |
| 188 | Less => todo!("entry compares less - catch up"), | 191 | Less => { |
| 192 | let mut cursor = lhs; | ||
| 193 | loop { | ||
| 194 | delete_entry_schedule_recursion(&cursor, &mut state.trees, delegate)?; | ||
| 195 | |||
| 196 | match lhs_entries.next() { | ||
| 197 | Some(entry) => { | ||
| 198 | let entry = entry?; | ||
| 199 | // if entry.filename == rhs. | ||
| 200 | todo!("peek entry, see if we caught up, ") | ||
| 201 | } | ||
| 202 | None => break, | ||
| 203 | } | ||
| 204 | } | ||
| 205 | } | ||
| 189 | Greater => todo!("entry compares more - let the other side catch up"), | 206 | Greater => todo!("entry compares more - let the other side catch up"), |
| 190 | } | 207 | } |
| 191 | } | 208 | } |
| 192 | (Some(lhs), None) => { | 209 | (Some(lhs), None) => { |
| 193 | let lhs = lhs?; | 210 | let lhs = lhs?; |
| 194 | delegate.push_path_component(lhs.filename); | 211 | delete_entry_schedule_recursion(&lhs, &mut state.trees, delegate)?; |
| 195 | if delegate | ||
| 196 | .record(Change::Deletion { | ||
| 197 | entry_mode: lhs.mode, | ||
| 198 | oid: lhs.oid.to_owned(), | ||
| 199 | }) | ||
| 200 | .cancelled() | ||
| 201 | { | ||
| 202 | break Err(Error::Cancelled); | ||
| 203 | } | ||
| 204 | if lhs.mode.is_tree() { | ||
| 205 | delegate.pop_path_component(); | ||
| 206 | let _path_id = delegate.push_tracked_path_component(lhs.filename); | ||
| 207 | todo!("delete tree recursively") | ||
| 208 | } | ||
| 209 | } | 212 | } |
| 210 | (None, Some(rhs)) => { | 213 | (None, Some(rhs)) => { |
| 211 | let rhs = rhs?; | 214 | let rhs = rhs?; |
| @@ -229,3 +232,34 @@ impl<'a> visit::Changes<'a> { · 17 unmodified lines | |||
| 229 | } | 232 | } |
| 230 | } | 233 | } |
| 231 | } | 234 | } |
| 235 | fn delete_entry_schedule_recursion<R>( | ||
| 236 | entry: &immutable::tree::Entry<'_>, | ||
| 237 | queue: &mut VecDeque<TreeInfoPair<R::PathId>>, | ||
| 238 | delegate: &mut R, | ||
| 239 | ) -> Result<(), Error> | ||
| 240 | where | ||
| 241 | R: visit::Record, | ||
| 242 | { | ||
| 243 | delegate.push_path_component(entry.filename); | ||
| 244 | if delegate | ||
| 245 | .record(Change::Deletion { | ||
| 246 | entry_mode: entry.mode, | ||
| 247 | oid: entry.oid.to_owned(), | ||
| 248 | }) | ||
| 249 | .cancelled() | ||
| 250 | { | ||
| 251 | return Err(Error::Cancelled); | ||
| 252 | } | ||
| 253 | if entry.mode.is_tree() { | ||
| 254 | delegate.pop_path_component(); | ||
| 255 | let path_id = delegate.push_tracked_path_component(entry.filename); | ||
| 256 | queue.push_back(( | ||
| 257 | Some(TreeInfo { | ||
| 258 | tree_id: entry.oid.to_owned(), | ||
| 259 | parent_path_id: path_id, | ||
| 260 | }), | ||
| 261 | None, | ||
| 262 | )); | ||
| 263 | } | ||
| 264 | Ok(()) | ||
| 265 | } | ||