This leads to greater correctness of generation numbers when dealing with certain kinds of commit-graphs.
Showing the changes to gix-commitgraph/tests/commitgraph.rs (1 of 10 files). Show all
Unified · Split
| @@ -8,12 +8,13 @@ use std::{ · 7 unmodified lines | |||
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | use gix_commitgraph::{Graph, Position as GraphPosition}; | 10 | use gix_commitgraph::{Graph, Position as GraphPosition}; |
| 11 | 11 | use gix_testtools::scripted_fixture_read_only; | |
| 12 | type Result = std::result::Result<(), Box<dyn std::error::Error>>; | ||
| 13 | 12 | ||
| 14 | mod access; | 13 | mod access; |
| 15 | 14 | ||
| 16 | pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHasher>) { | 15 | pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHasher>) { |
| 16 | cg.verify_integrity(|_| Ok::<_, std::convert::Infallible>(())) | ||
| 17 | .expect("graph is valid"); | ||
| 17 | assert_eq!( | 18 | assert_eq!( |
| 18 | usize::try_from(cg.num_commits()).expect("an architecture able to hold 32 bits of integer"), | 19 | usize::try_from(cg.num_commits()).expect("an architecture able to hold 32 bits of integer"), |
| 19 | expected.len() | 20 | expected.len() |
| @@ -39,6 +40,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 19 unmodified lines | |||
| 39 | 40 | ||
| 40 | let commit = cg.commit_at(ref_info.pos()); | 41 | let commit = cg.commit_at(ref_info.pos()); |
| 41 | assert_eq!(commit.id(), ref_info.id()); | 42 | assert_eq!(commit.id(), ref_info.id()); |
| 43 | assert_eq!(commit.committer_timestamp(), ref_info.time.seconds); | ||
| 42 | assert_eq!(commit.root_tree_id(), ref_info.root_tree_id()); | 44 | assert_eq!(commit.root_tree_id(), ref_info.root_tree_id()); |
| 43 | assert_eq!( | 45 | assert_eq!( |
| 44 | commit.parent1().expect("failed to access commit's parent1"), | 46 | commit.parent1().expect("failed to access commit's parent1"), |
| @@ -59,13 +61,29 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 14 unmodified lines | |||
| 59 | ); | 61 | ); |
| 60 | } | 62 | } |
| 61 | 63 | ||
| 62 | use gix_testtools::scripted_fixture_read_only; | 64 | pub fn graph_and_expected( |
| 63 | pub fn make_readonly_repo(script_path: &str) -> std::path::PathBuf { | 65 | script_path: &str, |
| 64 | scripted_fixture_read_only(script_path).expect("script succeeds all the time") | 66 | refs: &[&'static str], |
| 67 | ) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) { | ||
| 68 | graph_and_expected_named(script_path, "", refs) | ||
| 69 | } | ||
| 70 | |||
| 71 | pub fn graph_and_expected_named( | ||
| 72 | script_path: &str, | ||
| 73 | name: &str, | ||
| 74 | refs: &[&'static str], | ||
| 75 | ) -> (gix_commitgraph::Graph, HashMap<String, RefInfo>) { | ||
| 76 | let repo_dir = scripted_fixture_read_only(script_path) | ||
| 77 | .expect("script succeeds all the time") | ||
| 78 | .join(name); | ||
| 79 | let expected = inspect_refs(&repo_dir, refs); | ||
| 80 | let cg = Graph::from_info_dir(repo_dir.join(".git").join("objects").join("info")).expect("graph present and valid"); | ||
| 81 | (cg, expected) | ||
| 65 | } | 82 | } |
| 66 | 83 | ||
| 67 | pub struct RefInfo { | 84 | pub struct RefInfo { |
| 68 | id: gix_hash::ObjectId, | 85 | id: gix_hash::ObjectId, |
| 86 | pub time: gix_date::Time, | ||
| 69 | parent_ids: Vec<gix_hash::ObjectId>, | 87 | parent_ids: Vec<gix_hash::ObjectId>, |
| 70 | pos: GraphPosition, | 88 | pos: GraphPosition, |
| 71 | root_tree_id: gix_hash::ObjectId, | 89 | root_tree_id: gix_hash::ObjectId, |
| @@ -89,13 +107,13 @@ impl RefInfo { · 17 unmodified lines | |||
| 89 | } | 107 | } |
| 90 | } | 108 | } |
| 91 | 109 | ||
| 92 | pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMap<String, RefInfo> { | 110 | fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMap<String, RefInfo> { |
| 93 | let output = Command::new("git") | 111 | let output = Command::new("git") |
| 94 | .arg("-C") | 112 | .arg("-C") |
| 95 | .arg(repo_dir.as_ref()) | 113 | .arg(repo_dir.as_ref()) |
| 96 | .arg("show") | 114 | .arg("show") |
| 97 | .arg("--no-patch") | 115 | .arg("--no-patch") |
| 98 | .arg("--pretty=format:%S %H %T %P") | 116 | .arg("--pretty=format:%S %H %T %ct %P") |
| 99 | .args(refs) | 117 | .args(refs) |
| 100 | .arg("--") | 118 | .arg("--") |
| 101 | .env_remove("GIT_DIR") | 119 | .env_remove("GIT_DIR") |
| @@ -111,7 +129,8 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 9 unmodified lines | |||
| 111 | parts[0].to_string(), | 129 | parts[0].to_string(), |
| 112 | gix_hash::ObjectId::from_hex(parts[1].as_bytes()).expect("40 bytes hex"), | 130 | gix_hash::ObjectId::from_hex(parts[1].as_bytes()).expect("40 bytes hex"), |
| 113 | gix_hash::ObjectId::from_hex(parts[2].as_bytes()).expect("40 bytes hex"), | 131 | gix_hash::ObjectId::from_hex(parts[2].as_bytes()).expect("40 bytes hex"), |
| 114 | parts[3..] | 132 | gix_date::Time::new(parts[3].parse().expect("valid stamp"), 0), |
| 133 | parts[4..] | ||
| 115 | .iter() | 134 | .iter() |
| 116 | .map(|x| gix_hash::ObjectId::from_hex(x.as_bytes()).expect("40 bytes hex")) | 135 | .map(|x| gix_hash::ObjectId::from_hex(x.as_bytes()).expect("40 bytes hex")) |
| 117 | .collect(), | 136 | .collect(), |
| @@ -132,13 +151,14 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 14 unmodified lines | |||
| 132 | infos | 151 | infos |
| 133 | .iter() | 152 | .iter() |
| 134 | .cloned() | 153 | .cloned() |
| 135 | .map(|(name, id, root_tree_id, parent_ids)| { | 154 | .map(|(name, id, root_tree_id, time, parent_ids)| { |
| 136 | ( | 155 | ( |
| 137 | name, | 156 | name, |
| 138 | RefInfo { | 157 | RefInfo { |
| 139 | id, | 158 | id, |
| 140 | parent_ids, | 159 | parent_ids, |
| 141 | root_tree_id, | 160 | root_tree_id, |
| 161 | time, | ||
| 142 | pos: get_pos(&id), | 162 | pos: get_pos(&id), |
| 143 | }, | 163 | }, |
| 144 | ) | 164 | ) |