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
37 /// * it does a breadth first iteration as buffer space only fits two trees, the current one on the one we compare with.37 /// * it does a breadth first iteration as buffer space only fits two trees, the current one on the one we compare with.
38 /// * does not do rename tracking but attempts to reduce allocations to zero (so performance is mostly determined38 /// * does not do rename tracking but attempts to reduce allocations to zero (so performance is mostly determined
39 /// by the delegate implementation which should be as specific as possible.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 pub fn needed_to_obtain<LocateFn, R>(41 pub fn needed_to_obtain<LocateFn, R>(
41 mut self,42 mut self,
42 other: immutable::TreeIter<'a>,43 other: immutable::TreeIter<'a>,
@@ -58,15 +59,27 @@ impl<'a> visit::Changes<'a> { · 15 unmodified lines
58 delegate.pop_path_component();59 delegate.pop_path_component();
59 }60 }
60 match (lhs_entries.next(), rhs_entries.next()) {61 match (lhs_entries.next(), rhs_entries.next()) {
61 (None, None) => match state.trees.pop_front() {62 (None, None) => {
62 Some((None, Some(rhs))) => {63 match state.trees.pop_front() {
63 delegate.set_current_path(rhs.parent_path_id.clone());64 Some((None, Some(rhs))) => {
64 rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;65 delegate.set_current_path(rhs.parent_path_id.clone());
65 avoid_popping_path = Some(());66 rhs_entries = locate(&rhs.tree_id, &mut state.buf2).ok_or(Error::NotFound(rhs.tree_id))?;
66 }67 }
67 None => return Ok(()),68 Some((Some(lhs), Some(rhs))) => {
68 _ => todo!("all other combinations to re-stock iterators"),69 delegate.set_current_path(lhs.parent_path_id.clone());
69 },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 (Some(lhs), Some(rhs)) => {83 (Some(lhs), Some(rhs)) => {
71 use std::cmp::Ordering::*;84 use std::cmp::Ordering::*;
72 let (lhs, rhs) = (lhs?, rhs?);85 let (lhs, rhs) = (lhs?, rhs?);
@@ -75,7 +88,7 @@ impl<'a> visit::Changes<'a> { · 2 unmodified lines
75 use tree::EntryMode::*;88 use tree::EntryMode::*;
76 match (lhs.mode, rhs.mode) {89 match (lhs.mode, rhs.mode) {
77 (Tree, Tree) => {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 if lhs.oid != rhs.oid92 if lhs.oid != rhs.oid
80 && delegate93 && delegate
81 .record(Change::Modification {94 .record(Change::Modification {
@@ -88,7 +101,16 @@ impl<'a> visit::Changes<'a> { · 6 unmodified lines
88 {101 {
89 return Err(Cancelled);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 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {115 (lhs_mode, Tree) if lhs_mode.is_no_tree() => {
94 let path_id = delegate.push_tracked_path_component(lhs.filename);116 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
3 use crate::hex_to_id;3 use crate::hex_to_id;
4 use git_diff::visit::recorder;4 use git_diff::visit::recorder;
5 use git_object::tree::EntryMode;5 use git_object::tree::EntryMode;
6 use git_odb::{pack, Locate};6 use git_odb::{linked, pack, Locate};
7 7
8 const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430";8 const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430";
9 const SECOND_COMMIT: &str = "a5ebf9ee3b1cac5daf3dc9056026ee848be52da2";9 const SECOND_COMMIT: &str = "a5ebf9ee3b1cac5daf3dc9056026ee848be52da2";
10 const FIFTH_COMMIT: &str = "69bbebb6608472d98be684f4e6ef1faaac2a03bc";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 fn db() -> crate::Result<linked::Db> {
13 let db = git_odb::linked::Db::at(14 linked::Db::at(
14 test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")?15 test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")?
15 .join(".git")16 .join(".git")
16 .join("objects"),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 let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?;23 let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?;
19 let mut buf = Vec::new();24 let mut buf = Vec::new();
20 let (main_tree_id, parent_commit_id) = {25 let (main_tree_id, parent_commit_id) = {
@@ -62,17 +67,19 @@ mod changes { · 41 unmodified lines
62 }67 }
63 68
64 #[test]69 #[test]
65 fn many_different_states() {70 fn many_different_states() -> crate::Result {
71 let db = db()?;
66 assert_eq!(72 assert_eq!(
67 diff_with_previous_commit_from(FIRST_COMMIT).unwrap(),73 diff_with_previous_commit_from(&db, FIRST_COMMIT)?,
68 vec![recorder::Change::Addition {74 vec![recorder::Change::Addition {
69 entry_mode: EntryMode::Blob,75 entry_mode: EntryMode::Blob,
70 oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),76 oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),
71 path: "f".into()77 path: "f".into()
72 }]78 }]
73 , ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f");79 , ":000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f");
80
74 assert_eq!(81 assert_eq!(
75 diff_with_previous_commit_from(SECOND_COMMIT).unwrap(),82 diff_with_previous_commit_from(&db, SECOND_COMMIT)?,
76 vec![recorder::Change::Modification {83 vec![recorder::Change::Modification {
77 previous_entry_mode: EntryMode::Blob,84 previous_entry_mode: EntryMode::Blob,
78 previous_oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),85 previous_oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"),
@@ -81,8 +88,9 @@ mod changes { · 2 unmodified lines
81 path: "f".into()88 path: "f".into()
82 }]89 }]
83 , ":100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 28ce6a8b26aa170e1de65536fe8abe1832bd3242 M f");90 , ":100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 28ce6a8b26aa170e1de65536fe8abe1832bd3242 M f");
91
84 assert_eq!(92 assert_eq!(
85 diff_with_previous_commit_from(FIFTH_COMMIT).unwrap(),93 diff_with_previous_commit_from(&db, FIFTH_COMMIT)?,
86 vec![recorder::Change::Deletion {94 vec![recorder::Change::Deletion {
87 entry_mode: EntryMode::Blob,95 entry_mode: EntryMode::Blob,
88 oid: hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"),96 oid: hex_to_id("28ce6a8b26aa170e1de65536fe8abe1832bd3242"),
@@ -100,6 +108,28 @@ mod changes { · 11 unmodified lines
100 }]108 }]
101 , ":100644 000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 0000000000000000000000000000000000000000 D f109 , ":100644 000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 0000000000000000000000000000000000000000 D f
102 :000000 100644 0000000000000000000000000000000000000000 28ce6a8b26aa170e1de65536fe8abe1832bd3242 A f/f");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}

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