History

[tree-diff] a step towards catching up with rhs

Sebastian Thiel committed 5 years ago

Commit bbe7beb1 parent 791c4293 files · +63 −17Browse files

Showing the changes to git-diff/src (1 of 3 files). Show all

Unified · Split

git-diff/src/visit/changes.rs+51−17
@@ -1,4 +1,4 @@
1−use crate::visit::TreeInfo;
1+use crate::visit::{TreeInfo, TreeInfoPair};
22 use crate::{
33 visit,
44 visit::{changes::Error::Cancelled, record::Change},
@@ -6,6 +6,7 @@ use crate::{ · 1 unmodified line
66 use git_hash::{oid, ObjectId};
77 use git_object::{immutable, tree};
88 use quick_error::quick_error;
9+use std::collections::VecDeque;
910
1011 quick_error! {
1112 #[derive(Debug)]
@@ -54,6 +55,7 @@ impl<'a> visit::Changes<'a> { · 42 unmodified lines
5455 let mut rhs_entries = other;
5556 let mut avoid_popping_path: Option<()> = None;
5657
58+ dbg!("================= START ===================");
5759 loop {
5860 if avoid_popping_path.take().is_none() {
5961 delegate.pop_path_component();
@@ -82,6 +84,7 @@ impl<'a> visit::Changes<'a> { · 22 unmodified lines
8284 (Some(lhs), Some(rhs)) => {
8385 use std::cmp::Ordering::*;
8486 let (lhs, rhs) = (lhs?, rhs?);
87+ dbg!(&lhs, &rhs);
8588 match lhs.filename.cmp(rhs.filename) {
8689 Equal => {
8790 use tree::EntryMode::*;
@@ -185,27 +188,27 @@ impl<'a> visit::Changes<'a> { · 97 unmodified lines
185188 }
186189 };
187190 }
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+ }
189206 Greater => todo!("entry compares more - let the other side catch up"),
190207 }
191208 }
192209 (Some(lhs), None) => {
193210 let lhs = lhs?;
194− delegate.push_path_component(lhs.filename);
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− }
211+ delete_entry_schedule_recursion(&lhs, &mut state.trees, delegate)?;
209212 }
210213 (None, Some(rhs)) => {
211214 let rhs = rhs?;
@@ -229,3 +232,34 @@ impl<'a> visit::Changes<'a> { · 17 unmodified lines
229232 }
230233 }
231234 }
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+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t