|
1 |
| -mod with_tree { |
2 |
| - use crate::hex_to_id; |
3 |
| - use git_diff::visit::recorder; |
4 |
| - use git_odb::{pack, Locate}; |
| 1 | +mod changes { |
| 2 | + mod to_obtain_tree { |
| 3 | + use crate::hex_to_id; |
| 4 | + use git_diff::visit::recorder; |
| 5 | + use git_odb::{pack, Locate}; |
5 | 6 |
|
6 |
| - const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430"; |
| 7 | + const FIRST_COMMIT: &str = "055df97e18cd537da3cb16bcbdf1733fdcdfb430"; |
7 | 8 |
|
8 |
| - fn diff_at(commit_id: &str) -> crate::Result<recorder::Changes> { |
9 |
| - let db = git_odb::linked::Db::at( |
10 |
| - test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")? |
11 |
| - .join(".git") |
12 |
| - .join("objects"), |
13 |
| - )?; |
14 |
| - let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?; |
15 |
| - let mut buf = Vec::new(); |
16 |
| - let (main_tree_id, parent_commit_id) = { |
17 |
| - let commit = db |
18 |
| - .locate(commit_id, &mut buf, &mut pack::cache::Never)? |
19 |
| - .expect("start commit to be present") |
| 9 | + fn diff_at(commit_id: &str) -> crate::Result<recorder::Changes> { |
| 10 | + let db = git_odb::linked::Db::at( |
| 11 | + test_tools::scripted_fixture_repo_read_only("make_diff_repo.sh")? |
| 12 | + .join(".git") |
| 13 | + .join("objects"), |
| 14 | + )?; |
| 15 | + let commit_id = git_hash::ObjectId::from_hex(commit_id.as_bytes())?; |
| 16 | + let mut buf = Vec::new(); |
| 17 | + let (main_tree_id, parent_commit_id) = { |
| 18 | + let commit = db |
| 19 | + .locate(commit_id, &mut buf, &mut pack::cache::Never)? |
| 20 | + .expect("start commit to be present") |
| 21 | + .decode()? |
| 22 | + .into_commit() |
| 23 | + .expect("id is actually a commit"); |
| 24 | + |
| 25 | + (commit.tree(), { |
| 26 | + let p = commit.parents().next(); |
| 27 | + p |
| 28 | + }) |
| 29 | + }; |
| 30 | + let main_tree = db |
| 31 | + .locate(main_tree_id, &mut buf, &mut pack::cache::Never)? |
| 32 | + .expect("main tree present") |
20 | 33 | .decode()?
|
21 |
| - .into_commit() |
22 |
| - .expect("id is actually a commit"); |
| 34 | + .into_tree() |
| 35 | + .expect("id to be a tree"); |
| 36 | + let mut buf2 = Vec::new(); |
| 37 | + let previous_tree: Option<_> = { |
| 38 | + parent_commit_id |
| 39 | + .and_then(|id| db.locate(id, &mut buf2, &mut pack::cache::Never).ok().flatten()) |
| 40 | + .and_then(|c| c.decode().ok()) |
| 41 | + .and_then(|c| c.into_commit()) |
| 42 | + .map(|c| c.tree()) |
| 43 | + .and_then(|tree| db.locate(tree, &mut buf2, &mut pack::cache::Never).ok().flatten()) |
| 44 | + .and_then(|tree| tree.decode().ok()) |
| 45 | + .and_then(|tree| tree.into_tree()) |
| 46 | + }; |
23 | 47 |
|
24 |
| - (commit.tree(), { |
25 |
| - let p = commit.parents().next(); |
26 |
| - p |
27 |
| - }) |
28 |
| - }; |
29 |
| - let main_tree = db |
30 |
| - .locate(main_tree_id, &mut buf, &mut pack::cache::Never)? |
31 |
| - .expect("main tree present") |
32 |
| - .decode()? |
33 |
| - .into_tree() |
34 |
| - .expect("id to be a tree"); |
35 |
| - let mut buf2 = Vec::new(); |
36 |
| - let previous_tree: Option<_> = { |
37 |
| - parent_commit_id |
38 |
| - .and_then(|id| db.locate(id, &mut buf2, &mut pack::cache::Never).ok().flatten()) |
39 |
| - .and_then(|c| c.decode().ok()) |
40 |
| - .and_then(|c| c.into_commit()) |
41 |
| - .map(|c| c.tree()) |
42 |
| - .and_then(|tree| db.locate(tree, &mut buf2, &mut pack::cache::Never).ok().flatten()) |
43 |
| - .and_then(|tree| tree.decode().ok()) |
44 |
| - .and_then(|tree| tree.into_tree()) |
45 |
| - }; |
| 48 | + let mut recorder = git_diff::visit::Recorder::default(); |
| 49 | + git_diff::visit::Changes::from(previous_tree.as_ref()).to_obtain_tree( |
| 50 | + &main_tree, |
| 51 | + &mut git_diff::visit::State::default(), |
| 52 | + |_oid, _buf| todo!("Actual lookup in db"), |
| 53 | + &mut recorder, |
| 54 | + )?; |
| 55 | + Ok(recorder.records) |
| 56 | + } |
46 | 57 |
|
47 |
| - let mut recorder = git_diff::visit::Recorder::default(); |
48 |
| - git_diff::visit::Changes::from(previous_tree.as_ref()).to_obtain_tree( |
49 |
| - &main_tree, |
50 |
| - &mut git_diff::visit::State::default(), |
51 |
| - |_oid, _buf| todo!("Actual lookup in db"), |
52 |
| - &mut recorder, |
53 |
| - )?; |
54 |
| - Ok(recorder.records) |
55 |
| - } |
56 |
| - #[test] |
57 |
| - #[should_panic] |
58 |
| - fn file_added() { |
59 |
| - // :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f |
60 |
| - assert_eq!( |
61 |
| - diff_at(FIRST_COMMIT).unwrap(), |
62 |
| - vec![recorder::Change::Addition { |
63 |
| - mode: git_object::tree::Mode::Tree, |
64 |
| - oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"), |
65 |
| - path: "f".into() |
66 |
| - }] |
67 |
| - ); |
68 |
| - todo!("detect an added file in the root tree") |
| 58 | + #[test] |
| 59 | + #[should_panic] |
| 60 | + fn file_added() { |
| 61 | + // :000000 100644 0000000000000000000000000000000000000000 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 A f |
| 62 | + assert_eq!( |
| 63 | + diff_at(FIRST_COMMIT).unwrap(), |
| 64 | + vec![recorder::Change::Addition { |
| 65 | + mode: git_object::tree::Mode::Tree, |
| 66 | + oid: hex_to_id("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"), |
| 67 | + path: "f".into() |
| 68 | + }] |
| 69 | + ); |
| 70 | + todo!("detect an added file in the root tree") |
| 71 | + } |
69 | 72 | }
|
70 | 73 | }
|
0 commit comments