Showing the changes to git-diff (2 of 2 files). Show all
Unified · Split
| @@ -37,6 +37,7 @@ impl<'a> visit::Changes<'a> { · 36 unmodified lines | ||
| 37 | 37 | /// * it does a breadth first iteration as buffer space only fits two trees, the current one on the one we compare with. |
| 38 | 38 | /// * does not do rename tracking but attempts to reduce allocations to zero (so performance is mostly determined |
| 39 | 39 | /// by the delegate implementation which should be as specific as possible. |
| 40 | + /// * cycle checking is not performed, but can be performed in the delegate | |
| 40 | 41 | pub fn needed_to_obtain<LocateFn, R>( |
| 41 | 42 | mut self, |
| 42 | 43 | other: immutable::TreeIter<'a>, |
| @@ -58,15 +59,27 @@ impl<'a> visit::Changes<'a> { · 15 unmodified lines | ||
| 58 | 59 | delegate.pop_path_component(); |
| 59 | 60 | } |
| 60 | 61 | match (lhs_entries.next(), rhs_entries.next()) { |
| 61 | − (None, None) => match state.trees.pop_front() { | |
| 62 | − Some((None, Some(rhs))) => { | |
| 63 | − delegate.set_current_path(rhs.parent_path_id.clone()); | |
| 64 | − rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?; | |
| 65 | − avoid_popping_path = Some(()); | |
| 66 | − } | |
| 67 | − None => return Ok(()), | |
| 68 | − _ => todo!("all other combinations to re-stock iterators"), | |
| 69 | − }, | |
| 62 | + (None, None) => { | |
| 63 | + match state.trees.pop_front() { | |
| 64 | + Some((None, Some(rhs))) => { | |
| 65 | + delegate.set_current_path(rhs.parent_path_id.clone()); | |
| 66 | + rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?; | |
| 67 | + } | |
| 68 | + Some((Some(lhs), Some(rhs))) => { | |
| 69 | + delegate.set_current_path(lhs.parent_path_id.clone()); | |
| 70 | + lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?; | |
| 71 | + rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?; | |
| 72 | + } | |
| 73 | + Some((Some(_lhs), None)) => { | |
| 74 | + todo!("locate none|tree"); | |
| 75 | + // delegate.set_current_path(lhs.parent_path_id.clone()); | |
| 76 | + // lhs_entries = locate(&lhs.tree_id, &mut state.buf1).ok_or(Error::NotFound(lhs.tree_id))?; | |
| 77 | + } | |
| 78 | + Some((None, None)) => unreachable!("BUG: it makes no sense to fill the stack with empties"), | |
| 79 | + None => return Ok(()), | |
| 80 | + }; | |
| 81 | + avoid_popping_path = Some(()); | |
| 82 | + } | |
| 70 | 83 | (Some(lhs), Some(rhs)) => { |
| 71 | 84 | use std::cmp::Ordering::*; |
| 72 | 85 | let (lhs, rhs) = (lhs?, rhs?); |
| @@ -75,7 +88,7 @@ impl<'a> visit::Changes<'a> { · 2 unmodified lines | ||
| 75 | 88 | use tree::EntryMode::*; |
| 76 | 89 | match (lhs.mode, rhs.mode) { |
| 77 | 90 | (Tree, Tree) => { |
| 78 | − let _path_id = delegate.push_tracked_path_component(lhs.filename); | |
| 91 | + let path_id = delegate.push_tracked_path_component(lhs.filename); | |
| 79 | 92 | if lhs.oid != rhs.oid |
| 80 | 93 | && delegate |
| 81 | 94 | .record(Change::Modification { |
| @@ -88,7 +101,16 @@ impl<'a> visit::Changes<'a> { · 6 unmodified lines | ||
| 88 | 101 | { |
| 89 | 102 | return Err(Cancelled); |
| 90 | 103 | } |
| 91 | − todo!("schedule tree|tree iteration schedule the trees with stack") | |
| 104 | + state.trees.push_back(( | |
| 105 | + Some(TreeInfo { | |
| 106 | + tree_id: lhs.oid.to_owned(), | |
| 107 | + parent_path_id: path_id.clone(), | |
| 108 | + }), | |
| 109 | + Some(TreeInfo { | |
| 110 | + tree_id: rhs.oid.to_owned(), | |
| 111 | + parent_path_id: path_id, | |
| 112 | + }), | |
| 113 | + )); | |
| 92 | 114 | } |
| 93 | 115 | (lhs_mode, Tree) if lhs_mode.is_no_tree() => { |
| 94 | 116 | let path_id = delegate.push_tracked_path_component(lhs.filename); |
| @@ -3,18 +3,23 @@ mod changes { · 2 unmodified lines | ||
| 3 | 3 | use crate::hex_to_id; |
| 4 | 4 | use git_diff::visit::recorder; |
| 5 | 5 | use git_object::tree::EntryMode; |
| 6 | − use git_odb::{pack, Locate}; | |
| 6 | + use git_odb::{linked, pack, Locate}; | |
| 7 | 7 | |
| 8 | 8 | const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430"; |
| 9 | 9 | const SECOND_COMMIT: &str = "a5ebf9ee3b1cac5daf3dc9056026ee848be52da2"; |
| 10 | 10 | const FIFTH_COMMIT: &str = "69bbebb6608472d98be684f4e6ef1faaac2a03bc"; |
| 11 | + const SIXTH_COMMIT: &str = "9bd749db486b2af4a0d4df2de1972db2f198903d"; | |
| 11 | 12 | |
| 12 | − fn diff_with_previous_commit_from(commit_id: &str) -> crate::Result<recorder::Changes> { | |
| 13 | − let db = git_odb::linked::Db::at( | |
| 13 | + fn db() -> crate::Result<linked::Db> { | |
| 14 | + linked::Db::at( | |
| 14 | 15 | test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")? |
| 15 | 16 | .join(".git") |
| 16 | 17 | .join("objects"), |
| 17 | − )?; | |
| 18 | + ) | |
| 19 | + .map_err(Into::into) | |
| 20 | + } | |
| 21 | + | |
| 22 | + fn diff_with_previous_commit_from(db: &linked::Db, commit_id: &str) -> crate::Result<recorder::Changes> { | |
| 18 | 23 | let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?; |
| 19 | 24 | let mut buf = Vec::new(); |
| 20 | 25 | let (main_tree_id, parent_commit_id) = { |
| @@ -62,17 +67,19 @@ mod changes { · 41 unmodified lines | ||
| 62 | 67 | } |
| 63 | 68 | |
| 64 | 69 | #[test] |
| 65 | − fn many_different_states() { | |
| 70 | + fn many_different_states() -> crate::Result { | |
| 71 | + let db = db()?; | |
| 66 | 72 | assert_eq!( |
| 67 | − diff_with_previous_commit_from(FIRST_COMMIT).unwrap(), | |
| 73 | + diff_with_previous_commit_from(&db, FIRST_COMMIT)?, | |
| 68 | 74 | vec![recorder::Change::Addition { |
| 69 | 75 | entry_mode: EntryMode::Blob, |
| 70 | 76 | oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"), |
| 71 | 77 | path: "f".into() |
| 72 | 78 | }] |
| 73 | 79 | , ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f"); |
| 80 | + | |
| 74 | 81 | assert_eq!( |
| 75 | − diff_with_previous_commit_from(SECOND_COMMIT).unwrap(), | |
| 82 | + diff_with_previous_commit_from(&db, SECOND_COMMIT)?, | |
| 76 | 83 | vec![recorder::Change::Modification { |
| 77 | 84 | previous_entry_mode: EntryMode::Blob, |
| 78 | 85 | previous_oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"), |
| @@ -81,8 +88,9 @@ mod changes { · 2 unmodified lines | ||
| 81 | 88 | path: "f".into() |
| 82 | 89 | }] |
| 83 | 90 | , ":100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 28ce6a8b26aa170e1de65536fe8abe1832bd3242 M f"); |
| 91 | + | |
| 84 | 92 | assert_eq!( |
| 85 | − diff_with_previous_commit_from(FIFTH_COMMIT).unwrap(), | |
| 93 | + diff_with_previous_commit_from(&db, FIFTH_COMMIT)?, | |
| 86 | 94 | vec![recorder::Change::Deletion { |
| 87 | 95 | entry_mode: EntryMode::Blob, |
| 88 | 96 | oid: hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"), |
| @@ -100,6 +108,28 @@ mod changes { · 11 unmodified lines | ||
| 100 | 108 | }] |
| 101 | 109 | , ":100644 000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 0000000000000000000000000000000000000000 D f |
| 102 | 110 | :000000 100644 0000000000000000000000000000000000000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 A f/f"); |
| 111 | + | |
| 112 | + assert_eq!( | |
| 113 | + diff_with_previous_commit_from(&db, SIXTH_COMMIT)?, | |
| 114 | + vec![ | |
| 115 | + recorder::Change::Modification { | |
| 116 | + previous_entry_mode: EntryMode::Tree, | |
| 117 | + previous_oid: hex_to_id("10f2f4b82222d2b5c31985130979a91fd87410f7"), | |
| 118 | + entry_mode: EntryMode::Tree, | |
| 119 | + oid: hex_to_id("ebbe0b3000afdfd1aed15000094b59a2800328eb"), | |
| 120 | + path: "f".into() | |
| 121 | + }, | |
| 122 | + recorder::Change::Modification { | |
| 123 | + previous_entry_mode: EntryMode::Blob, | |
| 124 | + previous_oid: hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"), | |
| 125 | + entry_mode: EntryMode::Blob, | |
| 126 | + oid: hex_to_id("13c2aca72ab576cb5f22dc8e7f8ba8ddab553a8a"), | |
| 127 | + path: "f/f".into() | |
| 128 | + }, | |
| 129 | + ], | |
| 130 | + ":100644 100644 28ce6a8b26aa170e1de65536fe8abe1832bd3242 13c2aca72ab576cb5f22dc8e7f8ba8ddab553a8a M f/f" | |
| 131 | + ); | |
| 132 | + Ok(()) | |
| 103 | 133 | } |
| 104 | 134 | } |
| 105 | 135 | } |