History

[tree-diff] test modification within a directory

Sebastian Thiel committed 5 years ago

Commit ff82a821 parent c223e312 files · +71 −19Browse files

Showing the changes to git-diff (2 of 2 files). Show all

Unified · Split

2 files
  1. git-diff/src/visit/changes.rs +33 −11
  2. git-diff/tests/visit/mod.rs +38 −8
git-diff/src/visit/changes.rs+33−11
@@ -37,6 +37,7 @@ impl<'a> visit::Changes<'a> { · 36 unmodified lines
3737 /// * it does a breadth first iteration as buffer space only fits two trees, the current one on the one we compare with.
3838 /// * does not do rename tracking but attempts to reduce allocations to zero (so performance is mostly determined
3939 /// by the delegate implementation which should be as specific as possible.
40+ /// * cycle checking is not performed, but can be performed in the delegate
4041 pub fn needed_to_obtain<LocateFn, R>(
4142 mut self,
4243 other: immutable::TreeIter<'a>,
@@ -58,15 +59,27 @@ impl<'a> visit::Changes<'a> { · 15 unmodified lines
5859 delegate.pop_path_component();
5960 }
6061 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+ }
7083 (Some(lhs), Some(rhs)) => {
7184 use std::cmp::Ordering::*;
7285 let (lhs, rhs) = (lhs?, rhs?);
@@ -75,7 +88,7 @@ impl<'a> visit::Changes<'a> { · 2 unmodified lines
7588 use tree::EntryMode::*;
7689 match (lhs.mode, rhs.mode) {
7790 (Tree, Tree) => {
78− let _path_id = delegate.push_tracked_path_component(lhs.filename);
91+ let path_id = delegate.push_tracked_path_component(lhs.filename);
7992 if lhs.oid != rhs.oid
8093 && delegate
8194 .record(Change::Modification {
@@ -88,7 +101,16 @@ impl<'a> visit::Changes<'a> { · 6 unmodified lines
88101 {
89102 return Err(Cancelled);
90103 }
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+ ));
92114 }
93115 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {
94116 let path_id = delegate.push_tracked_path_component(lhs.filename);
git-diff/tests/visit/mod.rs+38−8
@@ -3,18 +3,23 @@ mod changes { · 2 unmodified lines
33 use crate::hex_to_id;
44 use git_diff::visit::recorder;
55 use git_object::tree::EntryMode;
6− use git_odb::{pack, Locate};
6+ use git_odb::{linked, pack, Locate};
77
88 const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430";
99 const SECOND_COMMIT: &str = "a5ebf9ee3b1cac5daf3dc9056026ee848be52da2";
1010 const FIFTH_COMMIT: &str = "69bbebb6608472d98be684f4e6ef1faaac2a03bc";
11+ const SIXTH_COMMIT: &str = "9bd749db486b2af4a0d4df2de1972db2f198903d";
1112
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(
1415 test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")?
1516 .join(".git")
1617 .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> {
1823 let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?;
1924 let mut buf = Vec::new();
2025 let (main_tree_id, parent_commit_id) = {
@@ -62,17 +67,19 @@ mod changes { · 41 unmodified lines
6267 }
6368
6469 #[test]
65− fn many_different_states() {
70+ fn many_different_states() -> crate::Result {
71+ let db = db()?;
6672 assert_eq!(
67− diff_with_previous_commit_from(FIRST_COMMIT).unwrap(),
73+ diff_with_previous_commit_from(&db, FIRST_COMMIT)?,
6874 vec![recorder::Change::Addition {
6975 entry_mode: EntryMode::Blob,
7076 oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),
7177 path: "f".into()
7278 }]
7379 , ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f");
80+
7481 assert_eq!(
75− diff_with_previous_commit_from(SECOND_COMMIT).unwrap(),
82+ diff_with_previous_commit_from(&db, SECOND_COMMIT)?,
7683 vec![recorder::Change::Modification {
7784 previous_entry_mode: EntryMode::Blob,
7885 previous_oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),
@@ -81,8 +88,9 @@ mod changes { · 2 unmodified lines
8188 path: "f".into()
8289 }]
8390 , ":100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 28ce6a8b26aa170e1de65536fe8abe1832bd3242 M f");
91+
8492 assert_eq!(
85− diff_with_previous_commit_from(FIFTH_COMMIT).unwrap(),
93+ diff_with_previous_commit_from(&db, FIFTH_COMMIT)?,
8694 vec![recorder::Change::Deletion {
8795 entry_mode: EntryMode::Blob,
8896 oid: hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"),
@@ -100,6 +108,28 @@ mod changes { · 11 unmodified lines
100108 }]
101109 , ":100644 000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 0000000000000000000000000000000000000000 D f
102110 :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(())
103133 }
104134 }
105135 }

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